From e1fff21861499deeeeb3c9edbf03f4b5ab6a34ca Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 31 May 2026 14:48:20 -0700 Subject: [PATCH] feat: add `blas/ext/base/ndarray/zxsa` --- 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/zxsa/README.md | 128 ++++++++++++++ .../base/ndarray/zxsa/benchmark/benchmark.js | 108 ++++++++++++ .../blas/ext/base/ndarray/zxsa/docs/repl.txt | 34 ++++ .../base/ndarray/zxsa/docs/types/index.d.ts | 58 +++++++ .../ext/base/ndarray/zxsa/docs/types/test.ts | 65 +++++++ .../ext/base/ndarray/zxsa/examples/index.js | 42 +++++ .../blas/ext/base/ndarray/zxsa/lib/index.js | 49 ++++++ .../blas/ext/base/ndarray/zxsa/lib/main.js | 73 ++++++++ .../blas/ext/base/ndarray/zxsa/package.json | 74 ++++++++ .../blas/ext/base/ndarray/zxsa/test/test.js | 164 ++++++++++++++++++ 10 files changed, 795 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/README.md new file mode 100644 index 000000000000..109a1bcfb675 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/README.md @@ -0,0 +1,128 @@ + + +# zxsa + +> Subtract a scalar constant from each element in a one-dimensional double-precision complex floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var zxsa = require( '@stdlib/blas/ext/base/ndarray/zxsa' ); +``` + +#### zxsa( arrays ) + +Subtracts a scalar constant from each element in a one-dimensional double-precision complex floating-point ndarray. + +```javascript +var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Complex128Vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' +}); + +zxsa( [ x, alpha ] ); +// x => [ [ -7.0, 1.0 ], [ -2.0, -5.0 ], [ -1.0, 0.0 ], [ -6.0, -3.0 ] ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to subtract. + +
+ + + +
+ +## Notes + +- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zxsa = require( '@stdlib/blas/ext/base/ndarray/zxsa' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Complex128Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( new Complex128( 5.0, -3.0 ), { + 'dtype': 'complex128' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +zxsa( [ x, alpha ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/benchmark/benchmark.js new file mode 100644 index 000000000000..16047e107294 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @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 Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var zxsa = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var xbuf; + var x; + + xbuf = uniform( len*2, -100.0, 100.0, { + 'dtype': 'float64' + }); + x = new Complex128Vector( xbuf.buffer ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + 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 = zxsa( [ x, alpha ] ); + 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/zxsa/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/repl.txt new file mode 100644 index 000000000000..407d20b1ff10 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( arrays ) + Subtracts a scalar constant from each element in a one-dimensional double- + precision complex floating-point ndarray. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant to subtract. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = [ -2.0, 1.0, 3.0, -5.0 ]; + > var x = new {{alias:@stdlib/ndarray/vector/complex128}}( buf ); + > var opts = { 'dtype': 'complex128' }; + > var a = new {{alias:@stdlib/complex/float64/ctor}}( 5.0, 0.0 ); + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( a, opts ); + > {{alias}}( [ x, alpha ] ) + [ [ -7.0, 1.0 ], [ -2.0, -5.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/index.d.ts new file mode 100644 index 000000000000..043349b5eca0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/index.d.ts @@ -0,0 +1,58 @@ +/* +* @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 { complex128ndarray, typedndarray } from '@stdlib/types/ndarray'; +import { Complex128 } from '@stdlib/types/complex'; + +/** +* Subtracts a scalar constant from each element in a one-dimensional double-precision complex floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to subtract. +* +* @param arrays - array-like object containing ndarrays +* @returns input ndarray +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Complex128Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* +* var alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { +* 'dtype': 'complex128' +* }); +* +* var out = zxsa( [ x, alpha ] ); +* // returns [ [ -7.0, 1.0 ], [ -2.0, -5.0 ] ] +*/ +declare function zxsa( arrays: [ complex128ndarray, typedndarray ] ): complex128ndarray; + + +// EXPORTS // + +export = zxsa; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/test.ts new file mode 100644 index 000000000000..86385be62205 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/docs/types/test.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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import Complex128 = require( '@stdlib/complex/float64/ctor' ); +import zxsa = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'complex128' + }); + const alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + zxsa( [ x, alpha ] ); // $ExpectType complex128ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + zxsa( '10' ); // $ExpectError + zxsa( 5 ); // $ExpectError + zxsa( true ); // $ExpectError + zxsa( false ); // $ExpectError + zxsa( null ); // $ExpectError + zxsa( undefined ); // $ExpectError + zxsa( [] ); // $ExpectError + zxsa( {} ); // $ExpectError + zxsa( ( 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': 'complex128' + }); + const alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + zxsa(); // $ExpectError + zxsa( [ x, alpha ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/examples/index.js new file mode 100644 index 000000000000..2149ad23e8b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var zxsa = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Complex128Vector( discreteUniform( 20, -100, 100, opts ) ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( new Complex128( 5.0, -3.0 ), { + 'dtype': 'complex128' +}); +console.log( 'Alpha:', ndarraylike2scalar( alpha ) ); + +zxsa( [ x, alpha ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/index.js new file mode 100644 index 000000000000..0272de7ba80b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/index.js @@ -0,0 +1,49 @@ +/** +* @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'; + +/** +* Subtract a scalar constant from each element in a one-dimensional double-precision complex floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/zxsa +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var zxsa = require( '@stdlib/blas/ext/base/ndarray/zxsa' ); +* +* var x = new Complex128Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* +* var alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { +* 'dtype': 'complex128' +* }); +* +* var out = zxsa( [ x, alpha ] ); +* // returns [ [ -7.0, 1.0 ], [ -2.0, -5.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/main.js new file mode 100644 index 000000000000..8c6f4ebb0aa7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/lib/main.js @@ -0,0 +1,73 @@ +/** +* @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/zxsa' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Subtracts a scalar constant from each element in a one-dimensional double-precision complex floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant to subtract. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Complex128Vector( [ -2.0, 1.0, 3.0, -5.0 ] ); +* +* var alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { +* 'dtype': 'complex128' +* }); +* +* var out = zxsa( [ x, alpha ] ); +* // returns [ [ -7.0, 1.0 ], [ -2.0, -5.0 ] ] +*/ +function zxsa( arrays ) { + var alpha; + var x; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + strided( numelDimension( x, 0 ), alpha, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = zxsa; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/package.json new file mode 100644 index 000000000000..237a3210d21d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/zxsa", + "version": "0.0.0", + "description": "Subtract a scalar constant from each element in a one-dimensional double-precision complex floating-point 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", + "zxsa", + "xsa", + "subtract", + "scalar", + "constant", + "strided", + "array", + "ndarray", + "complex128", + "complex", + "double", + "double-precision", + "float64" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/test/test.js new file mode 100644 index 000000000000..1df839a15d18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxsa/test/test.js @@ -0,0 +1,164 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var zxsa = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Complex128Array} 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( 'complex128', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zxsa, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function subtracts a scalar constant from each element', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 5, 1, 0 ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = zxsa( [ x, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Complex128Array( [ -7.0, 1.0, -2.0, -5.0, -1.0, 0.0, -6.0, -3.0, -3.0, 1.0 ] ); + t.deepEqual( xbuf, expected, '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 xbuf; + var x; + + xbuf = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + x = vector( xbuf, 2, 2, 0 ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = zxsa( [ x, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Complex128Array( [ -7.0, 1.0, 3.0, -5.0, -1.0, 0.0, -1.0, -3.0 ] ); + t.deepEqual( xbuf, expected, '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 xbuf; + var x; + + xbuf = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 5, -1, 4 ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = zxsa( [ x, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Complex128Array( [ -7.0, 1.0, -2.0, -5.0, -1.0, 0.0, -6.0, -3.0, -3.0, 1.0 ] ); + t.deepEqual( xbuf, expected, '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 xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 0.0, -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, 2.0, 1.0 ] ); + x = vector( xbuf, 3, 1, 2 ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = zxsa( [ x, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Complex128Array( [ 1.0, 0.0, -2.0, 1.0, -2.0, -5.0, -1.0, 0.0, -6.0, -3.0, 2.0, 1.0 ] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex128Array( [] ); + x = vector( xbuf, 0, 1, 0 ); + alpha = scalar2ndarray( new Complex128( 5.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = zxsa( [ x, alpha ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = new Complex128Array( [] ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +});