From b566bb2ef02c768772f599fa5107c08ad2274cb6 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Mon, 9 Jun 2025 16:35:34 +0530 Subject: [PATCH 1/4] feat: add blas/base/grot --- .../@stdlib/blas/base/grot/README.md | 192 ++++ .../blas/base/grot/benchmark/benchmark.js | 103 ++ .../base/grot/benchmark/benchmark.ndarray.js | 103 ++ .../@stdlib/blas/base/grot/docs/repl.txt | 136 +++ .../blas/base/grot/docs/types/index.d.ts | 114 +++ .../@stdlib/blas/base/grot/docs/types/test.ts | 309 ++++++ .../@stdlib/blas/base/grot/examples/index.js | 35 + .../@stdlib/blas/base/grot/lib/accessors.js | 88 ++ .../@stdlib/blas/base/grot/lib/index.js | 61 ++ .../@stdlib/blas/base/grot/lib/main.js | 56 ++ .../@stdlib/blas/base/grot/lib/ndarray.js | 84 ++ .../@stdlib/blas/base/grot/package.json | 69 ++ .../@stdlib/blas/base/grot/test/test.js | 38 + .../@stdlib/blas/base/grot/test/test.main.js | 743 ++++++++++++++ .../blas/base/grot/test/test.ndarray.js | 909 ++++++++++++++++++ 15 files changed, 3040 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/grot/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/grot/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/grot/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/base/grot/README.md b/lib/node_modules/@stdlib/blas/base/grot/README.md new file mode 100644 index 000000000000..d27d037445bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/README.md @@ -0,0 +1,192 @@ + + +# grot + +> Apply a plane rotation. + +
+ +This BLAS level 1 routine applies a real plane rotation to real double-precision floating-point vectors. The plane rotation is applied to `N` points, where the points to be rotated are contained in vectors `x` and `y` and where the cosine and sine of the angle of rotation are `c` and `s`, respectively. The operation is as follows: + + + + + +where `x_i` and `y_i` are the individual elements on which the rotation is applied. + +
+ + + +
+ +## Usage + +```javascript +var grot = require( '@stdlib/blas/base/grot' ); +``` + +#### grot( N, x, strideX, y, strideY, c, s ) + +Applies a plane rotation. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + +grot( x.length, x, 1, y, 1, 0.8, 0.6 ); +// x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +// y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input array. +- **strideX**: index increment for `x`. +- **y**: second input array. +- **strideY**: index increment for `y`. +- **c**: cosine of the angle of rotation. +- **s**: sine of the angle of rotation. + +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply a plane rotation to every other element, + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + +grot( 3, x, 2, y, 2, 0.8, 0.6 ); +// x => [ 5.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] +// y => [ ~5.0, 8.0, 5.4, 10.0, ~5.8, 12.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 arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +grot( 3, x1, -2, y1, 1, 0.8, 0.6 ); +// x0 => [ 1.0, ~8.8, 3.0, 9.8, 5.0, 10.8 ] +// y0 => [ 7.0, 8.0, 9.0, 4.4, 6.4, ~8.4 ] +``` + +#### grot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) + +Applies a plane rotation using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + +grot.ndarray( 4, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +// x => [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] +// y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +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 apply a plane rotation to every other element starting from the second element, + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + +grot.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); +// x => [ 1.0, 6.4, 3.0, 9.2, 5.0, 12.0 ] +// y => [ 7.0, 5.2, 9.0, 5.6, 11.0, ~6.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions leave `x` and `y` unchanged. +- `grot()` corresponds to the [BLAS][blas] level 1 function [`grot`][grot]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var grot = require( '@stdlib/blas/base/grot' ); + +var opts = { + 'dtype': 'generic' +}; +var x = discreteUniform( 10, 0, 500, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 255, opts ); +console.log( y ); + +// Apply a plane rotation: +grot( x.length, x, 1, y, 1, 0.8, 0.6 ); +console.log( x ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js new file mode 100644 index 000000000000..cd09bf5651c7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 pkg = require( './../package.json' ).name; +var grot = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = grot( x.length, x, 1, y, 1, 0.707, 0.707 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%x.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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..37f1cc2b787f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 pkg = require( './../package.json' ).name; +var grot = require( './../lib' ).ndarray; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = grot( x.length, x, 1, 0, y, 1, 0, 0.707, 0.707 ); + if ( isnan( z[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%x.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 = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/grot/docs/repl.txt new file mode 100644 index 000000000000..a50c8ecf5a98 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/repl.txt @@ -0,0 +1,136 @@ + +{{alias}}( N, x, strideX, y, strideY, c, s ) + Applies a plane rotation. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N` is less than or equal to `0`, the vectors are unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Index increment for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Index increment for `y`. + + c: number + Cosine of the angle of rotation. + + s: number + Sine of the angle of rotation. + + Returns + ------- + y: Array|TypedArray + Input array `y`. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + > {{alias}}( x.length, x, 1, y, 1, 0.8, 0.6 ); + > x + [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] + > y + [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] + + // Advanced Indexing: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + > {{alias}}( 2, x, -1, y, 2, 0.707, 0.707 ); + > x + [ ~6.36, ~5.66, 3.0, 4.0, 5.0 ] + > y + [ ~2.83, 7.0, ~4.95, 9.0, 10.0 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + > {{alias}}( 3, x1, 1, y1, 1, 0.8, 0.6 ); + > x0 + [ 1.0, 7.6, 9.0, ~10.4, 5.0, 6.0 ] + > y0 + [ 7.0, 8.0, 9.0, 6.8, ~7.0, ~7.2 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) + Applies a plane rotation using alternative indexing semantics. + + 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. + + x: Array|TypedArray + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + c: number + Cosine of the angle of rotation. + + s: number + Sine of the angle of rotation. + + Returns + ------- + y: Array|TypedArray + Input array `y`. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + > var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + > {{alias}}.ndarray( 4, x, 1, 1, y, 1, 1, 0.8, 0.6 ); + > x + [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] + > y + [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] + + // Advanced Indexing: + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > {{alias}}.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); + > x + [ 1.0, 6.4, 3.0, 9.2, 5.0, 12.0 ] + > y + [ 7.0, 5.2, 9.0, 5.6, 11.0, ~6.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts new file mode 100644 index 000000000000..0a615648aa0b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts @@ -0,0 +1,114 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `grot`. +*/ +interface Routine { + /** + * Applies a plane rotation. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param y - second input array + * @param strideY - `y` stride length + * @param c - cosine of the angle of rotation + * @param s - sine of the angle of rotation + * @returns `y` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + * var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + * + * grot( x.length, x, 1, y, 1, 0.8, 0.6 ); + * // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] + * // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] + */ + ( N: number, x: InputArray, strideX: number, y: T, strideY: number, c: number, s: number ): T; + + /** + * Applies a plane rotation using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @param c - cosine of the angle of rotation + * @param s - sine of the angle of rotation + * @returns `y` + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + * + * grot.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); + * // x => [ 1.0, 6.4, 3.0, 9.2, 5.0, 12.0 ] + * // y => [ 7.0, 5.2, 9.0, 5.6, 11.0, ~6.0 ] + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number, c: number, s: number ): T; +} + +/** +* Applies a plane rotation. +* +* @param N - number of indexed elements +* @param x - first input array +* @param strideX - `x` stride length +* @param y - second input array +* @param strideY - `y` stride length +* @param c - cosine of the angle of rotation +* @param s - sine of the angle of rotation +* @returns `y` +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( x.length, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, ~4.6, ~4.8, 5.0 ] +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +* +* grot.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); +* // x => [ 1.0, 6.4, 3.0, 9.2, 5.0, 12.0 ] +* // y => [ 7.0, 5.2, 9.0, 5.6, 11.0, ~6.0 ] +*/ +declare var grot: Routine; + + +// EXPORTS // + +export = grot; diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts new file mode 100644 index 000000000000..96896e6d1525 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts @@ -0,0 +1,309 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import grot = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( x.length, x, 1, y, 1, 1.0, 0.0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( '10', x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( true, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( false, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( null, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( undefined, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( [], x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( {}, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( ( x: number ): number => x, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( x.length, 10, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, '10', 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, true, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, false, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, null, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, undefined, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, [], 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, {}, 1, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, ( x: number ): number => x, 1, y, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( x.length, x, '10', y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, true, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, false, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, null, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, undefined, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, [], y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, {}, y, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, ( x: number ): number => x, y, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + grot( x.length, x, 1, 10, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, '10', 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, true, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, false, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, null, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, undefined, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, [], 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, {}, 1, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, ( x: number ): number => x, 1, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( x.length, x, 1, y, '10', 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, true, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, false, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, null, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, undefined, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, [], 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, {}, 1.0, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, ( x: number ): number => x, 1.0, 0.0 ); // $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 y = new Float64Array( 10 ); + + grot( x.length, x, 1, y, 1, '10', 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, true, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, false, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, null, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, undefined, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, [], 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, {}, 0.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, ( x: number ): number => x, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot( x.length, x, 1, y, 1, 1.0, '10' ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, true ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, false ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, null ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, undefined ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, [] ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, {} ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, ( 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 y = new Float64Array( 10 ); + + grot(); // $ExpectError + grot( x.length ); // $ExpectError + grot( x.length, x ); // $ExpectError + grot( x.length, x, 1 ); // $ExpectError + grot( x.length, x, 1, y ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0 ); // $ExpectError + grot( x.length, x, 1, y, 1, 1.0, 0.0, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectType Float64Array +} + +// 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 y = new Float64Array( 10 ); + + grot.ndarray( '10', x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( true, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( false, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( null, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( undefined, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( [], x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( {}, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot.ndarray( x.length, 10, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, '10', 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, true, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, false, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, null, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, undefined, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, [], 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, {}, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0, 1.0, 0.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 y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, '10', 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, true, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, false, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, null, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, undefined, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, [], 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, {}, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, 1.0, 0.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 y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, '10', y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, true, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, false, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, null, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, undefined, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, [], y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, {}, y, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, 10, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, '10', 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, true, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, false, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, null, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, undefined, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, [], 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, {}, 1, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0, 1.0, 0.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 y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, y, '10', 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, true, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, false, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, null, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, undefined, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, [], 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, {}, 0, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, 1.0, 0.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 y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, y, 1, '10', 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, true, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, false, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, null, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, undefined, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, [], 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, {}, 1.0, 0.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, 1.0, 0.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, y, 1, 0, '10', 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, true, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, false, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, null, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, undefined, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, [], 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, {}, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, ( x: number ): number => x, 1.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( 10 ); + const y = new Float64Array( 10 ); + + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, '1.0' ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, true ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, false ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, null ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, undefined ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, [] ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, {} ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, ( 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 y = new Float64Array( 10 ); + + grot.ndarray(); // $ExpectError + grot.ndarray( x.length ); // $ExpectError + grot.ndarray( x.length, x ); // $ExpectError + grot.ndarray( x.length, x, 1 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1.0 ); // $ExpectError + grot.ndarray( x.length, x, 1, 0, y, 1.0, 0.0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/grot/examples/index.js b/lib/node_modules/@stdlib/blas/base/grot/examples/index.js new file mode 100644 index 000000000000..22cf0f3f317a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 grot = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; +var x = discreteUniform( 10, 0, 500, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 255, opts ); +console.log( y ); + +grot( x.length, x, 1, y, 1, 0.8, 0.6 ); +console.log( x ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js new file mode 100644 index 000000000000..0a0f970d0cc9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +// MAIN // + +/** +* Applies a plane rotation. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Object} y - output array object +* @param {Collection} y.data - output array data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {number} c - cosine of the angle of rotation +* @param {number} s - sine of the angle of rotation +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( 4, arraylike2object( toAccessorArray( x ) ), 1, 1, arraylike2object( toAccessorArray( y ) ), 1, 1, 0.8, 0.6 ); +* // x => [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] +*/ +function grot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { + var xbuf; + var ybuf; + var set; + var get; + var tmp; + var ix; + var iy; + var i; + + // Cache references to array data: + xbuf = x.data; + ybuf = y.data; + + // Cache references to element accessors: + get = x.accessors[ 0 ]; + set = y.accessors[ 1 ]; + + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + var xval = get( xbuf, ix ); + var yval = get( ybuf, iy ); + + set( xbuf, ix, c * xval + s * yval ); + set( ybuf, iy, c * yval - s * xval ); + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = grot; diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/index.js b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js new file mode 100644 index 000000000000..4e59e301d866 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* BLAS level 1 routine to apply a plane rotation. +* +* @module @stdlib/blas/base/grot +* +* @example +* var grot = require( '@stdlib/blas/base/grot' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( 4, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* +* @example +* var grot = require( '@stdlib/blas/base/grot' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( 4, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +* // x => [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.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/base/grot/lib/main.js b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js new file mode 100644 index 000000000000..c94e40f26363 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Applies a plane rotation. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NumericArray} y - second input array +* @param {integer} strideY - `y` stride length +* @param {number} c - cosine of the angle of rotation +* @param {number} s - sine of the angle of rotation +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( 4, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +*/ +function grot( N, x, strideX, y, strideY, c, s ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), c, s ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = grot; diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js new file mode 100644 index 000000000000..c9cd583d299e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Applies a plane rotation. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NumericArray} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {number} c - cosine of the angle of rotation +* @param {number} s - sine of the angle of rotation +* @returns {NumericArray} `y` +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; +* +* grot( 4, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +* // x => [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] +*/ +function grot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { + var tmp; + var ix; + var iy; + var ox; + var oy; + var i; + + if ( N <= 0 ) { + return y; + } + ox = arraylike2object( x ); + oy = arraylike2object( y ); + if ( ox.accessorProtocol || oy.accessorProtocol ) { + accessors( N, ox, strideX, offsetX, oy, strideY, offsetY, c, s ); + return oy.data; + } + ix = offsetX; + iy = offsetY; + + for ( i = 0; i < N; i++ ) { + tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); + y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); + x[ ix ] = tmp; + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = grot; diff --git a/lib/node_modules/@stdlib/blas/base/grot/package.json b/lib/node_modules/@stdlib/blas/base/grot/package.json new file mode 100644 index 000000000000..90dead18fd60 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/base/grot", + "version": "0.0.0", + "description": "Applies a plane rotation.", + "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", + "level 1", + "rot", + "drot", + "srot", + "linear", + "algebra", + "subroutines", + "rotation", + "vector", + "array", + "ndarray" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.js new file mode 100644 index 000000000000..2da4d97b3733 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 grot = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grot, '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 grot.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js new file mode 100644 index 000000000000..13430ac139be --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js @@ -0,0 +1,743 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 gcopy = require( '@stdlib/blas/base/gcopy' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var grot = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( grot.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, 1, y, 1, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 6.0 ); + isApprox( t, y, ye[ i ], 6.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), 1, toAccessorArray( y ), 1, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 6.0 ); + isApprox( t, y, ye[ i ], 6.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, 2, y, -2, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), 2, toAccessorArray( y ), -2, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, -2, y, 1, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), -2, toAccessorArray( y ), 1, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, -1, y, -2, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 4.0 ); + isApprox( t, y, ye[ i ], 4.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), -1, toAccessorArray( y ), -2, 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 4.0 ); + isApprox( t, y, ye[ i ], 4.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, x, 2, y, 1, 0.8, 0.6 ); + + xe = [ 4.4, 2.0, 6.6, 4.0, 5.0 ]; + ye = [ 4.2, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, toAccessorArray( x ), 2, toAccessorArray( y ), 1, 0.8, 0.6 ); + + xe = [ 4.4, 2.0, 6.6, 4.0, 5.0 ]; + ye = [ 4.2, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + + grot( 3, x, 1, y, 2, 0.0, -1.0 ); + + xe = [ -1.0, -3.0, -5.0, 4.0, 5.0 ]; + ye = [ 1.0, 2.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + + grot( 3, toAccessorArray( x ), 1, toAccessorArray( y ), 2, 0.0, -1.0 ); + + xe = [ -1.0, -3.0, -5.0, 4.0, 5.0 ]; + ye = [ 1.0, 2.0, 2.0, 4.0, 3.0 ]; + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = grot( x.length, x, 1, y, 1, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the second input array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = toAccessorArray( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = grot( x.length, x, 1, y, 1, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function leaves both input arrays unchanged', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( x.length, x, 1, xe, 1 ); + + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( y.length, y, 1, ye, 1 ); + + grot( -1, x, 1, y, 1, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + grot( 0, x, 1, y, 1, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function leaves both input arrays unchanged (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( x.length, x, 1, xe, 1 ); + + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( y.length, y, 1, ye, 1 ); + + grot( -1, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + grot( 0, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]; + y = [ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]; + + grot( 4, x, -2, y, 1, 0.8, 0.6 ); + + xe = [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ]; + ye = [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]; + y = [ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]; + + grot( 4, toAccessorArray( x ), -2, toAccessorArray( y ), 1, 0.8, 0.6 ); + + xe = [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ]; + ye = [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]; + y = [ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]; + + grot( 2, x, -1, y, -2, 0.8, 0.6 ); + + xe = [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ye = [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]; + y = [ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]; + + grot( 2, toAccessorArray( x ), -1, toAccessorArray( y ), -2, 0.8, 0.6 ); + + xe = [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ye = [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js new file mode 100644 index 000000000000..4e58b7fcf2f4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js @@ -0,0 +1,909 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var grot = require( './../lib/ndarray.js' ); +const toAccessorArray = require('@stdlib/array/base/to-accessor-array'); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof grot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( grot.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, 1, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 6.0 ); + isApprox( t, y, ye[ i ], 6.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), 1, ox[ i ], toAccessorArray( y ), 1, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 6.0 ); + isApprox( t, y, ye[ i ], 6.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, 2, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), 2, ox[ i ], toAccessorArray( y ), -2, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 2, 6 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] + ]; + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, -2, ox[ i ], y, 1, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 2, 6 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ], + [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] + ]; + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), -2, ox[ i ], toAccessorArray( y ), 1, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 20.0 ); + isApprox( t, y, ye[ i ], 20.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 1, 3 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], x, -1, ox[ i ], y, -2, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 4.0 ); + isApprox( t, y, ye[ i ], 4.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', function test( t ) { + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var ox; + var oy; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + ox = [ 0, 0, 1, 3 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] + ]; + ye = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] + ]; + + for ( i = 0; i < N.length; i++ ) { + x = xbuf.slice(); + y = ybuf.slice(); + out = grot( N[ i ], toAccessorArray( x ), -1, ox[ i ], toAccessorArray( y ), -2, oy[ i ], 0.8, 0.6 ); + isApprox( t, x, xe[ i ], 4.0 ); + isApprox( t, y, ye[ i ], 4.0 ); + t.strictEqual( out._buffer, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, x, 2, 0, y, 1, 0, 0.8, 0.6 ); + + xe = [ 4.4, 2.0, 6.6, 4.0, 5.0 ]; + ye = [ 4.2, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0, 0.8, 0.6 ); + + xe = [ 4.4, 2.0, 6.6, 4.0, 5.0 ]; + ye = [ 4.2, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, x, 1, 1, y, 1, 0, 0.8, 0.6 ); + + xe = [ 1.0, 5.2, 6.6, 4.0, 5.0 ]; + ye = [ 3.6, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]; + + grot( 2, toAccessorArray( x ), 1, 1, toAccessorArray( y ), 1, 0, 0.8, 0.6 ); + + xe = [ 1.0, 5.2, 6.6, 4.0, 5.0 ]; + ye = [ 3.6, 3.8, 8.0, 9.0, 10.0 ]; + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + + grot( 3, x, 1, 0, y, 2, 0, 0.0, -1.0 ); + + xe = [ -1.0, -3.0, -5.0, 4.0, 5.0 ]; + ye = [ 1.0, 2.0, 2.0, 4.0, 3.0 ]; + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + + grot( 3, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0, 0.0, -1.0 ); + + xe = [ -1.0, -3.0, -5.0, 4.0, 5.0 ]; + ye = [ 1.0, 2.0, 2.0, 4.0, 3.0 ]; + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, + 4.0, + 5.0 + ]; + y = [ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 + ]; + + grot( 2, x, 1, 0, y, 1, 2, 0.8, 0.6 ); + + xe = [ 5.6, 7.0, 3.0, 4.0, 5.0 ]; + ye = [ 6.0, 7.0, 5.8, 6.0, 10.0 ]; + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` offset (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, + 4.0, + 5.0 + ]; + y = [ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 + ]; + + grot( 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 2, 0.8, 0.6 ); + + xe = [ 5.6, 7.0, 3.0, 4.0, 5.0 ]; + ye = [ 6.0, 7.0, 5.8, 6.0, 10.0 ]; + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input array', function test( t ) { + var out; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = grot( x.length, x, 1, 0, y, 1, 0, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the second input array', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = toAccessorArray( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = grot( x.length, x, 1, 0, y, 1, 0, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function leaves both input arrays unchanged', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( x.length, x, 1, 0, xe, 1, 0 ); + + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( y.length, y, 1, 0, ye, 1, 0 ); + + grot( -1, x, 1, 0, y, 1, 0, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + grot( 0, x, 1, 0, y, 1, 0, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function leaves both input arrays unchanged (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( x.length, x, 1, 0, xe, 1, 0 ); + + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + gcopy( y.length, y, 1, 0, ye, 1, 0 ); + + grot( -1, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + grot( 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]; + y = [ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]; + + grot( 4, x, -2, 6, y, 1, 0, 0.8, 0.6 ); + + xe = [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ]; + ye = [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]; + y = [ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]; + + grot( 4, toAccessorArray( x ), -2, 6, toAccessorArray( y ), 1, 0, 0.8, 0.6 ); + + xe = [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ]; + ye = [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]; + y = [ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]; + + grot( 2, x, -1, 1, y, -2, 2, 0.8, 0.6 ); + + xe = [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ye = [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var xe; + var ye; + var x; + var y; + + x = [ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]; + y = [ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]; + + grot( 2, toAccessorArray( x ), -1, 1, toAccessorArray( y ), -2, 2, 0.8, 0.6 ); + + xe = [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ye = [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ]; + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); \ No newline at end of file From fccb0d53013ba802edd7dfef88a05b39c81941a5 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Mon, 9 Jun 2025 16:37:25 +0530 Subject: [PATCH 2/4] chore: update implementation --- lib/node_modules/@stdlib/blas/base/grot/README.md | 11 ++++++++++- .../@stdlib/blas/base/grot/docs/types/index.d.ts | 4 ++-- .../@stdlib/blas/base/grot/lib/accessors.js | 11 ++++++----- lib/node_modules/@stdlib/blas/base/grot/lib/index.js | 6 +++--- lib/node_modules/@stdlib/blas/base/grot/lib/main.js | 6 +++--- .../@stdlib/blas/base/grot/lib/ndarray.js | 4 ++-- .../@stdlib/blas/base/grot/test/test.main.js | 8 ++++---- .../@stdlib/blas/base/grot/test/test.ndarray.js | 2 +- 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/grot/README.md b/lib/node_modules/@stdlib/blas/base/grot/README.md index d27d037445bd..5421274b4e2c 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/README.md +++ b/lib/node_modules/@stdlib/blas/base/grot/README.md @@ -136,7 +136,8 @@ grot.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); ## Notes - If `N <= 0`, both functions leave `x` and `y` unchanged. -- `grot()` corresponds to the [BLAS][blas] level 1 function [`grot`][grot]. +- `grot()` corresponds to the [BLAS][blas] level 1 function [`drot`][drot] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`drot`][@stdlib/blas/base/drot], [`srot`][@stdlib/blas/base/srot], etc.) are likely to be significantly more performant. +- 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]). @@ -185,8 +186,16 @@ console.log( y ); [blas]: http://www.netlib.org/blas +[drot]: https://www.netlib.org/lapack/explore-html-3.6.1/de/da4/group__double__blas__level1_ga54d516b6e0497df179c9831f2554b1f9.html + [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/blas/base/drot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/drot + +[@stdlib/blas/base/srot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/srot + +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts index 0a615648aa0b..69d990ab121d 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts @@ -47,7 +47,7 @@ interface Routine { * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; * var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; * - * grot( x.length, x, 1, y, 1, 0.8, 0.6 ); + * grot( 5, x, 1, y, 1, 0.8, 0.6 ); * // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] * // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] */ @@ -94,7 +94,7 @@ interface Routine { * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; * var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; * -* grot( x.length, x, 1, y, 1, 0.8, 0.6 ); +* grot( 5, x, 1, y, 1, 0.8, 0.6 ); * // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] * // y => [ ~4.2, 4.4, ~4.6, ~4.8, 5.0 ] * diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js index 0a0f970d0cc9..5014a3a3cd10 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/accessors.js @@ -53,9 +53,10 @@ function grot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var xbuf; var ybuf; + var xval; + var yval; var set; var get; - var tmp; var ix; var iy; var i; @@ -71,11 +72,11 @@ function grot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { ix = offsetX; iy = offsetY; for ( i = 0; i < N; i++ ) { - var xval = get( xbuf, ix ); - var yval = get( ybuf, iy ); + xval = get( xbuf, ix ); + yval = get( ybuf, iy ); - set( xbuf, ix, c * xval + s * yval ); - set( ybuf, iy, c * yval - s * xval ); + set( xbuf, ix, ( c * xval ) + ( s * yval ) ); + set( ybuf, iy, ( c * yval ) - ( s * xval ) ); ix += strideX; iy += strideY; } diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/index.js b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js index 4e59e301d866..563902caf111 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js @@ -29,9 +29,9 @@ * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; * var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; * -* grot( 4, x, 1, y, 1, 0.8, 0.6 ); -* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] -* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* grot( 5, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] * * @example * var grot = require( '@stdlib/blas/base/grot' ); diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/main.js b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js index c94e40f26363..3aa72f559bd0 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js @@ -42,9 +42,9 @@ var ndarray = require( './ndarray.js' ); * var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; * var y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; * -* grot( 4, x, 1, y, 1, 0.8, 0.6 ); -* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] -* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +* grot( 5, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] */ function grot( N, x, strideX, y, strideY, c, s ) { return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), c, s ); // eslint-disable-line max-len diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js index c9cd583d299e..1a9bf68616f2 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js @@ -52,14 +52,14 @@ function grot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var tmp; var ix; var iy; - var ox; + var ox; var oy; var i; if ( N <= 0 ) { return y; } - ox = arraylike2object( x ); + ox = arraylike2object( x ); oy = arraylike2object( y ); if ( ox.accessorProtocol || oy.accessorProtocol ) { accessors( N, ox, strideX, offsetX, oy, strideY, offsetY, c, s ); diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js index 13430ac139be..0b84e1754229 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js @@ -555,10 +555,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( x.length, x, 1, xe, 1 ); - ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( y.length, y, 1, ye, 1 ); grot( -1, x, 1, y, 1, 0.8, 0.6 ); @@ -581,10 +581,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( x.length, x, 1, xe, 1 ); - ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( y.length, y, 1, ye, 1 ); grot( -1, toAccessorArray( x ), 1, toAccessorArray( y ), 1, 0.8, 0.6 ); diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js index 4e58b7fcf2f4..ce6549c8386b 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js @@ -906,4 +906,4 @@ tape( 'the function supports complex access patterns (accessors)', function test isApprox( t, y, ye, 5.0 ); t.end(); -}); \ No newline at end of file +}); From 4720453a2eeef4e9b6baf4f07290b9999136c387 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 9 Jun 2025 11:22:28 +0000 Subject: [PATCH 3/4] chore: update copyright years --- lib/node_modules/@stdlib/blas/base/grot/README.md | 2 +- lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js | 2 +- .../@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/blas/base/grot/examples/index.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/lib/index.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/lib/main.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/test/test.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/test/test.main.js | 2 +- lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/grot/README.md b/lib/node_modules/@stdlib/blas/base/grot/README.md index 5421274b4e2c..eb2ad4233c8b 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/README.md +++ b/lib/node_modules/@stdlib/blas/base/grot/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js index cd09bf5651c7..afad48803173 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js index 37f1cc2b787f..4d68d731f78b 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts index 69d990ab121d..21433e9f62cb 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts index 96896e6d1525..ddd1fc22e3f7 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/grot/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/examples/index.js b/lib/node_modules/@stdlib/blas/base/grot/examples/index.js index 22cf0f3f317a..cdd1c1e111f2 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/grot/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/index.js b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js index 563902caf111..b15d9cf45841 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/main.js b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js index 3aa72f559bd0..ea73de530387 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js index 1a9bf68616f2..6f7ec928b661 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.js index 2da4d97b3733..f70812d2ad86 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js index 0b84e1754229..531a48a1aa44 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js index ce6549c8386b..cfd681891093 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. From 4e97f18d4ccd08d9265ac4b4649bbd43fe5c98f8 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Mon, 9 Jun 2025 17:28:16 +0530 Subject: [PATCH 4/4] chore: update test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/grot/test/test.main.js | 24 ++++++++----- .../blas/base/grot/test/test.ndarray.js | 34 ++++++++++++------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js index 531a48a1aa44..9bca38191389 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.main.js @@ -114,6 +114,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function var xbuf; var ybuf; var out; + var yob; var xe; var ye; var N; @@ -142,10 +143,11 @@ tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), 1, toAccessorArray( y ), 1, 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), 1, yob, 1, 0.8, 0.6 ); isApprox( t, x, xe[ i ], 6.0 ); isApprox( t, y, ye[ i ], 6.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -194,6 +196,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', functio var xbuf; var ybuf; var out; + var yob; var xe; var ye; var N; @@ -222,10 +225,11 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', functio for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), 2, toAccessorArray( y ), -2, 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), 2, yob, -2, 0.8, 0.6 ); isApprox( t, x, xe[ i ], 20.0 ); isApprox( t, y, ye[ i ], 20.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -274,6 +278,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', functio var xbuf; var ybuf; var out; + var yob; var xe; var ye; var N; @@ -302,10 +307,11 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', functio for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), -2, toAccessorArray( y ), 1, 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), -2, yob, 1, 0.8, 0.6 ); isApprox( t, x, xe[ i ], 20.0 ); isApprox( t, y, ye[ i ], 20.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -354,6 +360,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', functi var xbuf; var ybuf; var out; + var yob; var xe; var ye; var N; @@ -382,10 +389,11 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', functi for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), -1, toAccessorArray( y ), -2, 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), -1, yob, -2, 0.8, 0.6 ); isApprox( t, x, xe[ i ], 4.0 ); isApprox( t, y, ye[ i ], 4.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js index cfd681891093..fa4ecd712d8b 100644 --- a/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/grot/test/test.ndarray.js @@ -21,11 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var gcopy = require( '@stdlib/blas/base/gcopy' ).ndarray; var EPS = require( '@stdlib/constants/float64/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); var grot = require( './../lib/ndarray.js' ); -const toAccessorArray = require('@stdlib/array/base/to-accessor-array'); // FUNCTIONS // @@ -119,6 +119,7 @@ tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function var xbuf; var ybuf; var out; + var yob; var xe; var ye; var ox; @@ -152,10 +153,11 @@ tape( 'the function applies a plane rotation (sx=1, sy=1) (accessors)', function for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), 1, ox[ i ], toAccessorArray( y ), 1, oy[ i ], 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), 1, ox[ i ], yob, 1, oy[ i ], 0.8, 0.6 ); isApprox( t, x, xe[ i ], 6.0 ); isApprox( t, y, ye[ i ], 6.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -209,6 +211,7 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', functio var xbuf; var ybuf; var out; + var yob; var xe; var ye; var ox; @@ -242,10 +245,11 @@ tape( 'the function applies a plane rotation (sx=2, sy=-2) (accessors)', functio for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), 2, ox[ i ], toAccessorArray( y ), -2, oy[ i ], 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), 2, ox[ i ], yob, -2, oy[ i ], 0.8, 0.6 ); isApprox( t, x, xe[ i ], 20.0 ); isApprox( t, y, ye[ i ], 20.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -298,6 +302,7 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', functio var xbuf; var ybuf; var out; + var yob; var xe; var ye; var ox; @@ -330,10 +335,11 @@ tape( 'the function applies a plane rotation (sx=-2, sy=1) (accessors)', functio for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), -2, ox[ i ], toAccessorArray( y ), 1, oy[ i ], 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), -2, ox[ i ], yob, 1, oy[ i ], 0.8, 0.6 ); isApprox( t, x, xe[ i ], 20.0 ); isApprox( t, y, ye[ i ], 20.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -387,6 +393,7 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', functi var xbuf; var ybuf; var out; + var yob; var xe; var ye; var ox; @@ -420,10 +427,11 @@ tape( 'the function applies a plane rotation (sx=-1, sy=-2) (accessors)', functi for ( i = 0; i < N.length; i++ ) { x = xbuf.slice(); y = ybuf.slice(); - out = grot( N[ i ], toAccessorArray( x ), -1, ox[ i ], toAccessorArray( y ), -2, oy[ i ], 0.8, 0.6 ); + yob = toAccessorArray( y ); + out = grot( N[ i ], toAccessorArray( x ), -1, ox[ i ], yob, -2, oy[ i ], 0.8, 0.6 ); isApprox( t, x, xe[ i ], 4.0 ); isApprox( t, y, ye[ i ], 4.0 ); - t.strictEqual( out._buffer, y, 'returns expected value' ); + t.strictEqual( out, yob, 'returns expected value' ); } t.end(); }); @@ -721,10 +729,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( x.length, x, 1, 0, xe, 1, 0 ); - ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( y.length, y, 1, 0, ye, 1, 0 ); grot( -1, x, 1, 0, y, 1, 0, 0.8, 0.6 ); @@ -747,10 +755,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + xe = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( x.length, x, 1, 0, xe, 1, 0 ); - ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + ye = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; gcopy( y.length, y, 1, 0, ye, 1, 0 ); grot( -1, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0, 0.8, 0.6 );