Skip to content

feat: add /blas/base/zdscal #5136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zdscal/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var pkg = require( './../package.json' ).name;
var zdscal = require( './../lib/zdscal.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var zxbuf;
var zx;

zxbuf = uniform( len*2, -100.0, 100.0, options );
zx = new Complex128Array( zxbuf.buffer );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zdscal( zx.length, 1.01, zx, 1 );
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':len='+len, f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var pkg = require( './../package.json' ).name;
var zdscal = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var zxbuf;
var zx;

zxbuf = uniform( len*2, -100.0, 100.0, options );
zx = new Complex128Array( zxbuf.buffer );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zdscal( zx.length, 1.01, zx, 1, 0 );
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( zxbuf[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':ndarray:len='+len, f );
}
}

main();
118 changes: 118 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zdscal/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

{{alias}}( N, alpha, zx, strideX )
Scales a double-precision complex floating-point vector by a double-
precision floating-point constant.

The `N` and stride parameters determine how values from `zx` are scaled by
`alpha`.

Indexing is relative to the first index. To introduce an offset, use typed
array views.

If `N` or `strideX` is less than or equal to `0`, the function returns `zx`
unchanged.


Parameters
----------
N: integer
Number of indexed elements.

alpha: Float64
Complex constant.

zx: Complex128Array
Input array.

strideX: integer
Index increment for `zx`.

Returns
-------
zx: Complex128Array
Input array.

Examples
--------
// Standard usage:
> var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> {{alias}}( 2, 5.0, zx, 1 );
> var z = zx.get( 0 );
> var re = {{alias:@stdlib/complex/float64/real}}( z )
5.0
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
10.0

// Advanced indexing:
> zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> {{alias}}( 2, 5.0, zx, 2 );
> z = zx.get( 0 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
5.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
10.0

// Using typed array views:
> var zx0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> var zx1 = new {{alias:@stdlib/array/complex128}}( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 );
> {{alias}}( 2, 5.0, zx1, 1 );
> z = zx0.get( 1 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
15.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
20.0


{{alias}}.ndarray( N, za, zx, strideX, offsetX )
Scales a double-precision complex floating-point vector by a double-
precision floating-point constant using alternative indexing
semantics.

While typed array views mandate a view offset based on the underlying
buffer, the offset parameter supports indexing semantics based on a starting
index.

Parameters
----------
N: integer
Number of indexed elements.

alpha: Float64
Float constant.

zx: Complex128Array
Input array.

strideX: integer
Index increment for `zx`.

offsetX: integer
Starting index for `zx`.

Returns
-------
zx: Complex128Array
Input array.

Examples
--------
// Standard usage:
> var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> {{alias}}.ndarray( 2, 5.0, zx, 1, 0 );
> var z = zx.get( 0 );
> var re = {{alias:@stdlib/complex/float64/real}}( z )
5.0
> var im = {{alias:@stdlib/complex/float64/imag}}( z )
10.0

// Advanced indexing:
> zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
> {{alias}}.ndarray( 2, 2.0, zx, 1, 2 );
> z = zx.get( 2 );
> re = {{alias:@stdlib/complex/float64/real}}( z )
10.0
> im = {{alias:@stdlib/complex/float64/imag}}( z )
12.0

See Also
--------
Loading
Loading