diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/README.md new file mode 100644 index 000000000000..35bfaab968c4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/README.md @@ -0,0 +1,192 @@ + + +# gcartesianSquare + +> Compute the Cartesian square for a strided array. + +
+ +## Usage + +```javascript +var gcartesianSquare = require( '@stdlib/blas/ext/base/gcartesian-square' ); +``` + +#### gcartesianSquare( order, N, x, strideX, out, LDO ) + +Computes the Cartesian square 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 ]; + +gcartesianSquare( 'row-major', x.length, 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. +- **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` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian square 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 ]; + +gcartesianSquare( 'row-major', 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 ); + +gcartesianSquare( 'row-major', 2, x1, 1, out, 2 ); +// out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +``` + + + +#### gcartesianSquare.ndarray( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) + + + +Computes the Cartesian square 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 ]; + +gcartesianSquare.ndarray( x.length, 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. +- **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 ]; + +gcartesianSquare.ndarray( 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 + +- Pairs are stored as rows in the output matrix, where the first column contains the first element of each pair and the second column contains the second element. +- For an input array of length `N`, the output array must contain at least `N * N * 2` indexed elements. +- For row-major order, the `LDO` parameter must be greater than or equal to `2`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N*N)`. +- If `N <= 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 ([`dcartesianSquare`][@stdlib/blas/ext/base/dcartesian-square], [`scartesianSquare`][@stdlib/blas/ext/base/scartesian-square], 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 gcartesianSquare = require( '@stdlib/blas/ext/base/gcartesian-square' ); + +var N = 2; +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( N*N*2, 'generic' ); +gcartesianSquare( 'row-major', N, x, 1, out, 2 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/benchmark/benchmark.js new file mode 100644 index 000000000000..00e07c39c162 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcartesianSquare = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len * 2, options.dtype ); + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 0.1; + y = gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%y.length ] ) ) { + 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/gcartesian-square/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..4b0530a3e006 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcartesianSquare = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = zeros( len * len * 2, options.dtype ); + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] += 0.1; + y = gcartesianSquare( len, x, 1, 0, out, 2, 1, 0 ); + if ( isnan( y[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%y.length ] ) ) { + 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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/repl.txt new file mode 100644 index 000000000000..6bfcc9e61bba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/repl.txt @@ -0,0 +1,127 @@ + +{{alias}}( order, N, x, strideX, out, LDO ) + Computes the Cartesian square for a strided array. + + Pairs are stored as rows in the output matrix, where the first column + contains the first element of each pair and the second column contains + the second element. + + The `N` and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + If `N <= 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. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + out: Array|TypedArray + Output array. + + LDO: integer + Stride length between successive contiguous vectors of the matrix `out` + (a.k.a., leading dimension of `out`). + + Returns + ------- + out: Array|TypedArray + 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, 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, 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, x1, 1, out, 2 ) + [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + + +{{alias}}.ndarray( N, x, sx, ox, out, so1, so2, oo ) + Computes the Cartesian square for a strided array using alternative + indexing semantics. + + Pairs are stored as rows in the output matrix, where the first column + contains the first element of each pair and the second column contains + the second element. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + The function supports array-like objects having getter and setter accessors + for array element access. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + out: Array|TypedArray + 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: Array|TypedArray + 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, 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, 1.0, 2.0, 3.0 ]; + > out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 2, x, 1, 1, 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-square/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/types/index.d.ts new file mode 100644 index 000000000000..4f6c328463e6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Layout } from '@stdlib/types/blas'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Output array. +*/ +type OutputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `gcartesianSquare`. +*/ +interface Routine { + /** + * Computes the Cartesian square for a strided array. + * + * @param order - storage layout + * @param N - number of indexed elements + * @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 ]; + * + * gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); + * // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] + */ + ( order: Layout, N: number, x: InputArray, strideX: number, out: T, LDO: number ): T; + + /** + * Computes the Cartesian square for a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @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 ]; + * + * gcartesianSquare.ndarray( x.length, 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( N: number, x: InputArray, strideX: number, offsetX: number, out: T, strideOut1: number, strideOut2: number, offsetOut: number ): T; +} + +/** +* Computes the Cartesian square for a strided array. +* +* @param order - storage layout +* @param N - number of indexed elements +* @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 ]; +* +* gcartesianSquare( 'row-major', x.length, 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 ]; +* +* gcartesianSquare.ndarray( x.length, 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 gcartesianSquare: Routine; + + +// EXPORTS // + +export = gcartesianSquare; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/types/test.ts new file mode 100644 index 000000000000..f21085af3ed4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/docs/types/test.ts @@ -0,0 +1,279 @@ +/* +* @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 gcartesianSquare = require( './index' ); + + +// TESTS // + +// The function returns a numeric array... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare( 'row-major', 10, x, 1, out, 2 ); // $ExpectType Float64Array + gcartesianSquare( 'row-major', 10, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare( '10', 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( true, 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( false, 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( null, 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( undefined, 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( [], 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( {}, 10, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( ( x: number ): number => x, 10, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare( 'row-major', '10', x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', true, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', false, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', null, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', undefined, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', [], x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', {}, x, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', ( x: number ): number => x, x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a numeric array... +{ + const out = new Float64Array( 200 ); + + gcartesianSquare( 'row-major', 10, '10', 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, true, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, false, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, null, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, undefined, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, [ '1' ], 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, {}, 1, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, ( x: number ): number => x, 1, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare( 'row-major', 10, x, '10', out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, true, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, false, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, null, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, undefined, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, [], out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, {}, out, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, ( x: number ): number => x, out, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gcartesianSquare( 'row-major', 10, x, 1, '10', 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, true, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, false, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, null, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, undefined, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, [ '1' ], 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, {}, 2 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, ( x: number ): number => x, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare( 'row-major', 10, x, 1, out, '10' ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, true ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, false ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, null ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, undefined ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, [] ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, {} ); // $ExpectError + gcartesianSquare( 'row-major', 10, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare(); // $ExpectError + gcartesianSquare( 'row-major' ); // $ExpectError + gcartesianSquare( 'row-major', 10 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1 ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out ); // $ExpectError + gcartesianSquare( 'row-major', 10, x, 1, out, 2, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a numeric array... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, 0 ); // $ExpectType Float64Array + gcartesianSquare.ndarray( 10, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( '10', x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( true, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( false, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( null, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( undefined, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( [], x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( {}, x, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( ( x: number ): number => x, 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 numeric array... +{ + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, '10', 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, true, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, false, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, null, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, undefined, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, [ '1' ], 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, {}, 1, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, ( x: number ): number => 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 number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, '10', 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, true, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, false, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, null, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, undefined, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, [], 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, {}, 0, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, ( x: number ): number => x, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, 1, '10', out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, true, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, false, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, null, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, undefined, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, [], out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, {}, out, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, ( x: number ): number => x, out, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + gcartesianSquare.ndarray( 10, x, 1, 0, '10', 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, true, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, false, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, null, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, undefined, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, [ '1' ], 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, {}, 2, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, ( x: number ): number => x, 2, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, 1, 0, out, '10', 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, true, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, false, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, null, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, undefined, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, [], 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, {}, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, ( x: number ): number => x, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, '10', 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, true, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, false, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, null, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, undefined, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, [], 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, {}, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, ( x: number ): number => x, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, '10' ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, true ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, false ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, null ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, undefined ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, [] ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, {} ); // $ExpectError + gcartesianSquare.ndarray( 10, 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( 10 ); + const out = new Float64Array( 200 ); + + gcartesianSquare.ndarray(); // $ExpectError + gcartesianSquare.ndarray( 10 ); // $ExpectError + gcartesianSquare.ndarray( 10, x ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1 ); // $ExpectError + gcartesianSquare.ndarray( 10, x, 1, 0, out, 2, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/examples/index.js new file mode 100644 index 000000000000..06816698174a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 gcartesianSquare = require( './../lib' ); + +var N = 2; +var x = discreteUniform( N, 1, 10, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = zeros( N*N*2, 'generic' ); +gcartesianSquare( 'row-major', N, x, 1, out, 2 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/accessors.js new file mode 100644 index 000000000000..791296b01587 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/accessors.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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); + + +// MAIN // + +/** +* Computes the Cartesian square for a strided array using accessor arrays. +* +* @private +* @param {NonNegativeInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} out - output array object +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianSquare( x.length, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 2, 1, 0 ); +* +* console.log( out ); +* // => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +function gcartesianSquare( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var xbuf; + var obuf; + var xget; + var oset; + var ix; + var jx; + var io; + var v; + var i; + var j; + + xbuf = x.data; + obuf = out.data; + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + ix = offsetX; + io = offsetOut; + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + for ( i = 0; i < N; i++ ) { + v = xget( xbuf, ix ); + jx = offsetX; + for ( j = 0; j < N; j++ ) { + oset( obuf, io, v ); + oset( obuf, io + strideOut2, xget( xbuf, jx ) ); + jx += strideX; + io += strideOut1; + } + ix += strideX; + } + return obuf; + } + // Column-major... + for ( i = 0; i < N; i++ ) { + v = xget( xbuf, ix ); + for ( j = 0; j < N; j++ ) { + oset( obuf, io, v ); + io += strideOut1; + } + ix += strideX; + } + io = offsetOut + strideOut2; + for ( i = 0; i < N; i++ ) { + jx = offsetX; + for ( j = 0; j < N; j++ ) { + oset( obuf, io, xget( xbuf, jx ) ); + jx += strideX; + io += strideOut1; + } + } + return obuf; +} + + +// EXPORTS // + +module.exports = gcartesianSquare; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/base.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/base.js new file mode 100644 index 000000000000..7227dbc5b086 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/base.js @@ -0,0 +1,99 @@ +/** +* @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 gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; +var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the Cartesian square for a strided array using alternative indexing semantics. +* +* @private +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} 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 {NumericArray} 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 ]; +* +* gcartesianSquare( x.length, 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 gcartesianSquare( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + var xobj; + var oobj; + var ix; + var jx; + var io; + var i; + var j; + + xobj = arraylike2object( x ); + oobj = arraylike2object( out ); + if ( xobj.accessorProtocol || oobj.accessorProtocol ) { + return accessors( N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut ); // eslint-disable-line max-len + } + ix = offsetX; + io = offsetOut; + if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) { + for ( i = 0; i < N; i++ ) { + jx = offsetX; + for ( j = 0; j < N; j++ ) { + out[ io ] = x[ ix ]; + out[ io + strideOut2 ] = x[ jx ]; + jx += strideX; + io += strideOut1; + } + ix += strideX; + } + return out; + } + // Column-major... + for ( i = 0; i < N; i++ ) { + gfill( N, x[ ix ], out, strideOut1, io ); + ix += strideX; + io += N * strideOut1; + } + io = offsetOut + strideOut2; + for ( i = 0; i < N; i++ ) { + gcopy( N, x, strideX, offsetX, out, strideOut1, io ); + io += N * strideOut1; + } + return out; +} + + +// EXPORTS // + +module.exports = gcartesianSquare; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/index.js new file mode 100644 index 000000000000..eb930ae2351e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/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 square for a strided array. +* +* @module @stdlib/blas/ext/base/gcartesian-square +* +* @example +* var gcartesianSquare = require( '@stdlib/blas/ext/base/gcartesian-square' ); +* +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +* +* @example +* var gcartesianSquare = require( '@stdlib/blas/ext/base/gcartesian-square' ); +* +* var x = [ 1.0, 2.0 ]; +* var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; +* +* gcartesianSquare.ndarray( x.length, 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-square/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/main.js new file mode 100644 index 000000000000..6a1f28799d67 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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 max = require( '@stdlib/math/base/special/fast/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the Cartesian square for a strided array. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NumericArray} 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} sixth argument must be a valid stride length +* @returns {NumericArray} 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 ]; +* +* gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); +* // out => [ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] +*/ +function gcartesianSquare( order, N, 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, N*N ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', N*N, LDO ) ); + } + sa1 = 1; + sa2 = LDO; + } else { // order === 'row-major' + if ( LDO < 2 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', 2, LDO ) ); + } + sa1 = LDO; + sa2 = 1; + } + if ( N <= 0 ) { + return out; + } + return base( N, x, strideX, stride2offset( N, strideX ), out, sa1, sa2, 0 ); +} + + +// EXPORTS // + +module.exports = gcartesianSquare; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/ndarray.js new file mode 100644 index 000000000000..3c92704ea066 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/lib/ndarray.js @@ -0,0 +1,62 @@ +/** +* @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 base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the Cartesian square for a strided array using alternative indexing semantics. +* +* ## Notes +* +* - Pairs are stored as rows in the output matrix, where the first column contains the first element of each pair and the second column contains the second element. +* +* @param {NonNegativeInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} 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 {NumericArray} 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 ]; +* +* gcartesianSquare( x.length, 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 gcartesianSquare( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) { // eslint-disable-line max-len + if ( N <= 0 ) { + return out; + } + return base( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ); +} + + +// EXPORTS // + +module.exports = gcartesianSquare; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/package.json new file mode 100644 index 000000000000..e526ca64d245 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/gcartesian-square", + "version": "0.0.0", + "description": "Compute the Cartesian square 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", + "square", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.js new file mode 100644 index 000000000000..e5f08a8b7ab5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/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 gcartesianSquare = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianSquare, '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 gcartesianSquare.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.main.js new file mode 100644 index 000000000000..1a225620b7c7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.main.js @@ -0,0 +1,587 @@ +/** +* @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 gcartesianSquare = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianSquare, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gcartesianSquare.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var x; + var o; + 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() { + x = [ 1.0, 2.0 ]; + o = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + gcartesianSquare( value, 2, x, 1, o, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid first argument (accessors)', function test( t ) { + var values; + var x; + var o; + 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() { + x = toAccessorArray( [ 1.0, 2.0 ] ); + o = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + gcartesianSquare( value, 2, x, 1, o, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (row-major)', function test( t ) { + var values; + var x; + var o; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + x = [ 1.0, 2.0, 3.0 ]; + o = [ 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 ]; + gcartesianSquare( 'row-major', 3, x, 1, o, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (row-major, accessors)', function test( t ) { + var values; + var x; + var o; + var i; + + values = [ + -2, + -1, + 0, + 1 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + o = toAccessorArray( [ 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 ] ); + gcartesianSquare( 'row-major', 3, x, 1, o, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (column-major)', function test( t ) { + var values; + var x; + var o; + var i; + + values = [ + -2, + -1, + 0, + 1, + 2, + 3, + 8 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + x = [ 1.0, 2.0, 3.0 ]; + o = [ 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 ]; + gcartesianSquare( 'column-major', 3, x, 1, o, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument (column-major, accessors)', function test( t ) { + var values; + var x; + var o; + var i; + + values = [ + -2, + -1, + 0, + 1, + 2, + 3, + 8 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + o = toAccessorArray( [ 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 ] ); + gcartesianSquare( 'column-major', 3, x, 1, o, value ); + }; + } +}); + +tape( 'the function computes the Cartesian square (row-major)', 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 ]; + + gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (row-major, 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 ]; + + gcartesianSquare( 'row-major', 2, toAccessorArray( x ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (column-major)', 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 ]; + + gcartesianSquare( 'column-major', x.length, x, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (column-major, 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 ]; + + gcartesianSquare( 'column-major', 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 = gcartesianSquare( 'row-major', x.length, x, 1, out, 2 ); + + t.strictEqual( y, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0 ] ); + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + y = gcartesianSquare( 'row-major', 2, x, 1, out, 2 ); + + t.strictEqual( y, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` 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 ]; + expected = [ 3.0, 4.0, 5.0, 6.0 ]; + + gcartesianSquare( 'row-major', 0, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0 ]; + out = [ 3.0, 4.0, 5.0, 6.0 ]; + expected = [ 3.0, 4.0, 5.0, 6.0 ]; + + gcartesianSquare( 'column-major', 0, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + 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 ]; + + gcartesianSquare( 'row-major', 2, x, 2, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.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 ]; + + gcartesianSquare( 'row-major', 2, toAccessorArray( x ), 2, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (row-major)', 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 ]; + + gcartesianSquare( 'row-major', 2, x, -1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + 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 ]; + + gcartesianSquare( 'column-major', 2, x, 2, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.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 ]; + + gcartesianSquare( 'column-major', 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` (column-major)', 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, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianSquare( 'column-major', 2, x, -1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (row-major)', 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 + ]; + + gcartesianSquare( 'row-major', 2, x, 1, out, 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (row-major, 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 + ]; + + gcartesianSquare( 'row-major', 2, toAccessorArray( x ), 1, toAccessorArray( out ), 4 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (column-major)', 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, + 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 + ]; + + gcartesianSquare( 'column-major', 2, x, 1, out, 8 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `LDO` larger than the matrix dimension (column-major, 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, + 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 + ]; + + gcartesianSquare( 'column-major', 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 ] ); + + gcartesianSquare( 'row-major', 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 ] ); + + gcartesianSquare( 'column-major', 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-square/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.ndarray.js new file mode 100644 index 000000000000..24ff5611b554 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcartesian-square/test/test.ndarray.js @@ -0,0 +1,517 @@ +/** +* @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 gcartesianSquare = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcartesianSquare, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gcartesianSquare.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the Cartesian square (row-major)', 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 ]; + + gcartesianSquare( x.length, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1.0, 2.0, 3.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 ]; + expected = [ + 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 + ]; + + gcartesianSquare( x.length, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 5.0 ]; + out = [ 0.0, 0.0 ]; + expected = [ 5.0, 5.0 ]; + + gcartesianSquare( 1, x, 1, 0, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (row-major, 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 ]; + + gcartesianSquare( 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (column-major)', 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 ]; + + gcartesianSquare( x.length, x, 1, 0, out, 1, 4, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Cartesian square (column-major, 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 ]; + + gcartesianSquare( 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 4, 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 = gcartesianSquare( x.length, x, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( y, out, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0 ] ); + out = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + y = gcartesianSquare( 2, x, 1, 0, out, 2, 1, 0 ); + + t.strictEqual( y, out, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` 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 ]; + expected = [ 3.0, 4.0, 5.0, 6.0 ]; + + gcartesianSquare( 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` (row-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + 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 ]; + + gcartesianSquare( 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` (row-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.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 ]; + + gcartesianSquare( 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` (row-major)', 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 ]; + + gcartesianSquare( 2, x, -1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 1.0, // 0 + 0.0, + 2.0 // 1 + ]; + 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 ]; + + gcartesianSquare( 2, x, 2, 0, out, 1, 4, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for `x` (column-major, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1.0, 0.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 ]; + + gcartesianSquare( 2, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 1, 4, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride for `x` (column-major)', 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, 2.0, 2.0, 1.0, 2.0, 1.0, 2.0 ]; + + gcartesianSquare( 2, x, -1, 1, out, 1, 4, 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 (row-major)', 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 + ]; + + gcartesianSquare( 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 (row-major, 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 + ]; + + gcartesianSquare( 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 stride for the second dimension of the output array (column-major)', 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, + 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 + ]; + + gcartesianSquare( 2, x, 1, 0, out, 1, 8, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride for the second dimension of the output array (column-major, 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, + 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 + ]; + + gcartesianSquare( 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 8, 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 ]; + + gcartesianSquare( 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 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 ]; + + gcartesianSquare( 2, x, 1, 0, out, 2, -1, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', 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 ]; + + gcartesianSquare( 2, x, 1, 1, out, 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (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 ]; + + gcartesianSquare( 2, toAccessorArray( x ), 1, 1, toAccessorArray( out ), 2, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an output offset', 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 + ]; + + gcartesianSquare( 2, x, 1, 0, out, 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an output offset (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 + ]; + + gcartesianSquare( 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});