diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/README.md new file mode 100644 index 000000000000..a52496708cf0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/README.md @@ -0,0 +1,153 @@ + + +# caxpby + +> Multiply a one-dimensional single-precision complex floating-point ndarray by a scalar constant and add the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant. + +
+ +This BLAS extension implements the operation + + + +```math +\mathbf{y} = \alpha \mathbf{x} + \beta \mathbf{y} +``` + + + +
+ + + +
+ +## Usage + +```javascript +var caxpby = require( '@stdlib/blas/ext/base/ndarray/caxpby' ); +``` + +#### caxpby( arrays ) + +Multiplies a one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant. + +```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( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); +var y = new Complex64Vector( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); + +var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' +}); + +var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' +}); + +var out = caxpby( [ x, y, alpha, beta ] ); +// returns [ [ 3.0, 4.0 ], [ 9.0, 5.0 ], [ 3.0, -2.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 constant by which to multiply the input ndarray. + - a zero-dimensional ndarray containing the constant by which to multiply the output ndarray. + +
+ + + +
+ +## Notes + +- The output ndarray is modified **in-place** (i.e., the output ndarray is **mutated**). + +
+ + + +
+ +## 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 caxpby = require( '@stdlib/blas/ext/base/ndarray/caxpby' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var y = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( y ) ); + +var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Beta:', ndarraylike2scalar( beta ) ); + +caxpby( [ x, y, alpha, beta ] ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/benchmark/benchmark.js new file mode 100644 index 000000000000..5e100fb7e3be --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/benchmark/benchmark.js @@ -0,0 +1,121 @@ +/** +* @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 caxpby = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'complex64' +}; + + +// 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 ybuf; + var x; + var y; + + xbuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + ybuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float32' + }); + x = new Complex64Vector( xbuf.buffer ); + y = new Complex64Vector( ybuf.buffer ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), options ); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), options ); + 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 = caxpby( [ x, y, 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/caxpby/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/repl.txt new file mode 100644 index 000000000000..c28d1af1004a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( arrays ) + Multiplies a one-dimensional single-precision complex floating-point ndarray + by a scalar constant and adds the result to a second one-dimensional single- + precision complex floating-point ndarray multiplied by a scalar constant. + + The output ndarray is modified *in-place* (i.e., the output ndarray is + *mutated*). + + 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 constant by which to + multiply the input ndarray. + - a zero-dimensional ndarray containing the constant by which to + multiply the output ndarray. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var bufX = [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ]; + > var bufY = [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/complex64}}( bufX ); + > var y = new {{alias:@stdlib/ndarray/vector/complex64}}( bufY ); + > var opts = { 'dtype': 'complex64' }; + > var a = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 1.0 ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( a, opts ); + > var b = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, -1.0 ); + > var beta = {{alias:@stdlib/ndarray/from-scalar}}( b, opts ); + > {{alias}}( [ x, y, alpha, beta ] ) + [ [ 3, 4 ], [ 9, 5 ], [ 3, -2 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/types/index.d.ts new file mode 100644 index 000000000000..22e3769792cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/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 a one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the constant by which to multiply the input ndarray. +* - a zero-dimensional ndarray containing the constant by which to multiply the output ndarray. +* +* @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( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); +* var y = new Complex64Vector( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); +* +* var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = caxpby( [ x, y, alpha, beta ] ); +* // returns [ [ 3.0, 4.0 ], [ 9.0, 5.0 ], [ 3.0, -2.0 ] ] +*/ +declare function caxpby( arrays: [ complex64ndarray, complex64ndarray, typedndarray, typedndarray ] ): complex64ndarray; + + +// EXPORTS // + +export = caxpby; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/docs/types/test.ts new file mode 100644 index 000000000000..f5564bb73e9c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/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 caxpby = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const y = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + const beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + caxpby( [ x, y, alpha, beta ] ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + caxpby( '10' ); // $ExpectError + caxpby( 5 ); // $ExpectError + caxpby( true ); // $ExpectError + caxpby( false ); // $ExpectError + caxpby( null ); // $ExpectError + caxpby( undefined ); // $ExpectError + caxpby( [] ); // $ExpectError + caxpby( {} ); // $ExpectError + caxpby( ( 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 y = zeros( [ 10 ], { + 'dtype': 'complex64' + }); + const alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + const beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + caxpby(); // $ExpectError + caxpby( [ x, y, alpha, beta ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/examples/index.js new file mode 100644 index 000000000000..81ba208abb07 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/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 caxpby = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; + +var x = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var y = new Complex64Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( y ) ); + +var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' +}); +console.log( 'Beta:', ndarraylike2scalar( beta ) ); + +caxpby( [ x, y, alpha, beta ] ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/lib/index.js new file mode 100644 index 000000000000..e7917a9c9ab9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/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 a one-dimensional single-precision complex floating-point ndarray by a scalar constant and add the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/caxpby +* +* @example +* var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var caxpby = require( '@stdlib/blas/ext/base/ndarray/caxpby' ); +* +* var x = new Complex64Vector( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); +* var y = new Complex64Vector( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); +* +* var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = caxpby( [ x, y, alpha, beta ] ); +* // returns [ [ 3.0, 4.0 ], [ 9.0, 5.0 ], [ 3.0, -2.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/lib/main.js new file mode 100644 index 000000000000..93c289e5f33d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/lib/main.js @@ -0,0 +1,84 @@ +/** +* @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 strided = require( '@stdlib/blas/ext/base/caxpby' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Multiplies a one-dimensional single-precision complex floating-point ndarray by a scalar constant and adds the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional output ndarray. +* - a zero-dimensional ndarray containing the constant by which to multiply the input ndarray. +* - a zero-dimensional ndarray containing the constant by which to multiply the output ndarray. +* +* @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( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); +* var y = new Complex64Vector( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); +* +* var alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = caxpby( [ x, y, alpha, beta ] ); +* // returns [ [ 3.0, 4.0 ], [ 9.0, 5.0 ], [ 3.0, -2.0 ] ] +*/ +function caxpby( arrays ) { + var alpha; + var beta; + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + alpha = ndarraylike2scalar( arrays[ 2 ] ); + beta = ndarraylike2scalar( arrays[ 3 ] ); + strided( numelDimension( x, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ), beta, getData( y ), getStride( y, 0 ), getOffset( y ) ); // eslint-disable-line max-len + return y; +} + + +// EXPORTS // + +module.exports = caxpby; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/package.json new file mode 100644 index 000000000000..5d4ed178d0ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/caxpby", + "version": "0.0.0", + "description": "Multiply a one-dimensional single-precision complex floating-point ndarray by a scalar constant and add the result to a second one-dimensional single-precision complex floating-point ndarray multiplied by a scalar constant.", + "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", + "caxpby", + "axpby", + "multiply", + "add", + "scalar", + "constant", + "linear", + "combination", + "strided", + "array", + "ndarray", + "complex64", + "complex", + "single", + "single-precision", + "float32" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/test/test.js new file mode 100644 index 000000000000..3ce477fc240b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/caxpby/test/test.js @@ -0,0 +1,383 @@ +/** +* @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 stdlib/empty-line-before-comment */ + +'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 caxpby = 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 caxpby, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( caxpby.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function multiplies `x` by a scalar constant and adds the result to `y` multiplied by a scalar constant', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 ] ); + ybuf = new Complex64Array( [ 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 ] ); + x = vector( xbuf, 3, 1, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array([ + // (2.0+1.0i)*(1.0+2.0i) + (1.0-1.0i)*(2.0+1.0i) + 3.0, + 4.0, + // (2.0+1.0i)*(3.0-1.0i) + (1.0-1.0i)*(-1.0+3.0i) + 9.0, + 5.0, + // (2.0+1.0i)*(0.0+1.0i) + (1.0-1.0i)*(4.0+0.0i) + 3.0, + -2.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = new Complex64Array( [ 1.0, 0.0, 2.0, 1.0 ] ); + ybuf = new Complex64Array( [ 3.0, -1.0, 4.0, 2.0 ] ); + x = vector( xbuf, 2, 1, 0 ); + y = vector( ybuf, 2, 1, 0 ); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array([ + // (2.0+1.0i)*(1.0+0.0i) + (1.0-1.0i)*(3.0-1.0i) + 4.0, + -3.0, + // (2.0+1.0i)*(2.0+1.0i) + (1.0-1.0i)*(4.0+2.0i) + 9.0, + 2.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + 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 ybuf; + var x; + var y; + + xbuf = new Complex64Array([ + 1.0, // 0 + 2.0, // 0 + 0.0, + 0.0, + 3.0, // 1 + -1.0, // 1 + 0.0, + 0.0, + 0.0, // 2 + 1.0 // 2 + ]); + ybuf = new Complex64Array([ + 2.0, // 0 + 1.0, // 0 + -1.0, // 1 + 3.0, // 1 + 4.0, // 2 + 0.0 // 2 + ]); + x = vector( xbuf, 3, 2, 0 ); + y = vector( ybuf, 3, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array([ + // (2.0+1.0i)*(1.0+2.0i) + (1.0-1.0i)*(2.0+1.0i) + 3.0, + 4.0, + // (2.0+1.0i)*(3.0-1.0i) + (1.0-1.0i)*(-1.0+3.0i) + 9.0, + 5.0, + // (2.0+1.0i)*(0.0+1.0i) + (1.0-1.0i)*(4.0+0.0i) + 3.0, + -2.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + 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 ybuf; + var x; + var y; + + xbuf = new Complex64Array([ + 1.0, // 0 + 2.0, // 0 + 3.0, // 1 + -1.0, // 1 + 0.0, // 2 + 1.0 // 2 + ]); + ybuf = new Complex64Array([ + 2.0, // 0 + 1.0, // 0 + 0.0, + 0.0, + -1.0, // 1 + 3.0, // 1 + 0.0, + 0.0, + 4.0, // 2 + 0.0 // 2 + ]); + x = vector( xbuf, 3, 1, 0 ); + y = vector( ybuf, 3, 2, 0 ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array([ + // (2.0+1.0i)*(1.0+2.0i) + (1.0-1.0i)*(2.0+1.0i) + 3.0, + 4.0, + 0.0, + 0.0, + // (2.0+1.0i)*(3.0-1.0i) + (1.0-1.0i)*(-1.0+3.0i) + 9.0, + 5.0, + 0.0, + 0.0, + // (2.0+1.0i)*(0.0+1.0i) + (1.0-1.0i)*(4.0+0.0i) + 3.0, + -2.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having negative strides', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Complex64Array([ + 1.0, // 2 + 2.0, // 2 + 0.0, + 0.0, + 3.0, // 1 + -1.0, // 1 + 0.0, + 0.0, + 5.0, // 0 + 6.0 // 0 + ]); + ybuf = new Complex64Array([ + 4.0, // 2 + 0.0, // 2 + 3.0, // 1 + -1.0, // 1 + 2.0, // 0 + 1.0 // 0 + ]); + x = vector( xbuf, 3, -2, 4 ); + y = vector( ybuf, 3, -1, 2 ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array([ + // (2.0+1.0i)*(1.0+2.0i) + (1.0-1.0i)*(4.0+0.0i) + 4.0, + 1.0, + // (2.0+1.0i)*(3.0-1.0i) + (1.0-1.0i)*(3.0-1.0i) + 9.0, + -3.0, + // (2.0+1.0i)*(5.0+6.0i) + (1.0-1.0i)*(2.0+1.0i) + 7.0, + 16.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Complex64Array([ + 0.0, + 0.0, + 1.0, // 0 + 0.0, // 0 + 0.0, + 0.0, + 2.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 3.0, // 2 + 0.0 // 2 + ]); + ybuf = new Complex64Array([ + 0.0, + 0.0, + 2.0, // 0 + 0.0, // 0 + 3.0, // 1 + 0.0, // 1 + 4.0, // 2 + 0.0 // 2 + ]); + x = vector( xbuf, 3, 2, 1 ); + y = vector( ybuf, 3, 1, 1 ); + alpha = scalar2ndarray( new Complex64( 5.0, 0.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 2.0, 0.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + + expected = new Complex64Array([ + 0.0, + 0.0, + // (5.0+0.0i)*(1.0+0.0i) + (2.0+0.0i)*(2.0+0.0i) + 9.0, + 0.0, + // (5.0+0.0i)*(2.0+0.0i) + (2.0+0.0i)*(3.0+0.0i) + 16.0, + 0.0, + // (5.0+0.0i)*(3.0+0.0i) + (2.0+0.0i)*(4.0+0.0i) + 23.0, + 0.0 + ]); + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided empty ndarrays, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var actual; + var alpha; + var beta; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = new Complex64Array( [] ); + ybuf = new Complex64Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + y = vector( ybuf, 0, 1, 0 ); + alpha = scalar2ndarray( new Complex64( 2.0, 1.0 ), { + 'dtype': 'complex64' + }); + beta = scalar2ndarray( new Complex64( 1.0, -1.0 ), { + 'dtype': 'complex64' + }); + + actual = caxpby( [ x, y, alpha, beta ] ); + expected = new Complex64Array( [] ); + t.strictEqual( actual, y, 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + t.end(); +});