diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md new file mode 100644 index 000000000000..a40de9dd62db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md @@ -0,0 +1,136 @@ + + +# dcartesianPower + +> Compute the Cartesian power for a double-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dcartesianPower = require( '@stdlib/blas/ext/base/ndarray/dcartesian-power' ); +``` + +#### dcartesianPower( arrays ) + +Computes the Cartesian power for a double-precision floating-point ndarray. + +```javascript +var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = new Float64Vector( [ 1.0, 2.0 ] ); +var out = zeros( [ 4, 2 ], { + 'dtype': 'float64' +}); + +var k = scalar2ndarray( 2, { + 'dtype': 'generic' +}); + +var v = dcartesianPower( [ x, out, k ] ); +// returns [ [ 1.0, 1.0 ], [ 1.0, 2.0 ], [ 2.0, 1.0 ], [ 2.0, 2.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 two-dimensional output ndarray. + - a zero-dimensional ndarray specifying the power. + +
+ + + +
+ +## Notes + +- `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple. +- For an input array of length `N`, the output array should have shape `[N^k, k]`, where `N^k` is the number of rows and `k` is the number of columns. +- If `N <= 0` or `k <= 0`, the function returns the output ndarray unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dcartesianPower = require( '@stdlib/blas/ext/base/ndarray/dcartesian-power' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 3 ], -50, 50, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ 9, 2 ], opts ); + +var k = scalar2ndarray( 2, { + 'dtype': 'generic' +}); + +var v = dcartesianPower( [ x, out, k ] ); +console.log( ndarray2array( v ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/benchmark/benchmark.js new file mode 100644 index 000000000000..df240ff63b56 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/benchmark/benchmark.js @@ -0,0 +1,116 @@ +/** +* @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/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var dcartesianPower = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; +var K = 2; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + var k; + + x = uniform( [ len ], -100.0, 100.0, options ); + out = zeros( [ pow( len, K ), K ], options ); + + k = scalar2ndarray( K, { + 'dtype': 'generic' + }); + + 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 = dcartesianPower( [ x, out, k ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( v.get( i%pow( len, K ), i%K ) ) ) { + 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/dcartesian-power/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/repl.txt new file mode 100644 index 000000000000..88dcaf2b2a96 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/repl.txt @@ -0,0 +1,39 @@ + +{{alias}}( arrays ) + Computes the Cartesian power for a double-precision floating-point ndarray. + + `k`-tuples are stored as rows in the output matrix, where the `j`-th column + contains the `j`-th element of each tuple. + + For an input array of length `N`, the output array should have shape + [N^k, k], where `N^k` is the number of rows and `k` is the number of + columns. + + If `N <= 0` or `k <= 0`, the function returns the output ndarray unchanged. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + - a zero-dimensional ndarray specifying the power. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 1.0, 2.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [ 4, 2 ], { 'dtype': 'float64' } ); + > var k = {{alias:@stdlib/ndarray/from-scalar}}( 2, { 'dtype': 'generic' } ); + > {{alias}}( [ x, out, k ] ); + > out + [ [ 1.0, 1.0 ], [ 1.0, 2.0 ], [ 2.0, 1.0 ], [ 2.0, 2.0 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/index.d.ts new file mode 100644 index 000000000000..4dcbfd288955 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @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 { float64ndarray, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the Cartesian power for a double-precision floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* - a zero-dimensional ndarray specifying the power. +* +* @param arrays - array-like object containing ndarrays +* @returns output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'float64' +* }); +* +* var k = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var v = dcartesianPower( [ x, out, k ] ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 2.0 ], [ 2.0, 1.0 ], [ 2.0, 2.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +declare function dcartesianPower( arrays: [ float64ndarray, float64ndarray, typedndarray ] ): float64ndarray; + + +// EXPORTS // + +export = dcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/test.ts new file mode 100644 index 000000000000..a3d4756e7484 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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 dcartesianPower = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [ 4, 2 ], { + 'dtype': 'float64' + }); + const k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + + dcartesianPower( [ x, out, k ] ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + dcartesianPower( '10' ); // $ExpectError + dcartesianPower( 10 ); // $ExpectError + dcartesianPower( true ); // $ExpectError + dcartesianPower( false ); // $ExpectError + dcartesianPower( null ); // $ExpectError + dcartesianPower( undefined ); // $ExpectError + dcartesianPower( [] ); // $ExpectError + dcartesianPower( {} ); // $ExpectError + dcartesianPower( ( 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': 'float64' + }); + const out = zeros( [ 4, 2 ], { + 'dtype': 'float64' + }); + const k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + + dcartesianPower(); // $ExpectError + dcartesianPower( [ x, out, k ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/examples/index.js new file mode 100644 index 000000000000..869787e1a991 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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/discrete-uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var dcartesianPower = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var x = discreteUniform( [ 3 ], -50, 50, opts ); +console.log( ndarray2array( x ) ); + +var out = zeros( [ 9, 2 ], opts ); + +var k = scalar2ndarray( 2, { + 'dtype': 'generic' +}); + +var v = dcartesianPower( [ x, out, k ] ); +console.log( ndarray2array( v ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/lib/index.js new file mode 100644 index 000000000000..42e0d5535732 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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 power for a double-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/dcartesian-power +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var dcartesianPower = require( '@stdlib/blas/ext/base/ndarray/dcartesian-power' ); +* +* var x = new Float64Vector( [ 1.0, 2.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'float64' +* }); +* +* var k = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var v = dcartesianPower( [ x, out, k ] ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 2.0 ], [ 2.0, 1.0 ], [ 2.0, 2.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/dcartesian-power/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/lib/main.js new file mode 100644 index 000000000000..349dbcaaf797 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +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/dcartesian-power' ).ndarray; + + +// MAIN // + +/** +* Computes the Cartesian power for a double-precision floating-point ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a two-dimensional output ndarray. +* - a zero-dimensional ndarray specifying the power. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {Object} output ndarray +* +* @example +* var Float64Vector = require( '@stdlib/ndarray/vector/float64' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = new Float64Vector( [ 1.0, 2.0 ] ); +* var out = zeros( [ 4, 2 ], { +* 'dtype': 'float64' +* }); +* +* var k = scalar2ndarray( 2, { +* 'dtype': 'generic' +* }); +* +* var v = dcartesianPower( [ x, out, k ] ); +* // returns [ [ 1.0, 1.0 ], [ 1.0, 2.0 ], [ 2.0, 1.0 ], [ 2.0, 2.0 ] ] +* +* var bool = ( v === out ); +* // returns true +*/ +function dcartesianPower( arrays ) { + var out; + var so; + var x; + var k; + + x = arrays[ 0 ]; + out = arrays[ 1 ]; + k = ndarraylike2scalar( arrays[ 2 ] ); + + so = getStrides( out, false ); + + strided( numelDimension( x, 0 ), k, getData( x ), getStride( x, 0 ), getOffset( x ), getData( out ), so[ 0 ], so[ 1 ], getOffset( out ) ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = dcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/package.json new file mode 100644 index 000000000000..f09e369dae3b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/dcartesian-power", + "version": "0.0.0", + "description": "Compute the Cartesian power for a double-precision 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", + "blas", + "extended", + "ext", + "linear", + "algebra", + "cartesian", + "power", + "tuples", + "product", + "array", + "ndarray", + "float64", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/test/test.js new file mode 100644 index 000000000000..8ea710f82ff9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/test/test.js @@ -0,0 +1,368 @@ +/** +* @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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var dcartesianPower = 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( 'float64', 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( 'float64', 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 dcartesianPower, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( dcartesianPower.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power (row-major, k=2)', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + out = matrix( new Float64Array( 8 ), 4, 2, 2, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power (row-major, k=3)', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + out = matrix( new Float64Array( 24 ), 8, 3, 3, 1, 0 ); + + k = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 2.0, + 1.0, + 2.0, + 1.0, + 1.0, + 2.0, + 2.0, + 2.0, + 1.0, + 1.0, + 2.0, + 1.0, + 2.0, + 2.0, + 2.0, + 1.0, + 2.0, + 2.0, + 2.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power (row-major, N=3, k=2)', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 3, 1, 0 ); + out = matrix( new Float64Array( 18 ), 9, 2, 2, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array([ + 1.0, + 1.0, + 1.0, + 2.0, + 1.0, + 3.0, + 2.0, + 1.0, + 2.0, + 2.0, + 2.0, + 3.0, + 3.0, + 1.0, + 3.0, + 2.0, + 3.0, + 3.0 + ]); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power (row-major, N=1, k=1)', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + x = vector( new Float64Array( [ 5.0 ] ), 1, 1, 0 ); + out = matrix( new Float64Array( 1 ), 1, 1, 1, 1, 0 ); + + k = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 5.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power (column-major)', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + out = matrix( new Float64Array( 8 ), 4, 2, 1, 4, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + out = matrix( new Float64Array( 8 ), 4, 2, 2, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `N` or `k` less than or equal to `0`, the function returns the output ndarray unchanged', function test( t ) { + var expected; + var out; + var x; + var k; + var v; + + out = matrix( new Float64Array( [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ), 4, 2, 2, 1, 0 ); + expected = new Float64Array( [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 0, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + + k = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + + k = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 k; + var v; + + x = vector( new Float64Array( [ 1.0, 0.0, 2.0, 0.0 ] ), 2, 2, 0 ); + out = matrix( new Float64Array( 8 ), 4, 2, 2, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 k; + var v; + + x = vector( new Float64Array( [ 2.0, 1.0 ] ), 2, -1, 1 ); + out = matrix( new Float64Array( 8 ), 4, 2, 2, 1, 0 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 k; + var v; + + x = vector( new Float64Array( [ 99.0, 1.0, 2.0 ] ), 2, 1, 1 ); + out = matrix( new Float64Array( 10 ), 4, 2, 2, 1, 2 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( 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 k; + var v; + + x = vector( new Float64Array( [ 1.0, 2.0 ] ), 2, 1, 0 ); + out = matrix( new Float64Array( 8 ), 4, 2, -2, 1, 6 ); + + k = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + v = dcartesianPower( [ x, out, k ] ); + + expected = new Float64Array( [ 2.0, 2.0, 2.0, 1.0, 1.0, 2.0, 1.0, 1.0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( v ), expected ), true, 'returns expected value' ); + t.end(); +});