diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/README.md new file mode 100644 index 000000000000..40b2b3d5f485 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/README.md @@ -0,0 +1,192 @@ + + +# gcartesianPower + +> Compute the Cartesian power for a strided array. + +
+ +## Usage + +```javascript +var gcartesianPower = require( '@stdlib/blas/ext/base/gcartesian-power' ); +``` + +#### gcartesianPower( order, N, k, x, strideX, out, LDO ) + +Computes the Cartesian power for a strided array. + +```javascript +var x = [ 1.0, 2.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + +The function has the following parameters: + +- **order**: storage layout. Must be either `'row-major'` or `'column-major'`. +- **N**: number of indexed elements. +- **k**: power. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`). + +The `N`, `k`, and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian power of every other element: + +```javascript +var x = [ 1.0, 0.0, 2.0, 0.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gcartesianPower( 'row-major', 2, 2, x, 2, out, 2 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Output array: +var out = new Float64Array( 8 ); + +gcartesianPower( 'row-major', 2, 2, x1, 1, out, 2 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + + + +#### gcartesianPower.ndarray( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) + + + +Computes the Cartesian power for a strided array using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: power. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **offsetX**: starting index for `x`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideOut1**: stride length for the first dimension of `out`. +- **strideOut2**: stride length for the second dimension of `out`. +- **offsetOut**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last two elements: + +```javascript +var x = [ 0.0, 0.0, 1.0, 2.0 ]; +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gcartesianPower.ndarray( 2, 2, x, 1, 2, out, 2, 1, 0 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + +
+ + + +
+ +## 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 must contain at least `N^k * k` indexed elements. +- For row-major order, the `LDO` parameter must be greater than or equal to `max(1,k)`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N^k)`. +- If `N <= 0` or `k <= 0`, both functions return `out` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). +- Depending on the environment, the typed versions ([`dcartesianPower`][@stdlib/blas/ext/base/dcartesian-power], [`scartesianPower`][@stdlib/blas/ext/base/scartesian-power], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var gcartesianPower = require( '@stdlib/blas/ext/base/gcartesian-power' ); + +var N = 2; +var k = 3; +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( pow( N, k ) * k, 'generic' ); +gcartesianPower( 'row-major', N, k, x, 1, out, k ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/benchmark/benchmark.js new file mode 100644 index 000000000000..82b32818f878 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcartesianPower = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; +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; + + x = uniform( len, -10.0, 10.0, options ); + out = zeros( pow( len, K ) * K, options.dtype ); + 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 = gcartesianPower( 'row-major', x.length, K, x, 1, out, K ); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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/gcartesian-power/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..cec4ff81dbfe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/benchmark/benchmark.ndarray.js @@ -0,0 +1,109 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcartesianPower = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; +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; + + x = uniform( len, -10.0, 10.0, options ); + out = zeros( pow( len, K ) * K, options.dtype ); + 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 = gcartesianPower( x.length, K, x, 1, 0, out, K, 1, 0 ); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/repl.txt new file mode 100644 index 000000000000..00d39597dab6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/repl.txt @@ -0,0 +1,128 @@ + +{{alias}}( order, N, k, x, strideX, out, LDO ) + Computes the Cartesian power for a strided array. + + `k`-tuples are stored as rows in the output matrix, where the `j`-th column + contains the `j`-th element of each tuple. + + The `N`, `k`, and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + If `N <= 0` or `k <= 0`, the function returns `out` unchanged. + + The function supports array-like objects having getter and setter accessors + for array element access. + + Parameters + ---------- + order: string + Row-major (C-style) or column-major (Fortran-style) order. + + N: integer + Number of indexed elements. + + k: integer + Power. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + out: ArrayLikeObject + Output array. + + LDO: integer + Stride length between successive contiguous vectors of the matrix `out` + (a.k.a., leading dimension of `out`). + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', x.length, 2, x, 1, out, 2 ) + [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + + // Using `N` and stride parameters: + > x = [ 1.0, 0.0, 2.0, 0.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 'row-major', 2, 2, x, 2, out, 2 ) + [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > out = new {{alias:@stdlib/array/float64}}( 8 ); + > {{alias}}( 'row-major', 2, 2, x1, 1, out, 2 ) + [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + + +{{alias}}.ndarray( N, k, x, sx, ox, out, so1, so2, oo ) + Computes the Cartesian power for a strided array using alternative indexing + semantics. + + `k`-tuples are stored as rows in the output matrix, where the `j`-th column + contains the `j`-th element of each tuple. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Power. + + x: ArrayLikeObject + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + out: ArrayLikeObject + Output array. + + so1: integer + Stride length for the first dimension of `out`. + + so2: integer + Stride length for the second dimension of `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0 ]; + > var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ) + [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + + // Using an index offset: + > x = [ 0.0, 0.0, 1.0, 2.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, 2, x, 1, 2, out, 2, 1, 0 ) + [ 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/gcartesian-power/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/types/index.d.ts new file mode 100644 index 000000000000..39301471765c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/types/index.d.ts @@ -0,0 +1,124 @@ +/* +* @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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gcartesianPower`. +*/ +interface Routine { + /** + * Computes the Cartesian power for a strided array. + * + * ## Notes + * + * - `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple. + * + * @param order - storage layout + * @param N - number of indexed elements + * @param k - power + * @param x - input array + * @param strideX - stride length for `x` + * @param out - output array + * @param LDO - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) + * @returns output array + * + * @example + * var x = [ 1.0, 2.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); + * // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + */ + = OutputArray>( order: Layout, N: number, k: number, x: InputArray, strideX: number, out: U, LDO: number ): U; + + /** + * Computes the Cartesian power for a strided array using alternative indexing semantics. + * + * ## Notes + * + * - `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple. + * + * @param N - number of indexed elements + * @param k - power + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param out - output array + * @param strideOut1 - stride length for the first dimension of `out` + * @param strideOut2 - stride length for the second dimension of `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var x = [ 1.0, 2.0 ]; + * var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + * + * gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); + * // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + */ + ndarray = OutputArray>( N: number, k: number, x: InputArray, strideX: number, offsetX: number, out: U, strideOut1: number, strideOut2: number, offsetOut: number ): U; +} + +/** +* Computes the Cartesian power for a strided array. +* +* @param order - storage layout +* @param N - number of indexed elements +* @param k - power +* @param x - input array +* @param strideX - stride length for `x` +* @param out - output array +* @param LDO - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) +* @returns output array +* +* @example +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +* +* @example +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +declare var gcartesianPower: Routine; + + +// EXPORTS // + +export = gcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/types/test.ts new file mode 100644 index 000000000000..e91cb9f14f24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/docs/types/test.ts @@ -0,0 +1,307 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import gcartesianPower = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); // $ExpectType Float64Array + gcartesianPower( 'row-major', x.length, 2, new AccessorArray( x ), 1, new AccessorArray( out ), 2 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a valid order... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 10, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( true, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( false, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( null, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( undefined, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( [], x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( {}, x.length, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( ( x: number ): number => x, x.length, 2, x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', '10', 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', true, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', false, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', null, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', undefined, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', [], 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', {}, 2, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', ( x: number ): number => x, 2, x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', x.length, '10', x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, true, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, false, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, null, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, undefined, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, [], x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, {}, x, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, ( x: number ): number => x, x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', 2, 2, 10, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, true, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, false, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, null, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, undefined, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, {}, 1, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', 2, 2, ( x: number ): number => x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', x.length, 2, x, '10', out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, true, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, false, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, null, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, undefined, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, [], out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, {}, out, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, ( x: number ): number => x, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + + gcartesianPower( 'row-major', x.length, 2, x, 1, 10, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, true, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, false, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, null, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, undefined, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, {}, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower( 'row-major', x.length, 2, x, 1, out, '10' ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, true ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, false ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, null ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, undefined ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, [] ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, {} ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower(); // $ExpectError + gcartesianPower( 'row-major' ); // $ExpectError + gcartesianPower( 'row-major', x.length ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1 ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out ); // $ExpectError + gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectType Float64Array + gcartesianPower.ndarray( x.length, 2, new AccessorArray( x ), 1, 0, new AccessorArray( out ), 2, 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( '10', 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( true, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( false, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( null, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( undefined, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( [], 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( {}, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( ( x: number ): number => x, 2, x, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, '10', x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, true, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, false, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, null, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, undefined, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, [], x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, {}, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, ( x: number ): number => x, x, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( 2, 2, 10, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, true, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, false, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, null, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, undefined, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, {}, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( 2, 2, ( x: number ): number => x, 1, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, '10', 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, true, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, false, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, null, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, undefined, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, [], 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, {}, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, ( x: number ): number => x, 0, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, '10', out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, true, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, false, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, null, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, undefined, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, [], out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, {}, out, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, ( x: number ): number => x, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a collection... +{ + const x = new Float64Array( 2 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, 0, 10, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, true, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, false, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, null, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, undefined, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, {}, 2, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, ( x: number ): number => x, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, '10', 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, true, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, false, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, null, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, [], 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, {}, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, '10', 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, true, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, false, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, null, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, undefined, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, [], 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, {}, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, '10' ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, true ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, false ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, null ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, undefined ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, [] ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, {} ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 2 ); + const out = new Float64Array( 8 ); + + gcartesianPower.ndarray(); // $ExpectError + gcartesianPower.ndarray( x.length ); // $ExpectError + gcartesianPower.ndarray( x.length, 2 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1 ); // $ExpectError + gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/examples/index.js new file mode 100644 index 000000000000..5a41286c65d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/examples/index.js @@ -0,0 +1,35 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var gcartesianPower = require( './../lib' ); + +var N = 2; +var k = 3; +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( pow( N, k ) * k, 'generic' ); +gcartesianPower( 'row-major', N, k, x, 1, out, k ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/accessors.js new file mode 100644 index 000000000000..e3902c044d5b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/accessors.js @@ -0,0 +1,113 @@ +/** +* @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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var pow = require( '@stdlib/math/base/special/pow' ); + + +// MAIN // + +/** +* Computes the Cartesian power for a strided array using alternative indexing semantics. +* +* @private +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NonNegativeInteger} k - power +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} out - output array object +* @param {Collection} out.data - output array data +* @param {Array} out.accessors - array element accessors +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower( 2, 2, arraylike2object( toAccessorArray( [ 1.0, 2.0 ] ) ), 1, 0, arraylike2object( out ), 2, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +function gcartesianPower( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var xbuf; + var obuf; + var xget; + var oset; + var len; + var oj; + var io; + var ix; + var sj; + var i; + var j; + var s; + var t; + + // Cache references to array data: + xbuf = x.data; + obuf = out.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + len = pow( N, k ); + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + io = offsetOut; + for ( i = 0; i < len; i++ ) { + t = i; + for ( j = k-1; j >= 0; j-- ) { + s = t % N; + t = (t-s) / N; + ix = offsetX + (s*strideX); + oj = io + (j*strideOut2); + oset( obuf, oj, xget( xbuf, ix ) ); + } + io += strideOut1; + } + } else { // isColMajor + sj = len; + for ( j = 0; j < k; j++ ) { + sj /= N; + io = offsetOut + (j*strideOut2); + for ( i = 0; i < len; i++ ) { + s = ((i-(i%sj))/sj) % N; + ix = offsetX + (s*strideX); + oset( obuf, io, xget( xbuf, ix ) ); + io += strideOut1; + } + } + } + return out; +} + + +// EXPORTS // + +module.exports = gcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/index.js new file mode 100644 index 000000000000..dc0a5fa3c2be --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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 strided array. +* +* @module @stdlib/blas/ext/base/gcartesian-power +* +* @example +* var gcartesianPower = require( '@stdlib/blas/ext/base/gcartesian-power' ); +* +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +* +* @example +* var gcartesianPower = require( '@stdlib/blas/ext/base/gcartesian-power' ); +* +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/main.js new file mode 100644 index 000000000000..eff9cc7b67d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/main.js @@ -0,0 +1,81 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the Cartesian power for a strided array. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NonNegativeInteger} k - power +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} out - output array +* @param {integer} LDO - stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} seventh argument must be a valid stride length +* @returns {Collection} output array +* +* @example +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +function gcartesianPower( order, N, k, x, strideX, out, LDO ) { + var sa1; + var sa2; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isColumnMajor( order ) ) { + if ( LDO < max( 1, pow( N, k ) ) ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be greater than or equal to max(1,%d). Value: `%d`.', pow( N, k ), LDO ) ); + } + sa1 = 1; + sa2 = LDO; + } else { // order === 'row-major' + if ( LDO < max( 1, k ) ) { + throw new RangeError( format( 'invalid argument. Seventh argument must be greater than or equal to max(1,%d). Value: `%d`.', k, LDO ) ); + } + sa1 = LDO; + sa2 = 1; + } + return ndarray( N, k, x, strideX, stride2offset( N, strideX ), out, sa1, sa2, 0 ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/ndarray.js new file mode 100644 index 000000000000..945c41169779 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/lib/ndarray.js @@ -0,0 +1,111 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the Cartesian power for a strided array using alternative indexing semantics. +* +* ## Notes +* +* - `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple. +* +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NonNegativeInteger} k - power +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} out - output array +* @param {integer} strideOut1 - stride length for the first dimension of `out` +* @param {integer} strideOut2 - stride length for the second dimension of `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianPower( x.length, 2, x, 1, 0, out, 2, 1, 0 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +function gcartesianPower( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var len; + var ox; + var oo; + var oj; + var io; + var ix; + var sj; + var i; + var j; + var s; + var t; + + if ( N <= 0 || k <= 0 ) { + return out; + } + ox = arraylike2object( x ); + oo = arraylike2object( out ); + if ( ox.accessorProtocol || oo.accessorProtocol ) { + accessors( N, k, ox, strideX, offsetX, oo, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len + return out; + } + len = pow( N, k ); + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + io = offsetOut; + for ( i = 0; i < len; i++ ) { + t = i; + for ( j = k-1; j >= 0; j-- ) { + s = t % N; + t = (t-s) / N; + ix = offsetX + (s*strideX); + oj = io + (j*strideOut2); + out[ oj ] = x[ ix ]; + } + io += strideOut1; + } + } else { // isColMajor + sj = len; + for ( j = 0; j < k; j++ ) { + sj /= N; + io = offsetOut + (j*strideOut2); + for ( i = 0; i < len; i++ ) { + s = ((i-(i%sj))/sj) % N; + ix = offsetX + (s*strideX); + out[ io ] = x[ ix ]; + io += strideOut1; + } + } + } + return out; +} + + +// EXPORTS // + +module.exports = gcartesianPower; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/package.json new file mode 100644 index 000000000000..9bdb33ebd643 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gcartesian-power", + "version": "0.0.0", + "description": "Compute the Cartesian power for a strided array.", + "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", + "cartesian", + "product", + "power", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.js new file mode 100644 index 000000000000..d340bdfddcf1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 gcartesianPower = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianPower, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gcartesianPower.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.main.js new file mode 100644 index 000000000000..08ae4596a0ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.main.js @@ -0,0 +1,672 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var gcartesianPower = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianPower, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gcartesianPower.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function throws if the first argument is not a valid order', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 1, + 0, + null, + true, + false, + void 0, + [], + {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + var x = [ 1.0, 2.0 ]; + gcartesianPower( value, x.length, 2, x, 1, out, 2 ); + }; + } +}); + +tape( 'the function throws if the seventh argument is less than max(1,k) for row-major order', function test( t ) { + t.throws( badValue, RangeError, 'throws a range error' ); + t.end(); + + function badValue() { + var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + var x = [ 1.0, 2.0 ]; + gcartesianPower( 'row-major', x.length, 3, x, 1, out, 2 ); + } +}); + +tape( 'the function throws if the seventh argument is less than max(1,N^k) for column-major order', function test( t ) { + t.throws( badValue, RangeError, 'throws a range error' ); + t.end(); + + function badValue() { + var out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + var x = [ 1.0, 2.0, 3.0 ]; + gcartesianPower( 'column-major', 3, 2, x, 1, out, 8 ); + } +}); + +tape( 'the function computes the Cartesian power', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 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 + ]; + + gcartesianPower( 'row-major', x.length, 3, x, 1, out, 3 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + out = [ 0.0 ]; + expected = [ 5.0 ]; + + gcartesianPower( 'row-major', 1, 1, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', x.length, 2, x, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 1.0, + 1.0, + 2.0, + 2.0, + 2.0, + 2.0, + 1.0, + 1.0, + 2.0, + 2.0, + 1.0, + 1.0, + 2.0, + 2.0, + 1.0, + 2.0, + 1.0, + 2.0, + 1.0, + 2.0, + 1.0, + 2.0 + ]; + + gcartesianPower( 'column-major', x.length, 3, x, 1, out, 8 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + out = [ 0.0 ]; + expected = [ 5.0 ]; + + gcartesianPower( 'column-major', 1, 1, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian power (accessors)', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', 2, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', 2, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = gcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 ); + + t.strictEqual( y, out, 'same reference' ); + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = gcartesianPower( 'column-major', x.length, 2, x, 1, out, 4 ); + + t.strictEqual( y, out, 'same reference' ); + + t.end(); +}); + +tape( 'if provided an `N` or `k` parameter equal to `0`, the function returns `out` unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + expected = [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + gcartesianPower( 'row-major', 0, 2, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcartesianPower( 'row-major', x.length, 0, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcartesianPower( 'column-major', 0, 2, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcartesianPower( 'column-major', x.length, 0, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x`', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', 2, 2, x, 2, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', 2, 2, x, 2, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (accessors)', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', 2, 2, toAccessorArray( x ), 2, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', 2, 2, toAccessorArray( x ), 2, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x`', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', 2, 2, x, -1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', 2, 2, x, -1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (accessors)', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 'row-major', 2, 2, toAccessorArray( x ), -1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 'column-major', 2, 2, toAccessorArray( x ), -1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 2.0, + 2.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 'row-major', x.length, 2, x, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 2.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 'column-major', x.length, 2, x, 1, out, 8 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a leading dimension stride for the output array (accessors)', function test( t ) { + var expected; + var out; + var x; + + // Row-major: + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 2.0, + 2.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 'row-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 2.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 'column-major', x.length, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 8 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var out; + var x0; + var x1; + + // Row-major: + x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + out = new Float64Array( 8 ); + expected = new Float64Array( [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] ); + + gcartesianPower( 'row-major', 2, 2, x1, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + // Column-major: + x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + out = new Float64Array( 8 ); + expected = new Float64Array( [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ] ); + + gcartesianPower( 'column-major', 2, 2, x1, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.ndarray.js new file mode 100644 index 000000000000..7ac6d806cfff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-power/test/test.ndarray.js @@ -0,0 +1,510 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gcartesianPower = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianPower, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( gcartesianPower.length, 9, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the Cartesian power', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( x.length, 2, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 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 + ]; + + gcartesianPower( x.length, 3, x, 1, 0, out, 3, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + out = [ 0.0 ]; + expected = [ 5.0 ]; + + gcartesianPower( 1, 1, x, 1, 0, out, 1, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian power (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + y = gcartesianPower( x.length, 2, x, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( y, out, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` or `k` parameter equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + expected = [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + gcartesianPower( 0, 2, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + gcartesianPower( 2, 0, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x`', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, x, 2, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x`', function test( t ) { + var expected; + var out; + var x; + + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, x, -1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 2.0, // 1 + 1.0 // 0 + ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), -1, 1, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for the first dimension of the output array', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 2.0, + 2.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 2, 2, x, 1, 0, out, 4, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for the first dimension of the output array (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + expected = [ + 1.0, + 1.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 2.0, + 2.0, + 0.0, + 0.0 + ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 4, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the first dimension of the output array', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 2.0, 2.0, 2.0, 1.0, 1.0, 2.0, 1.0, 1.0 ]; + + gcartesianPower( 2, 2, x, 1, 0, out, -2, 1, 6 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the first dimension of the output array (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 2.0, 2.0, 2.0, 1.0, 1.0, 2.0, 1.0, 1.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), -2, 1, 6 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the second dimension of the output array', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, x, 1, 0, out, 2, -1, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for the second dimension of the output array (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 1.0, 1.0, 2.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, -1, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter for `x`', function test( t ) { + var expected; + var out; + var x; + + x = [ 0.0, 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, x, 1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter for `x` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0.0, 1.0, 2.0, 3.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 1, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter for the output array', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 2.0, + 2.0, + 1.0, + 2.0, + 2.0 + ]; + + gcartesianPower( 2, 2, x, 1, 0, out, 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter for the output array (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ + 0.0, + 0.0, + 1.0, + 1.0, + 1.0, + 2.0, + 2.0, + 1.0, + 2.0, + 2.0 + ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a column-major output layout', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 2, 2, x, 1, 0, out, 1, 4, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a column-major output layout (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 2.0 ]; + out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + expected = [ 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianPower( 2, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 4, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});