From 84f523c2b75f8c54de42792e944632d32c752ad3 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 1 Nov 2026 11:20:27 -0700 Subject: [PATCH] feat: add `blas/ext/base/ndarray/cwaxpb` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/cwaxpb/README.md | 149 ++++ .../ndarray/cwaxpb/benchmark/benchmark.js | 114 +++ .../ext/base/ndarray/cwaxpb/docs/repl.txt | 38 + .../base/ndarray/cwaxpb/docs/types/index.d.ts | 65 ++ .../base/ndarray/cwaxpb/docs/types/test.ts | 77 ++ .../ext/base/ndarray/cwaxpb/examples/index.js | 50 ++ .../blas/ext/base/ndarray/cwaxpb/lib/index.js | 54 ++ .../blas/ext/base/ndarray/cwaxpb/lib/main.js | 103 +++ .../blas/ext/base/ndarray/cwaxpb/package.json | 77 ++ .../blas/ext/base/ndarray/cwaxpb/test/test.js | 673 ++++++++++++++++++ 10 files changed, 1400 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/README.md new file mode 100644 index 000000000000..78b9288c0bd2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/README.md @@ -0,0 +1,149 @@ + + +# cwaxpb + +> Multiply each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and add a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray. + +
+ +This BLAS extension implements the linear transformation + + + +```math +\mathbf{w} = \alpha \mathbf{x} + \beta +``` + + + +
+ + + +
+ +## Usage + +```javascript +var cwaxpb = require( '@stdlib/blas/ext/base/ndarray/cwaxpb' ); +``` + +#### cwaxpb( arrays ) + +Multiplies each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray. + +```javascript +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Complex64Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +var w = new Complex64Vector( 4 ); + +var alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' +}); + +var beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' +}); + +cwaxpb( [ x, w, alpha, beta ] ); +// w => [ [ -7.0, 5.0 ], [ 18.0, -25.0 ], [ 23.0, 0.0 ], [ -2.0, -15.0 ] ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional output ndarray. + - a zero-dimensional ndarray containing the scalar constant to multiply. + - a zero-dimensional ndarray containing the scalar constant to add. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cwaxpb = require( '@stdlib/blas/ext/base/ndarray/cwaxpb' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var w = new Complex64Vector( 10 ); +console.log( ndarray2array( w ) ); + +var alpha = scalar2ndarray( new Complex64( 5.0, -3.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Beta:', ndarraylike2scalar( beta ) ); + +cwaxpb( [ x, w, alpha, beta ] ); +console.log( ndarray2array( w ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/benchmark/benchmark.js new file mode 100644 index 000000000000..bc5610291d58 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/benchmark/benchmark.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var cwaxpb = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var beta; + var xbuf; + var x; + var w; + + xbuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + x = new Complex64Vector( xbuf.buffer ); + w = new Complex64Vector( len ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = cwaxpb( [ x, w, alpha, beta ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/repl.txt new file mode 100644 index 000000000000..bde0284c462a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( arrays ) + Multiplies each element in an input one-dimensional single-precision complex + floating-point ndarray by a scalar constant and adds a scalar constant + before assigning the results to elements in a one-dimensional single- + precision complex floating-point output ndarray. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional output ndarray. + - a zero-dimensional ndarray containing the scalar constant to multiply. + - a zero-dimensional ndarray containing the scalar constant to add. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var xbuf = [ -2.0, 1.0, 3.0, -5.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/complex64}}( xbuf ); + > var w = new {{alias:@stdlib/ndarray/vector/complex64}}( 2 ); + > var opts = { 'dtype': 'complex64' }; + > var a = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, 0.0 ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( a, opts ); + > var b = new {{alias:@stdlib/complex/float32/ctor}}( 3.0, 0.0 ); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( b, opts ); + > {{alias}}( [ x, w, alpha, beta ] ) + [ [ -7.0, 5.0 ], [ 18.0, -25.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/index.d.ts new file mode 100644 index 000000000000..36bcfd9d5572 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/index.d.ts @@ -0,0 +1,65 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { complex64ndarray, typedndarray } from '@stdlib/types/ndarray'; +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Multiplies each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the scalar constant to multiply. +* - a zero-dimensional ndarray containing the scalar constant to add. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Complex64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* var w = new Complex64Vector( 2 ); +* +* var alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cwaxpb( [ x, w, alpha, beta ] ); +* // returns [ [ -7.0, 5.0 ], [ 18.0, -25.0 ] ] +*/ +declare function cwaxpb( arrays: [ complex64ndarray, complex64ndarray, typedndarray, typedndarray ] ): complex64ndarray; + + +// EXPORTS // + +export = cwaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/test.ts new file mode 100644 index 000000000000..48a380c4b10f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/docs/types/test.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import cwaxpb = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const w = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + const beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + cwaxpb( [ x, w, alpha, beta ] ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + cwaxpb( '10' ); // $ExpectError + cwaxpb( 5 ); // $ExpectError + cwaxpb( true ); // $ExpectError + cwaxpb( false ); // $ExpectError + cwaxpb( null ); // $ExpectError + cwaxpb( undefined ); // $ExpectError + cwaxpb( [] ); // $ExpectError + cwaxpb( {} ); // $ExpectError + cwaxpb( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const w = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + const beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + cwaxpb(); // $ExpectError + cwaxpb( [ x, w, alpha, beta ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/examples/index.js new file mode 100644 index 000000000000..eefd3390bb4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/examples/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var cwaxpb = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var w = new Complex64Vector( 10 ); +console.log( ndarray2array( w ) ); + +var alpha = scalar2ndarray( new Complex64( 5.0, -3.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Beta:', ndarraylike2scalar( beta ) ); + +cwaxpb( [ x, w, alpha, beta ] ); +console.log( ndarray2array( w ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/index.js new file mode 100644 index 000000000000..edcd0ea9fac3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Multiply each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and add a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/cwaxpb +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var cwaxpb = require( '@stdlib/blas/ext/base/ndarray/cwaxpb' ); +* +* var x = new Complex64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* var w = new Complex64Vector( 2 ); +* +* var alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cwaxpb( [ x, w, alpha, beta ] ); +* // returns [ [ -7.0, 5.0 ], [ 18.0, -25.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/main.js new file mode 100644 index 000000000000..84bbaa3c2b49 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/lib/main.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var cwax = require( '@stdlib/blas/ext/base/cwax' ).ndarray; +var capx = require( '@stdlib/blas/ext/base/capx' ).ndarray; + + +// MAIN // + +/** +* Multiplies each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the scalar constant to multiply. +* - a zero-dimensional ndarray containing the scalar constant to add. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} output ndarray +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Complex64Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* var w = new Complex64Vector( 2 ); +* +* var alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cwaxpb( [ x, w, alpha, beta ] ); +* // returns [ [ -7.0, 5.0 ], [ 18.0, -25.0 ] ] +* +* var bool = ( out === w ); +* // returns true +*/ +function cwaxpb( arrays ) { + var alpha; + var wbuf; + var beta; + var sw; + var ow; + var N; + var x; + var w; + + x = arrays[ 0 ]; + w = arrays[ 1 ]; + alpha = ndarraylike2scalar( arrays[ 2 ] ); + beta = ndarraylike2scalar( arrays[ 3 ] ); + + N = numelDimension( x, 0 ); + wbuf = getData( w ); + sw = getStride( w, 0 ); + ow = getOffset( w ); + + // Multiply each element by the scalar constant (w = alpha*x): + cwax( N, alpha, getData( x ), getStride( x, 0 ), getOffset( x ), wbuf, sw, ow ); // eslint-disable-line max-len + + // Add the scalar constant (w += beta): + capx( N, beta, wbuf, sw, ow ); + + return w; +} + + +// EXPORTS // + +module.exports = cwaxpb; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/package.json new file mode 100644 index 000000000000..c194e6379daf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/cwaxpb", + "version": "0.0.0", + "description": "Multiply each element in an input one-dimensional single-precision complex floating-point ndarray by a scalar constant and add a scalar constant before assigning the results to elements in a one-dimensional single-precision complex floating-point output ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "ext", + "cwaxpb", + "waxpb", + "multiply", + "add", + "scalar", + "constant", + "linear", + "transform", + "strided", + "array", + "ndarray", + "complex64", + "complex", + "single", + "single-precision", + "float32" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/test/test.js new file mode 100644 index 000000000000..99f925044c0c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cwaxpb/test/test.js @@ -0,0 +1,673 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cwaxpb = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Complex64Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'complex64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cwaxpb, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( cwaxpb.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant and adds a scalar constant before assigning the results to an output ndarray', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0, // 2 + -1.0, // 3 + -3.0, // 3 + 2.0, // 4 + 1.0 // 4 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, // 3 + 0.0, // 3 + 0.0, // 4 + 0.0 // 4 + ]); + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + -7.0, // 0 + 5.0, // 0 + 18.0, // 1 + -25.0, // 1 + 23.0, // 2 + 0.0, // 2 + -2.0, // 3 + -15.0, // 3 + 13.0, // 4 + 5.0 // 4 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies the input ndarray to the output ndarray when alpha is one and beta is zero', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0, // 2 + -1.0, // 3 + -3.0, // 3 + 2.0, // 4 + 1.0 // 4 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, // 3 + 0.0, // 3 + 0.0, // 4 + 0.0 // 4 + ]); + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 0.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0, // 2 + -1.0, // 3 + -3.0, // 3 + 2.0, // 4 + 1.0 // 4 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds a scalar constant to each element when alpha is one', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0, // 2 + -1.0, // 3 + -3.0, // 3 + 2.0, // 4 + 1.0 // 4 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, // 3 + 0.0, // 3 + 0.0, // 4 + 0.0 // 4 + ]); + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 1.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + 1.0, // 0 + 1.0, // 0 + 6.0, // 1 + -5.0, // 1 + 7.0, // 2 + 0.0, // 2 + 2.0, // 3 + -3.0, // 3 + 5.0, // 4 + 1.0 // 4 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies each element by a scalar constant when beta is zero', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0, // 2 + -1.0, // 3 + -3.0, // 3 + 2.0, // 4 + 1.0 // 4 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, // 3 + 0.0, // 3 + 0.0, // 4 + 0.0 // 4 + ]); + x = vector( xbuf, 5, 1, 0 ); + w = vector( wbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 0.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + -10.0, // 0 + 5.0, // 0 + 15.0, // 1 + -25.0, // 1 + 20.0, // 2 + 0.0, // 2 + -5.0, // 3 + -15.0, // 3 + 10.0, // 4 + 5.0 // 4 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 0.0, + 0.0, + 4.0, // 1 + 0.0, // 1 + 0.0, + 0.0 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0 // 1 + ]); + x = vector( xbuf, 2, 2, 0 ); + w = vector( wbuf, 2, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + -7.0, // 0 + 5.0, // 0 + 23.0, // 1 + 0.0 // 1 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 4 + 1.0, // 4 + 3.0, // 3 + -5.0, // 3 + 4.0, // 2 + 0.0, // 2 + -1.0, // 1 + -3.0, // 1 + 2.0, // 0 + 1.0 // 0 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, // 3 + 0.0, // 3 + 0.0, // 4 + 0.0 // 4 + ]); + x = vector( xbuf, 5, -1, 4 ); + w = vector( wbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + 13.0, // 0 + 5.0, // 0 + -2.0, // 1 + -15.0, // 1 + 23.0, // 2 + 0.0, // 2 + 18.0, // 3 + -25.0, // 3 + -7.0, // 4 + 5.0 // 4 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an output ndarray having a non-unit stride', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0 // 1 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, + 0.0, + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0 + ]); + x = vector( xbuf, 2, 1, 0 ); + w = vector( wbuf, 2, 2, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + -7.0, // 0 + 5.0, // 0 + 0.0, + 0.0, + 18.0, // 1 + -25.0, // 1 + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an output ndarray having a negative stride', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0 // 2 + ]); + wbuf = new Complex64Array([ + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, // 0 + 0.0 // 0 + ]); + x = vector( xbuf, 3, 1, 0 ); + w = vector( wbuf, 3, -1, 2 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + 23.0, // 2 + 0.0, // 2 + 18.0, // 1 + -25.0, // 1 + -7.0, // 0 + 5.0 // 0 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 3.0, // 0 + -5.0, // 0 + 4.0, // 1 + 0.0, // 1 + -1.0, // 2 + -3.0 // 2 + ]); + wbuf = new Complex64Array([ + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + x = vector( xbuf, 3, 1, 2 ); + w = vector( wbuf, 3, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + 18.0, // 0 + -25.0, // 0 + 23.0, // 1 + 0.0, // 1 + -2.0, // 2 + -15.0 // 2 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an output ndarray having a non-zero offset', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array([ + -2.0, // 0 + 1.0, // 0 + 3.0, // 1 + -5.0, // 1 + 4.0, // 2 + 0.0 // 2 + ]); + wbuf = new Complex64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 0 + 0.0, // 0 + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + x = vector( xbuf, 3, 1, 0 ); + w = vector( wbuf, 3, 1, 2 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + -7.0, // 0 + 5.0, // 0 + 18.0, // 1 + -25.0, // 1 + 23.0, // 2 + 0.0 // 2 + ]); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the output ndarray unchanged when the input ndarray is empty', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var wbuf; + var x; + var w; + + xbuf = new Complex64Array( [] ); + wbuf = new Complex64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + w = vector( wbuf, 0, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 3.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = cwaxpb( [ x, w, alpha, beta ] ); + t.strictEqual( actual, w, 'returns expected value' ); + + expected = new Complex64Array( [] ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +});