From 854f7136d76aa4eebaf0174220009a2d11524a98 Mon Sep 17 00:00:00 2001 From: Mayur Jogade Date: Sun, 8 Nov 2026 22:50:25 +0530 Subject: [PATCH] feat: add `blas/ext/base/ndarray/zcartesian-product` --- 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 --- --- .../base/ndarray/zcartesian-product/README.md | 133 ++++++++ .../zcartesian-product/benchmark/benchmark.js | 115 +++++++ .../ndarray/zcartesian-product/docs/repl.txt | 41 +++ .../zcartesian-product/docs/types/index.d.ts | 60 ++++ .../zcartesian-product/docs/types/test.ts | 69 ++++ .../zcartesian-product/examples/index.js | 42 +++ .../ndarray/zcartesian-product/lib/index.js | 51 +++ .../ndarray/zcartesian-product/lib/main.js | 82 +++++ .../ndarray/zcartesian-product/package.json | 70 +++++ .../ndarray/zcartesian-product/test/test.js | 297 ++++++++++++++++++ 10 files changed, 960 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/README.md new file mode 100644 index 000000000000..470e1b11a566 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/README.md @@ -0,0 +1,133 @@ + + +# zcartesianProduct + +> Compute the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays. + +
+ +
+ + + +
+ +## Usage + +```javascript +var zcartesianProduct = require( '@stdlib/blas/ext/base/ndarray/zcartesian-product' ); +``` + +#### zcartesianProduct( arrays ) + +Computes the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays. + +```javascript +var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +var y = new Complex128Vector( [ 5.0, 6.0, 7.0, 8.0 ] ); +var out = zeros( [ 4, 2 ], { + 'dtype': 'complex128' +}); + +var v = zcartesianProduct( [ x, y, out ] ); +// returns [ [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ], [ 7.0, 8.0 ] ], [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ], [ [ 3.0, 4.0 ], [ 7.0, 8.0 ] ] ] + +var bool = ( v === out ); +// returns true +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + +
+ + + +
+ +## Notes + +- Pairs are stored as rows in the output matrix, where the first column contains the first element of each pair and the second column contains the second element. +- For input arrays `x` of length `M` and `y` of length `N`, the output array should have shape `[M*N, 2]`, where `M*N` is the number of rows and `2` is the number of columns. +- If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zcartesianProduct = require( '@stdlib/blas/ext/base/ndarray/zcartesian-product' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Complex128Vector( discreteUniform( 6, -50, 50, opts ) ); +console.log( ndarray2array( x ) ); + +var y = new Complex128Vector( discreteUniform( 4, -50, 50, opts ) ); +console.log( ndarray2array( y ) ); + +var out = zeros( [ 6, 2 ], { + 'dtype': 'complex128' +}); + +var v = zcartesianProduct( [ x, y, out ] ); +console.log( ndarray2array( v ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/benchmark/benchmark.js new file mode 100644 index 000000000000..fe7487113f63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @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 Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var real = require( '@stdlib/complex/float64/real' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var zcartesianProduct = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + var y; + + x = new Complex128Vector( uniform( len*2, -100.0, 100.0, options ) ); + y = new Complex128Vector( uniform( len*2, -100.0, 100.0, options ) ); + out = zeros( [ len*len, 2 ], { + 'dtype': 'complex128' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = zcartesianProduct( [ x, y, out ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( real( v.get( i%(len*len), i%2 ) ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 3; // 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/zcartesian-product/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/repl.txt new file mode 100644 index 000000000000..4e43096a80b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/repl.txt @@ -0,0 +1,41 @@ + +{{alias}}( arrays ) + Computes the Cartesian product for two one-dimensional double-precision + complex floating-point ndarrays. + + Pairs are stored as rows in the output matrix, where the first column + contains the first element of each pair and the second column contains the + second element. + + For input arrays `x` of length `M` and `y` of length `N`, the output array + should have shape [M*N, 2], where `M*N` is the number of rows and `2` is + the number of columns. + + If `M <= 0` or `N <= 0`, the function returns the output ndarray unchanged. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/complex128}}( [ 1.0, 2.0 ] ); + > var y = new {{alias:@stdlib/ndarray/vector/complex128}}( [ 3.0, 4.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [ 1, 2 ], { 'dtype': 'complex128' } ); + > {{alias}}( [ x, y, out ] ); + > out + [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/index.d.ts new file mode 100644 index 000000000000..888e2422a8aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/index.d.ts @@ -0,0 +1,60 @@ +/* +* @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 } from '@stdlib/types/ndarray'; + +/** +* Computes the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex128Vector( [ 5.0, 6.0, 7.0, 8.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'complex128' +* }); +* +* var v = zcartesianProduct( [ x, y, out ] ); +* // returns [ [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ], [ 7.0, 8.0 ] ], [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ], [ [ 3.0, 4.0 ], [ 7.0, 8.0 ] ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +declare function zcartesianProduct( arrays: [ complex128ndarray, complex128ndarray, complex128ndarray ] ): complex128ndarray; + + +// EXPORTS // + +export = zcartesianProduct; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/test.ts new file mode 100644 index 000000000000..7fb7ead508b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @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 zcartesianProduct = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2 ], { + 'dtype': 'complex128' + }); + const y = zeros( [ 2 ], { + 'dtype': 'complex128' + }); + const out = zeros( [ 4, 2 ], { + 'dtype': 'complex128' + }); + + zcartesianProduct( [ x, y, out ] ); // $ExpectType complex128ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + zcartesianProduct( '10' ); // $ExpectError + zcartesianProduct( 10 ); // $ExpectError + zcartesianProduct( true ); // $ExpectError + zcartesianProduct( false ); // $ExpectError + zcartesianProduct( null ); // $ExpectError + zcartesianProduct( undefined ); // $ExpectError + zcartesianProduct( [] ); // $ExpectError + zcartesianProduct( {} ); // $ExpectError + zcartesianProduct( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2 ], { + 'dtype': 'complex128' + }); + const y = zeros( [ 2 ], { + 'dtype': 'complex128' + }); + const out = zeros( [ 4, 2 ], { + 'dtype': 'complex128' + }); + + zcartesianProduct(); // $ExpectError + zcartesianProduct( [ x, y, out ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/examples/index.js new file mode 100644 index 000000000000..1de758125c84 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/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 zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zcartesianProduct = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = new Complex128Vector( discreteUniform( 6, -50, 50, opts ) ); +console.log( ndarray2array( x ) ); + +var y = new Complex128Vector( discreteUniform( 4, -50, 50, opts ) ); +console.log( ndarray2array( y ) ); + +var out = zeros( [ 6, 2 ], { + 'dtype': 'complex128' +}); + +var v = zcartesianProduct( [ x, y, out ] ); +console.log( ndarray2array( v ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/index.js new file mode 100644 index 000000000000..9e19d0d127e1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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'; + +/** +* Compute the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays. +* +* @module @stdlib/blas/ext/base/ndarray/zcartesian-product +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var zcartesianProduct = require( '@stdlib/blas/ext/base/ndarray/zcartesian-product' ); +* +* var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex128Vector( [ 5.0, 6.0, 7.0, 8.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'complex128' +* }); +* +* var v = zcartesianProduct( [ x, y, out ] ); +* // returns [ [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ], [ 7.0, 8.0 ] ], [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ], [ [ 3.0, 4.0 ], [ 7.0, 8.0 ] ] ] +* +* var bool = ( v === out ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/main.js new file mode 100644 index 000000000000..b3816ebb4b9b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/lib/main.js @@ -0,0 +1,82 @@ +/** +* @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 getStrides = require( '@stdlib/ndarray/base/strides' ); +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/zcartesian-product' ).ndarray; + + +// MAIN // + +/** +* Computes the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var y = new Complex128Vector( [ 5.0, 6.0, 7.0, 8.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'complex128' +* }); +* +* var v = zcartesianProduct( [ x, y, out ] ); +* // returns [ [ [ 1.0, 2.0 ], [ 5.0, 6.0 ] ], [ [ 1.0, 2.0 ], [ 7.0, 8.0 ] ], [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ], [ [ 3.0, 4.0 ], [ 7.0, 8.0 ] ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +function zcartesianProduct( arrays ) { + var out; + var so; + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + out = arrays[ 2 ]; + + so = getStrides( out, false ); + + strided( numelDimension( x, 0 ), numelDimension( y, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( y ), getStride( y, 0 ), getOffset( y ), getData( out ), so[ 0 ], so[ 1 ], getOffset( out ) ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = zcartesianProduct; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/package.json new file mode 100644 index 000000000000..a5af0d4cc5b9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/zcartesian-product", + "version": "0.0.0", + "description": "Compute the Cartesian product for two one-dimensional double-precision complex floating-point ndarrays.", + "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", + "blas", + "extended", + "ext", + "linear", + "algebra", + "cartesian", + "product", + "pairs", + "tuples", + "array", + "ndarray", + "complex128", + "complex", + "double", + "complex128array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/test/test.js new file mode 100644 index 000000000000..c2997fa90d08 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zcartesian-product/test/test.js @@ -0,0 +1,297 @@ +/** +* @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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var zcartesianProduct = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} N - number of elements +* @param {integer} stride - stride +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, N, stride, offset ) { + return new ndarray( 'complex128', buffer, [ N ], [ stride ], offset, 'row-major' ); +} + +/** +* Returns a two-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} M - number of rows +* @param {NonNegativeInteger} N - number of columns +* @param {integer} stride0 - stride of the first dimension +* @param {integer} stride1 - stride of the second dimension +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} two-dimensional ndarray +*/ +function matrix( buffer, M, N, stride0, stride1, offset ) { + return new ndarray( 'complex128', buffer, [ M, N ], [ stride0, stride1 ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zcartesianProduct, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( zcartesianProduct.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the Cartesian product (row-major)', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 0 ); + out = matrix( new Complex128Array( 8 ), 4, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 4.0, 4.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 4.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian product (row-major, M=3, N=2)', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 3, 1, 0 ); + y = vector( new Complex128Array( [ 4.0, 4.0, 5.0, 5.0 ] ), 2, 1, 0 ); + out = matrix( new Complex128Array( 12 ), 6, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array([ + 1.0, + 1.0, + 4.0, + 4.0, + 1.0, + 1.0, + 5.0, + 5.0, + 2.0, + 2.0, + 4.0, + 4.0, + 2.0, + 2.0, + 5.0, + 5.0, + 3.0, + 3.0, + 4.0, + 4.0, + 3.0, + 3.0, + 5.0, + 5.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian product (row-major, M=1, N=1)', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 5.0, 5.0 ] ), 1, 1, 0 ); + y = vector( new Complex128Array( [ 7.0, 7.0 ] ), 1, 1, 0 ); + out = matrix( new Complex128Array( 2 ), 1, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 5.0, 5.0, 7.0, 7.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian product (column-major)', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 0 ); + out = matrix( new Complex128Array( 8 ), 4, 2, 1, 4, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 3.0, 3.0, 4.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output ndarray', function test( t ) { + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 0 ); + out = matrix( new Complex128Array( 8 ), 4, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `M` or `N` less than or equal to `0`, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + out = matrix( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0, 9.0, 9.0, 10.0, 10.0 ] ), 4, 2, 2, 1, 0 ); + expected = new Complex128Array( [ 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0, 9.0, 9.0, 10.0, 10.0 ] ); + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 0, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 0, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays with strides', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0 ] ), 2, 2, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 0.0, 0.0, 4.0, 4.0, 0.0, 0.0 ] ), 2, 2, 0 ); + out = matrix( new Complex128Array( 8 ), 4, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 4.0, 4.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 4.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports input ndarrays with negative strides', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 2.0, 2.0, 1.0, 1.0 ] ), 2, -1, 1 ); + y = vector( new Complex128Array( [ 4.0, 4.0, 3.0, 3.0 ] ), 2, -1, 1 ); + out = matrix( new Complex128Array( 8 ), 4, 2, 2, 1, 0 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 4.0, 4.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 4.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays having non-zero offsets', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 99.0, 99.0, 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 1 ); + y = vector( new Complex128Array( [ 99.0, 99.0, 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 1 ); + out = matrix( new Complex128Array( 10 ), 4, 2, 2, 1, 2 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 3.0, 3.0, 1.0, 1.0, 4.0, 4.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 4.0, 4.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports output ndarrays with negative strides', function test( t ) { + var expected; + var out; + var x; + var y; + var v; + + x = vector( new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ), 2, 1, 0 ); + y = vector( new Complex128Array( [ 3.0, 3.0, 4.0, 4.0 ] ), 2, 1, 0 ); + out = matrix( new Complex128Array( 8 ), 4, 2, -2, 1, 6 ); + + v = zcartesianProduct( [ x, y, out ] ); + + expected = new Complex128Array( [ 2.0, 2.0, 4.0, 4.0, 2.0, 2.0, 3.0, 3.0, 1.0, 1.0, 4.0, 4.0, 1.0, 1.0, 3.0, 3.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});