From ccd0c39cad045005aef199ed577772afc93de7e8 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 11 Mar 2024 01:58:40 +0530 Subject: [PATCH 01/27] chore: in-process --- .../@stdlib/blas/base/drot/README.md | 192 +++++++++++ .../blas/base/drot/benchmark/benchmark.js | 103 ++++++ .../base/drot/benchmark/benchmark.ndarray.js | 103 ++++++ .../@stdlib/blas/base/drot/docs/repl.txt | 113 +++++++ .../blas/base/drot/docs/types/index.d.ts | 113 +++++++ .../@stdlib/blas/base/drot/docs/types/test.ts | 309 ++++++++++++++++++ .../@stdlib/blas/base/drot/examples/index.js | 54 +++ .../@stdlib/blas/base/drot/lib/drot.js | 89 +++++ .../@stdlib/blas/base/drot/lib/index.js | 72 ++++ .../@stdlib/blas/base/drot/lib/main.js | 35 ++ .../@stdlib/blas/base/drot/lib/ndarray.js | 85 +++++ .../@stdlib/blas/base/drot/package.json | 78 +++++ .../@stdlib/blas/base/drot/test/test.drot.js | 214 ++++++++++++ .../@stdlib/blas/base/drot/test/test.js | 82 +++++ .../blas/base/drot/test/test.ndarray.js | 280 ++++++++++++++++ 15 files changed, 1922 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/drot/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/drot/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/drot.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md new file mode 100644 index 000000000000..10f6284209b9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -0,0 +1,192 @@ + + +# drot + +> Applies a plane rotation. + +
+ +## Usage + +```javascript +var drot = require( '@stdlib/blas/base/drot' ); +``` + +#### drot( N, x, strideX, y, strideY, c, s ) + +Applies a plane rotation. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + +drot( x.length, x, 1, y, 1, 1.0, 0.0 ); +// x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +// y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input [`Float64Array`][mdn-float64array]. +- **strideX**: index increment for `x`. +- **y**: second input [`Float64Array`][mdn-float64array]. +- **strideY**: index increment for `y`. +- **c**: double precision cosine. +- **s**: double precision sin. + +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply plane rotation for the strided arrays +in reverse order. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +drot( x.length, x, 2, y, 2, 0.707, 0.707 ); +// x => [ ~5.6, 2.0, ~8.5, 4.0, ~11.3, 6.0 ] +// y => [ ~4.2, 8.0, ~4.2, ~10.0, ~4.2, 12.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +#### drot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) + +Applies a plane rotation. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + +drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 0.0 ); +// x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +// y => [ 6.0, 7.0, 8.0, 9.0, 10.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, for offset of two in x rotate every other value in `x` starting from the second value,..., + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); +// 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 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions leave `x` and `y` unchanged. +- `drot()` corresponds to the [BLAS][blas] level 1 function [`drot`][drot]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var drot = require( '@stdlib/blas/base/drot' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 500, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 255, opts ); +console.log( y ); + +// Applies a plane rotation : +drot( x.length, x, 1, y, -1, 0.707, 0.707 ); +console.log( x ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.js new file mode 100644 index 000000000000..0f9731626539 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/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 drot = require( './../lib/drot.js' ); + + +// 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 = drot( 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/drot/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..a67f074eeeb1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/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 drot = require( './../lib/ndarray.js' ); + + +// 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 = drot( 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/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt new file mode 100644 index 000000000000..5049fb1927fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -0,0 +1,113 @@ + +{{alias}}( N, x, strideX, y, strideY, c, s ) + Applies a plane rotation. + + The `N` and stride parameters determine how values from `x` and `y` are rotated. + + 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: Float64Array + First input array. + + strideX: integer + Index increment for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Index increment for `y`. + + c: float + cosine of angle for rotation. + + s: float + sin of angle for rotation. + + Returns + ------- + y: Float64Array + Second input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + > {{alias}}( x.length, x, 1, y, 1, 0.707, 0.707 ) + [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + > {{alias}}( 2, x, -2, y, 1, 0.707, 0.707 ) + [ 6.0, 2.121, 4.242, 9.0, 10.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Interchanges two double-precision floating-point vectors 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: Float64Array + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + c: float + cosine of angle for rotation. + + s: float + sin of angle for rotation. + + Returns + ------- + y: Float64Array + Second input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, 0.707, 0.707 ) + [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] + + // Advanced indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > {{alias}}.ndarray( 2, x, 1, 0, y, 1, 2, 0.707, 0.707 ) + [ 6.0, 7.0, 4.949, 4.949, 10.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts new file mode 100644 index 000000000000..74f1e20bbc54 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -0,0 +1,113 @@ +/* +* @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 + +/** +* Interface describing `drot`. +*/ +interface Routine { + /** + * Applies 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 - double precision + * @param s - double precision + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + * + * dswap( x.length, x, 1, y, 1, 1.0, 1.0 ); + * // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] + * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + ( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number, c: number, s: number ): Float64Array; + + /** + * Applies plane rotation. + * + * @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 - double precision + * @param s - double precision + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + * + * dswap.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.0); + * // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] + * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, c: number, s: number ): Float64Array; +} + +/** +* Applies 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 - double precision +* @param s - double precision +* @returns `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* dswap( x.length, x, 1, y, 1, 1.0, 1.0 ); +* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* dswap.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.0); +* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +declare var drot: Routine; + + +// EXPORTS // + +export = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts new file mode 100644 index 000000000000..c001e318d5c4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/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 drot = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot( x.length, x, 1, y, 1, 1.0, 1.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 ); + + drot( '10', x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( true, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( false, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( null, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( undefined, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( [], x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( {}, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( ( x: number ): number => x, x, 1, y, 1, 1.0, 1.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 ); + + drot( x.length, 10, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, '10', 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, true, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, false, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, null, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, undefined, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, [], 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, {}, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, ( x: number ): number => x, 1, y, 1, 1.0, 1.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 ); + + drot( x.length, x, '10', y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, true, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, false, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, null, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, undefined, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, [], y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, {}, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, ( x: number ): number => x, y, 1, 1.0, 1.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 ); + + drot( x.length, x, 1, 10, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, '10', 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, true, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, false, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, null, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, undefined, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, [], 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, {}, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, ( x: number ): number => x, 1, 1.0, 1.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 ); + + drot( x.length, x, 1, y, '10', 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, true, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, false, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, null, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, undefined, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, [], 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, {}, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, ( x: number ): number => x, 1.0, 1.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 ); + + drot( x.length, x, 1, y, 1, '10', 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, true, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, false, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, null, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, undefined, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, [], 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, {}, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, ( x: number ): number => x, 1.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 ); + + drot( x.length, x, 1, y, 1, 1.0, '10' ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, true ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, false ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, null ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, undefined ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, [] ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, {} ); // $ExpectError + drot( 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 ); + + drot(); // $ExpectError + drot( x.length ); // $ExpectError + drot( x.length, x ); // $ExpectError + drot( x.length, x, 1 ); // $ExpectError + drot( x.length, x, 1, y ); // $ExpectError + drot( x.length, x, 1, y, 1, 10 ); // $ExpectError + drot( x.length, x, 1, y, 1, 10, 1.0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.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 ); + + drot.ndarray( '10', x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( true, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( false, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( null, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( undefined, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( [], x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( {}, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0, 1.0, 1.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 ); + + drot.ndarray( x.length, 10, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, '10', 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, true, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, false, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, null, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, undefined, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, [], 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, {}, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot.ndarray( x.length, x, '10', 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, true, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, false, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, null, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, undefined, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, [], 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, {}, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot.ndarray( x.length, x, 1, '10', y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, true, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, false, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, null, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, undefined, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, [], y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, {}, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, 1.0, 1.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 ); + + drot.ndarray( x.length, x, 1, 0, 10, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, '10', 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, true, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, false, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, null, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, undefined, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, [], 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, {}, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0, 1.0, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot.ndarray( x.length, x, 1, 0, y, '10', 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, true, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, false, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, null, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, undefined, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, [], 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, {}, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, 1.0, 1.0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drot.ndarray( x.length, x, 1, 0, y, 1, '10', 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, true, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, false, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, null, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, undefined, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, [], 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, {}, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, 1.0, 1.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 ); + + drot.ndarray( x.length, x, 1, 0, y, 1, 0, '10', 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, true, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, false, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, null, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, undefined, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, [], 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, {}, 1.0 ); // $ExpectError + drot.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 ); + + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, '1.0' ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, true ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, false ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, null ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, undefined ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, [] ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, {} ); // $ExpectError + drot.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 ); + + drot.ndarray(); // $ExpectError + drot.ndarray( x.length ); // $ExpectError + drot.ndarray( x.length, x ); // $ExpectError + drot.ndarray( x.length, x, 1 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js new file mode 100644 index 000000000000..21232c1b269f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js @@ -0,0 +1,54 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var drot = require( './../lib' ); + +// var opts = { +// 'dtype': 'float64' +// }; +// var x = discreteUniform( 10, 0, 500, opts ); +// console.log( x ); + +// var y = discreteUniform( x.length, 0, 255, opts ); +// console.log( y ); + +// drot( x.length, x, 0, y, 0, 0.707, 0.707 ); +// console.log( x ); +// console.log( y ); +var x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 +]); +var y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 +]); +drot( 2, x, -1, y, 2, 0.707, 0.707 ); +console.log(x); +console.log(y); + diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js new file mode 100644 index 000000000000..7368365fa4a3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -0,0 +1,89 @@ +/** +* @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'; + +// MAIN // + +/** +* Applies a plane rotation. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {number} c - double-precision floating-point number +* @param {number} s - double-precision floating-point number +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* drot( x.length, x, 1, y, 1, 0.707, 0.707 ); +* // x => [ ~4.9, ~6.4, ~7.8, ~9.2, ~10.6 ] +* // y => [ ~3.5, ~3.5, ~3.5, ~3.5, ~3.5 ] +*/ +function drot( N, x, strideX, y, strideY, c, s ) { + var tmp; + var ix; + var iy; + var i; + if ( N <= 0 ) { + return y; + } + + // If both strides are equal to `1`... + if ( strideX === 1 && strideY === 1 ) { + for ( i = 0; i < N; i++ ) { + tmp = c * x[ i ] + s * y[ i ]; + y[ i ] = c * y[ i ] - s * x[ i ]; + x[ i ] = tmp; + } + } + + // If both strides are not equal to `1`... + else { + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + 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 = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js new file mode 100644 index 000000000000..028898514944 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -0,0 +1,72 @@ +/** +* @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'; + +/** +* BLAS level 1 routine to apply a plane rotation. +* +* @module @stdlib/blas/base/drot +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var drot = require( '@stdlib/blas/base/drot' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* drot( x.length, x, 1, y, 1 ); +* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var drot = require( '@stdlib/blas/base/drot' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* drot( x.length, x, 1, y, 1, 1.0, 0.0 ); +* // x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* // y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var drot; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + drot = main; +} else { + drot = tmp; +} + + +// EXPORTS // + +module.exports = drot; + +// exports: { "ndarray": "drot.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/main.js b/lib/node_modules/@stdlib/blas/base/drot/lib/main.js new file mode 100644 index 000000000000..348b83c4caa8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/main.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'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var drot = require( './drot.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( drot, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js new file mode 100644 index 000000000000..a5a3576b5bc8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -0,0 +1,85 @@ +/** +* @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'; + +// MAIN // + +/** +* Applies a plane rotation. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @param {number} c - double-precision floating-point number +* @param {number} s - double-precision floating-point number +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* drot( x.length, x, 1, 2, y, 1, 2, 0.707, 0.707 ); +* // x => [ 1.0, 2.0, ~7.8, ~9.2, ~10.6 ] +* // y => [ 6.0, 7.0, ~3.5, ~3.5, ~3.5 ] +*/ +function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { + var tmp; + var ix; + var iy; + var i; + if ( N <= 0 ) { + return y; + } + ix = offsetX; + iy = offsetY; + + // If both strides are equal to `1`... + if (strideX === 1 && strideY === 1 ) { + 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; + } + } + + // If both strides are not equal to `1`... + else { + 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 = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/package.json b/lib/node_modules/@stdlib/blas/base/drot/package.json new file mode 100644 index 000000000000..9868fafbb8b7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/package.json @@ -0,0 +1,78 @@ +{ + "name": "@stdlib/blas/base/drot", + "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", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "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", + "linear", + "algebra", + "subroutines", + "drot", + "rotation", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "typed array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js new file mode 100644 index 000000000000..17862ec803db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -0,0 +1,214 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var drot = require( './../lib/drot.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( drot.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + N = 2; + + drot( N, x, 2, y, 1, 0.707, 0.707 ); + + xe = new Float64Array( [ ~5.0, 2.0, ~7.1, 4.0, 5.0 ] ); + ye = new Float64Array( [ ~3.5, ~2.9, 8.0, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + N = 2; + + drot( N, x, 1, y, 2, 0.707, 0.707 ); + + xe = new Float64Array( [ ~5.0, ~7.1, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ ~3.5, 7.0, ~4.2, 9.0, 10.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 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = drot( 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 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float64Array( x.length ); + dcopy( x.length, x, 1, xe, 1, 0.707, 0.707 ); + + ye = new Float64Array( y.length ); + dcopy( y.length, y, 1, ye, 1, 0.707, 0.707 ); + + drot( -1, x, 1, y, 1, 0.707, 0.707 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drot( 0, x, 1, y, 1, 0.707, 0.707 ); + 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; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + N = 2; + + drot( N, x, -1, y, 2, 0.707, 0.707 ); + + xe = new Float64Array( [ 6.3629999999999995, 5.656, 3, 4, 5 ] ); + ye = new Float64Array( [ 2.8280000000000003, 7, 4.949, 9, 10 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float64Array([ + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0, + 11.0, + 12.0 + ]); + N = 2; + + drot( N, x, 2, y, -1, 0.707, 0.707 ); + + xe = new Float64Array( [ 6.3629999999999995, 2, 7.07, 4, 5, 6 ] ); + ye = new Float64Array( [ 7.0, 2.828, 4.949, 10.0, 11.0, 12.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.js new file mode 100644 index 000000000000..9a024d23d713 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var isBrowser = require( '@stdlib/assert/is-browser' ); +var drot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, '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 drot.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var drot = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( drot, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var drot; + var main; + + main = require( './../lib/drot.js' ); + + drot = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( drot, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js new file mode 100644 index 000000000000..7f4b16ffd4c6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -0,0 +1,280 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var drot = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', function test( t ) { + t.strictEqual( drot.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + var N = 2; + + drot( N, x, 2, 0, y, 1, 0, 0.707, 0.707); + + xe = new Float64Array( [ 4.949, 2.0, 7.07, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.535, 2.828, 8.0, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]); + var N = 2; + + drot( N, x, 2, 2, y, 1, 0, 0.707, 0.707); + + xe = new Float64Array( [ 1.0, 2.0, 6.3629999999999995, 4.0, 8.484 ] ); + ye = new Float64Array( [ 2.121, 1.4140000000000001, 8.0, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + var N = 2; + + drot( N, x, 1, 0, y, 2, 0, 0.707, 0.707); + + xe = new Float64Array( [ 4.949, 7.069999999999999, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 // 2 + ]); + var N = 2; + + drot( N, x, 1, 0, y, 1, 2, 0.707, 0.707); + + xe = new Float64Array( [ 6.3629999999999995, 7.776999999999999, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 7.0, 4.949, 4.949, 10.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 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = drot( x.length, x, 1, 0, y, 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 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float64Array( x.length ); + dcopy( x.length, x, 1, 0, xe, 1, 0, 0.707, 0.707 ); + + ye = new Float64Array( y.length ); + dcopy( y.length, y, 1, 0, ye, 1, 0, 0.707, 0.707 ); + + drot( -1, x, 1, 0, y, 1, 0, 0.707, 0.707 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drot( 0, x, 1, 0, y, 1, 0, 0.707, 0.707 ); + 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; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + var N = 2; + + drot( N, x, -1, 0, y, 1, 2, 0.707, 0.707); + + xe = new Float64Array( [ 1.0, 7.776999999999999, 7.776999999999999, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 7.0, 3.5349999999999997, 4.949, 10.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var xe; + var ye; + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 7.0, + 8.0, + 9.0, + 10.0, // 2 + 11.0, // 1 + 12.0 // 0 + ]); + var N = 2; + + drot( N, x, 1, 0, y, -1, 2, 0.707, 0.707); + + xe = new Float64Array( [ 7.069999999999999, 7.069999999999999, 3.0, 4.0, 5.0, 6.0 ] ); + ye = new Float64Array( [ 7.0, 4.242, 5.656, 10.0, 11.0, 12.0 ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + t.end(); +}); From 64788f5c3c9b23109a7bd251c18a6b5dec822629 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 11 Mar 2024 12:19:06 +0530 Subject: [PATCH 02/27] feat: add BLAS Level 1 drot routine --- .../@stdlib/blas/base/drot/examples/index.js | 39 +++++-------------- .../@stdlib/blas/base/drot/lib/index.js | 13 ++++--- .../@stdlib/blas/base/drot/test/test.drot.js | 12 +++--- .../blas/base/drot/test/test.ndarray.js | 38 +++++++----------- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js index 21232c1b269f..5942084aeb45 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js @@ -19,36 +19,17 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); var drot = require( './../lib' ); -// var opts = { -// 'dtype': 'float64' -// }; -// var x = discreteUniform( 10, 0, 500, opts ); -// console.log( x ); +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 500, opts ); +console.log( x ); -// var y = discreteUniform( x.length, 0, 255, opts ); -// console.log( y ); - -// drot( x.length, x, 0, y, 0, 0.707, 0.707 ); -// console.log( x ); -// console.log( y ); -var x = new Float64Array([ - 1.0, // 0 - 2.0, - 3.0, // 1 - 4.0, - 5.0 // 2 -]); -var y = new Float64Array([ - 6.0, // 0 - 7.0, // 1 - 8.0, // 2 - 9.0, - 10.0 -]); -drot( 2, x, -1, y, 2, 0.707, 0.707 ); -console.log(x); -console.log(y); +var y = discreteUniform( x.length, 0, 255, opts ); +console.log( y ); +drot( x.length, x, 0, y, 0, 0.707, 0.707 ); +console.log( x ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index 028898514944..fd92a6fdf5d5 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -30,9 +30,9 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 1, y, 1 ); -* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] -* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* drot( x.length, x, 1, y, 1, 0.707, 0.707 ); +* // x => [ ~4.9, ~6.4, ~7.8, ~9.2, ~10.6 ] +* // y => [ ~3.5, ~3.5, ~3.5, ~3.5, ~3.5 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -40,10 +40,11 @@ * * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* var N = 2; * -* drot( x.length, x, 1, y, 1, 1.0, 0.0 ); -* // x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* // y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +* drot( N, x, 2, y, 1, 0.707, 0.707 ); +* // x => [ ~5.0, 2.0, ~7.1, 4.0, 5.0 ] +* // y => [ ~3.5, ~2.8, 8.0, 9.0, 10.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index 17862ec803db..c9844c297f1d 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -64,8 +64,8 @@ tape( 'the function supports an `x` stride', function test( t ) { drot( N, x, 2, y, 1, 0.707, 0.707 ); - xe = new Float64Array( [ ~5.0, 2.0, ~7.1, 4.0, 5.0 ] ); - ye = new Float64Array( [ ~3.5, ~2.9, 8.0, 9.0, 10.0 ] ); + xe = new Float64Array( [ 4.949, 2.0, 7.07, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.535, 2.828, 8.0, 9.0, 10.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); @@ -97,8 +97,8 @@ tape( 'the function supports a `y` stride', function test( t ) { drot( N, x, 1, y, 2, 0.707, 0.707 ); - xe = new Float64Array( [ ~5.0, ~7.1, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ ~3.5, 7.0, ~4.2, 9.0, 10.0 ] ); + xe = new Float64Array( [ 4.949, 7.069999999999999, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); @@ -205,8 +205,8 @@ tape( 'the function supports complex access patterns', function test( t ) { drot( N, x, 2, y, -1, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, 2, 7.07, 4, 5, 6 ] ); - ye = new Float64Array( [ 7.0, 2.828, 4.949, 10.0, 11.0, 12.0 ] ); + xe = new Float64Array( [ 6.3629999999999995, 2.0, 7.07, 4.0, 5.0, 6.0 ] ); + ye = new Float64Array( [ 2.828, 4.949, 9.0, 10.0, 11.0, 12.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 7f4b16ffd4c6..31c82ca2822a 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -44,7 +44,6 @@ tape( 'the function supports an `x` stride', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -60,9 +59,8 @@ tape( 'the function supports an `x` stride', function test( t ) { 9.0, 10.0 ]); - var N = 2; - drot( N, x, 2, 0, y, 1, 0, 0.707, 0.707); + drot( 2, x, 2, 0, y, 1, 0, 0.707, 0.707 ); xe = new Float64Array( [ 4.949, 2.0, 7.07, 4.0, 5.0 ] ); ye = new Float64Array( [ 3.535, 2.828, 8.0, 9.0, 10.0 ] ); @@ -77,7 +75,6 @@ tape( 'the function supports an `x` offset', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, @@ -93,9 +90,8 @@ tape( 'the function supports an `x` offset', function test( t ) { 9.0, 10.0 ]); - var N = 2; - drot( N, x, 2, 2, y, 1, 0, 0.707, 0.707); + drot( 2, x, 2, 2, y, 1, 0, 0.707, 0.707 ); xe = new Float64Array( [ 1.0, 2.0, 6.3629999999999995, 4.0, 8.484 ] ); ye = new Float64Array( [ 2.121, 1.4140000000000001, 8.0, 9.0, 10.0 ] ); @@ -110,7 +106,6 @@ tape( 'the function supports a `y` stride', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -126,9 +121,8 @@ tape( 'the function supports a `y` stride', function test( t ) { 9.0, 10.0 // 2 ]); - var N = 2; - drot( N, x, 1, 0, y, 2, 0, 0.707, 0.707); + drot( 2, x, 1, 0, y, 2, 0, 0.707, 0.707 ); xe = new Float64Array( [ 4.949, 7.069999999999999, 3.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); @@ -143,7 +137,6 @@ tape( 'the function supports a `y` offset', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -159,11 +152,14 @@ tape( 'the function supports a `y` offset', function test( t ) { 9.0, // 1 10.0 // 2 ]); - var N = 2; - drot( N, x, 1, 0, y, 1, 2, 0.707, 0.707); + drot( 2, x, 1, 0, y, 1, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, 7.776999999999999, 3.0, 4.0, 5.0 ] ); + xe = new Float64Array( [ 6.3629999999999995, + 7.776999999999999, + 3.0, + 4.0, + 5.0 ] ); ye = new Float64Array( [ 6.0, 7.0, 4.949, 4.949, 10.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); @@ -216,7 +212,6 @@ tape( 'the function supports negative strides', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, // 2 @@ -232,12 +227,11 @@ tape( 'the function supports negative strides', function test( t ) { 9.0, // 0 10.0 ]); - var N = 2; - drot( N, x, -1, 0, y, 1, 2, 0.707, 0.707); + drot( 5, x, -1, 0, y, -1, 0, 0.707, 0.707 ); - xe = new Float64Array( [ 1.0, 7.776999999999999, 7.776999999999999, 4.0, 5.0 ] ); - ye = new Float64Array( [ 6.0, 7.0, 3.5349999999999997, 4.949, 10.0 ] ); + xe = new Float64Array( [ 4.949, 2.0, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.535, 7.0, 8.0, 9.0, 10.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); @@ -249,7 +243,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var ye; var x; var y; - var N; x = new Float64Array([ 1.0, @@ -267,12 +260,11 @@ tape( 'the function supports complex access patterns', function test( t ) { 11.0, // 1 12.0 // 0 ]); - var N = 2; - drot( N, x, 1, 0, y, -1, 2, 0.707, 0.707); + drot( 4, x, 1, 5, y, -5, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 7.069999999999999, 7.069999999999999, 3.0, 4.0, 5.0, 6.0 ] ); - ye = new Float64Array( [ 7.0, 4.242, 5.656, 10.0, 11.0, 12.0 ] ); + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 10.605 ] ); + ye = new Float64Array( [ 7.0, 8.0, 2.1209999999999996, 10.0, 11.0, 12.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); From e064ac3958f050bc1a892a0a31d743f9f643c0bd Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 11 Mar 2024 14:30:53 +0530 Subject: [PATCH 03/27] chore: apply error changes --- lib/node_modules/@stdlib/blas/base/drot/README.md | 13 ++++--------- lib/node_modules/@stdlib/blas/base/drot/lib/drot.js | 8 ++++---- .../@stdlib/blas/base/drot/lib/ndarray.js | 8 ++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 10f6284209b9..bcb042dde921 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -65,8 +65,8 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); drot( x.length, x, 2, y, 2, 0.707, 0.707 ); -// x => [ ~5.6, 2.0, ~8.5, 4.0, ~11.3, 6.0 ] -// y => [ ~4.2, 8.0, ~4.2, ~10.0, ~4.2, 12.0 ] +// x => [ 5.656, 2.0, 8.484, 4.0, 11.312, 6.0 ] +// y => [ 4.242, 8.0, 4.241999999999999, 10.0, 4.241999999999999, 12.0 ] ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. @@ -102,8 +102,8 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); -// 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 ] +// x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] +// y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] ``` @@ -158,9 +158,6 @@ console.log( y ); ## See Also -- [`@stdlib/blas/base/dcopy`][@stdlib/blas/base/dcopy]: copy values from x into y. -- [`@stdlib/blas/base/gswap`][@stdlib/blas/base/gswap]: interchange two vectors. -- [`@stdlib/blas/base/sswap`][@stdlib/blas/base/sswap]: interchange two single-precision floating-point vectors. - [`@stdlib/blas/drot`][@stdlib/blas/drot]: interchange two double-precision floating-point vectors. @@ -181,8 +178,6 @@ console.log( y ); -[@stdlib/blas/base/dcopy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dcopy - [@stdlib/blas/drot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/drot diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index 7368365fa4a3..54f32ddc52cd 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -54,8 +54,8 @@ function drot( N, x, strideX, y, strideY, c, s ) { // If both strides are equal to `1`... if ( strideX === 1 && strideY === 1 ) { for ( i = 0; i < N; i++ ) { - tmp = c * x[ i ] + s * y[ i ]; - y[ i ] = c * y[ i ] - s * x[ i ]; + tmp = ( c * x[ i ] ) + ( s * y[ i ] ); + y[ i ] = ( c * y[ i ] ) - ( s * x[ i ] ); x[ i ] = tmp; } } @@ -73,8 +73,8 @@ function drot( N, x, strideX, y, strideY, c, s ) { iy = 0; } for ( i = 0; i < N; i++ ) { - tmp = c * x[ ix ] + s * y[ iy ]; - y[ iy ] = c * y[ iy ] - s * x[ ix ]; + tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); + y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); x[ ix ] = tmp; ix += strideX; iy += strideY; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index a5a3576b5bc8..aa53d84d5275 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -58,8 +58,8 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { // If both strides are equal to `1`... if (strideX === 1 && strideY === 1 ) { for ( i = 0; i < N; i++ ) { - tmp = c * x[ ix ] + s * y[ iy ]; - y[ iy ] = c * y[ iy ] - s * x[ ix ]; + tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); + y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); x[ ix ] = tmp; ix += strideX; iy += strideY; @@ -69,8 +69,8 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { // If both strides are not equal to `1`... else { for ( i = 0; i < N; i++ ) { - tmp = c * x[ ix ] + s * y[ iy ]; - y[ iy ] = c * y[ iy ] - s * x[ ix ]; + tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); + y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); x[ ix ] = tmp; ix += strideX; iy += strideY; From 9960599594f6494d8527bb98102bc58a3804589c Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 11 Mar 2024 18:21:06 +0530 Subject: [PATCH 04/27] chore: solve lint error --- .../@stdlib/blas/base/drot/docs/repl.txt | 41 +++++++++---------- .../@stdlib/blas/base/drot/test/test.drot.js | 4 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 5049fb1927fa..d7944f0acc46 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -2,7 +2,8 @@ {{alias}}( N, x, strideX, y, strideY, c, s ) Applies a plane rotation. - The `N` and stride parameters determine how values from `x` and `y` are rotated. + The `N` and stride parameters determine how values + from `x` and `y` are rotated. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -27,10 +28,10 @@ Index increment for `y`. c: float - cosine of angle for rotation. + Cosine of angle for rotation. s: float - sin of angle for rotation. + Sin of angle for rotation. Returns ------- @@ -39,22 +40,21 @@ Examples -------- - // Standard usage: + // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}( x.length, x, 1, y, 1, 0.707, 0.707 ) - [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] + > {{alias}}( x.length, x, 1, y, 1, 1.0, 0.0 ) + [ 6.0, 7.0, 8.0, 9.0, 10.0 ] - // Advanced indexing: + // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}( 2, x, -2, y, 1, 0.707, 0.707 ) - [ 6.0, 2.121, 4.242, 9.0, 10.0 ] + > {{alias}}( 2, x, -1, y, 2, 0.707, 0.707 ) + [ 2.8280000000000003, 7.0, 4.949, 9.0, 10.0 ] -{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) - Interchanges two double-precision floating-point vectors using alternative - indexing semantics. +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) + Applies a plane rotation. While typed array views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting @@ -84,10 +84,10 @@ Starting index for `y`. c: float - cosine of angle for rotation. + Cosine of angle for rotation. s: float - sin of angle for rotation. + Sin of angle for rotation. Returns ------- @@ -96,18 +96,17 @@ Examples -------- - // Standard usage: + // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, 0.707, 0.707 ) - [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 0.0 ) + [ 6.0, 7.0, 8.0, 9.0, 10.0 ] - // Advanced indexing: + // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > {{alias}}.ndarray( 2, x, 1, 0, y, 1, 2, 0.707, 0.707 ) - [ 6.0, 7.0, 4.949, 4.949, 10.0 ] + > {{alias}}.ndarray( 4, x, 1, 5, y, -5, 2, 0.707, 0.707 ) + [ 7.0, 8.0, 2.1209999999999996, 10.0, 11.0, 12.0 ] See Also -------- - diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index c9844c297f1d..88ff9cb3ec4c 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -170,8 +170,8 @@ tape( 'the function supports negative strides', function test( t ) { drot( N, x, -1, y, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, 5.656, 3, 4, 5 ] ); - ye = new Float64Array( [ 2.8280000000000003, 7, 4.949, 9, 10 ] ); + xe = new Float64Array( [ 6.3629999999999995, 5.656, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 2.8280000000000003, 7.0, 4.949, 9.0, 10.0 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); From 37dd2672973b15ed1328f08e429d69e8ca3516f7 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 11 Mar 2024 23:25:50 +0530 Subject: [PATCH 05/27] chore: apply changes for lint error and tests --- .../@stdlib/blas/base/drot/README.md | 2 +- .../blas/base/drot/docs/types/index.d.ts | 44 ++-- .../@stdlib/blas/base/drot/docs/types/test.ts | 228 +++++++++--------- .../@stdlib/blas/base/drot/examples/index.js | 2 +- .../@stdlib/blas/base/drot/lib/drot.js | 4 +- .../@stdlib/blas/base/drot/lib/index.js | 8 +- .../@stdlib/blas/base/drot/lib/ndarray.js | 11 +- .../@stdlib/blas/base/drot/test/test.drot.js | 115 ++++++++- .../blas/base/drot/test/test.ndarray.js | 135 ++++++++++- 9 files changed, 390 insertions(+), 159 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index bcb042dde921..9047dd7876f7 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -141,7 +141,7 @@ var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); // Applies a plane rotation : -drot( x.length, x, 1, y, -1, 0.707, 0.707 ); +drot( x.length, x, 1, y, 1, 0.707, 0.707 ); console.log( x ); console.log( y ); ``` diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts index 74f1e20bbc54..581eb35c8cf0 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -30,8 +30,8 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length - * @param c - double precision - * @param s - double precision + * @param c - double precision floating-point number + * @param s - double precision floating-point number * @returns `y` * * @example @@ -40,9 +40,9 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * - * dswap( x.length, x, 1, y, 1, 1.0, 1.0 ); - * // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] - * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); + * // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] + * // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] */ ( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number, c: number, s: number ): Float64Array; @@ -56,19 +56,19 @@ interface Routine { * @param y - second input array * @param strideY - `y` stride length * @param offsetY - starting index for `y` - * @param c - double precision - * @param s - double precision + * @param c - double precision floating-point number + * @param s - double precision floating-point number * @returns `y` * * @example * var Float64Array = require( '@stdlib/array/float64' ); * - * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * - * dswap.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.0); - * // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] - * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] + * drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); + * // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] + * // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] */ ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, c: number, s: number ): Float64Array; } @@ -81,8 +81,8 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length -* @param c - double precision -* @param s - double precision +* @param c - double precision floating-point number +* @param s - double precision floating-point number * @returns `y` * * @example @@ -91,19 +91,19 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* dswap( x.length, x, 1, y, 1, 1.0, 1.0 ); -* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] -* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* drot( x.length, x, 1, y, 1, 1.0, 0.0 ); +* // x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* // y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); * -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * -* dswap.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.0); -* // x => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] -* // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); +* // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] +* // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] */ declare var drot: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts index c001e318d5c4..310f6fe4efe4 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/test.ts @@ -26,7 +26,7 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( x.length, x, 1, y, 1, 1.0, 1.0 ); // $ExpectType Float64Array + drot( 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... @@ -34,14 +34,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( '10', x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( true, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( false, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( null, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( undefined, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( [], x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( {}, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( ( x: number ): number => x, x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( '10', x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( true, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( false, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( null, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( undefined, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( [], x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( {}, x, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( ( 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... @@ -49,15 +49,15 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( x.length, 10, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, '10', 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, true, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, false, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, null, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, undefined, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, [], 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, {}, 1, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, ( x: number ): number => x, 1, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, 10, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, '10', 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, true, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, false, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, null, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, undefined, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, [], 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, {}, 1, y, 1, 1.0, 0.0 ); // $ExpectError + drot( 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... @@ -65,29 +65,29 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( x.length, x, '10', y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, true, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, false, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, null, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, undefined, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, [], y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, {}, y, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, ( x: number ): number => x, y, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, '10', y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, true, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, false, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, null, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, undefined, y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, [], y, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, {}, y, 1, 1.0, 0.0 ); // $ExpectError + drot( 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 ); - drot( x.length, x, 1, 10, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, '10', 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, true, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, false, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, null, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, undefined, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, [], 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, {}, 1, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, ( x: number ): number => x, 1, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, 10, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, '10', 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, true, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, false, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, null, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, undefined, 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, [], 1, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, {}, 1, 1.0, 0.0 ); // $ExpectError + drot( 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... @@ -95,14 +95,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( x.length, x, 1, y, '10', 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, true, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, false, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, null, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, undefined, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, [], 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, {}, 1.0, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, ( x: number ): number => x, 1.0, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, '10', 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, true, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, false, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, null, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, undefined, 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, [], 1.0, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, {}, 1.0, 0.0 ); // $ExpectError + drot( 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... @@ -110,14 +110,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot( x.length, x, 1, y, 1, '10', 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, true, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, false, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, null, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, undefined, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, [], 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, {}, 1.0 ); // $ExpectError - drot( x.length, x, 1, y, 1, ( x: number ): number => x, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, '10', 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, true, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, false, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, null, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, undefined, 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, [], 0.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, {}, 0.0 ); // $ExpectError + drot( 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... @@ -145,8 +145,8 @@ import drot = require( './index' ); drot( x.length, x ); // $ExpectError drot( x.length, x, 1 ); // $ExpectError drot( x.length, x, 1, y ); // $ExpectError - drot( x.length, x, 1, y, 1, 10 ); // $ExpectError - drot( x.length, x, 1, y, 1, 10, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0 ); // $ExpectError + drot( x.length, x, 1, y, 1, 1.0, 0.0, 10 ); // $ExpectError } // Attached to main export is an `ndarray` method which returns a Float64Array... @@ -154,7 +154,7 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectType Float64Array + drot.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... @@ -162,14 +162,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( '10', x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( true, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( false, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( null, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( undefined, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( [], x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( {}, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( '10', x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( true, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( false, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( null, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( undefined, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( [], x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( {}, x, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -177,15 +177,15 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, 10, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, '10', 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, true, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, false, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, null, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, undefined, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, [], 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, {}, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, 10, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, '10', 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, true, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, false, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, null, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, undefined, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, [], 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, {}, 1, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -193,14 +193,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, x, '10', 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, true, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, false, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, null, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, undefined, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, [], 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, {}, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, '10', 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, true, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, false, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, null, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, undefined, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, [], 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, {}, 0, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -208,29 +208,29 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, x, 1, '10', y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, true, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, false, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, null, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, undefined, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, [], y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, {}, y, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, '10', y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, true, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, false, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, null, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, undefined, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, [], y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, {}, y, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.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 ); - drot.ndarray( x.length, x, 1, 0, 10, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, '10', 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, true, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, false, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, null, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, undefined, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, [], 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, {}, 1, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, 10, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, '10', 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, true, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, false, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, null, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, undefined, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, [], 1, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, {}, 1, 0, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -238,14 +238,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, x, 1, 0, y, '10', 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, true, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, false, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, null, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, undefined, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, [], 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, {}, 0, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, '10', 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, true, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, false, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, null, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, undefined, 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, [], 0, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, {}, 0, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -253,14 +253,14 @@ import drot = require( './index' ); const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); - drot.ndarray( x.length, x, 1, 0, y, 1, '10', 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, true, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, false, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, null, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, undefined, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, [], 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, {}, 1.0, 1.0 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, 1.0, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, '10', 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, true, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, false, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, null, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, undefined, 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, [], 1.0, 0.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1, {}, 1.0, 0.0 ); // $ExpectError + drot.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... @@ -304,6 +304,6 @@ import drot = require( './index' ); drot.ndarray( x.length, x, 1 ); // $ExpectError drot.ndarray( x.length, x, 1, 0 ); // $ExpectError drot.ndarray( x.length, x, 1, 0, y ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError - drot.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1.0 ); // $ExpectError + drot.ndarray( x.length, x, 1, 0, y, 1.0, 0.0, 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js index 5942084aeb45..2e8fb4720818 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js @@ -30,6 +30,6 @@ console.log( x ); var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); -drot( x.length, x, 0, y, 0, 0.707, 0.707 ); +drot( x.length, x, 1, y, 1, 0.707, 0.707 ); console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index 54f32ddc52cd..1a4b2ef72b2b 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -39,8 +39,8 @@ * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ ~4.9, ~6.4, ~7.8, ~9.2, ~10.6 ] -* // y => [ ~3.5, ~3.5, ~3.5, ~3.5, ~3.5 ] +* // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] +* // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] */ function drot( N, x, strideX, y, strideY, c, s ) { var tmp; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index fd92a6fdf5d5..7ba59459b143 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -31,8 +31,8 @@ * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ ~4.9, ~6.4, ~7.8, ~9.2, ~10.6 ] -* // y => [ ~3.5, ~3.5, ~3.5, ~3.5, ~3.5 ] +* // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] +* // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -43,8 +43,8 @@ * var N = 2; * * drot( N, x, 2, y, 1, 0.707, 0.707 ); -* // x => [ ~5.0, 2.0, ~7.1, 4.0, 5.0 ] -* // y => [ ~3.5, ~2.8, 8.0, 9.0, 10.0 ] +* // x => [ 4.949, 2.0, 7.07, 4.0, 5.0 ] +* // y => [ 3.535, 2.828, 8.0, 9.0, 10.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index aa53d84d5275..4a1bcd8774a5 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -37,12 +37,13 @@ * @example * var Float64Array = require( '@stdlib/array/float64' ); * -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var N = 4; * -* drot( x.length, x, 1, 2, y, 1, 2, 0.707, 0.707 ); -* // x => [ 1.0, 2.0, ~7.8, ~9.2, ~10.6 ] -* // y => [ 6.0, 7.0, ~3.5, ~3.5, ~3.5 ] +* drot( N, x, 0, 2, y, 0, 2, 0.707, 0.707 ); +* // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] +* // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] */ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var tmp; diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index 88ff9cb3ec4c..e975ab5d7dbc 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -23,6 +23,8 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var dcopy = require( '@stdlib/blas/base/dcopy' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); var drot = require( './../lib/drot.js' ); @@ -39,6 +41,115 @@ tape( 'the function has an arity of 7', function test( t ) { t.end(); }); +tape( 'the function applies a plane rotation', function test( t ) { + var xexpected; + var yexpected; + var ixvalues; + var iyvalues; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var ix; + var iy; + var c; + var i; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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 ], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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.020000000000000073], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06000000000000005, 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.020000000000000073], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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 ] + ]; + yexpected = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.78, 0.54, 0.07999999999999996, -0.6, 0.2, 0.8 ], // eslint-disable-line max-len + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -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.28000000000000014 ], + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -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 ], + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16000000000000014 ] // eslint-disable-line max-len + + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalues = [ 1, 2, -2, -1 ]; + iyvalues = [ 1, -2, 1, -2 ]; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8] + ]; + + c = 0; + for ( i = 0; i < ixvalues.length; i++ ) { + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + ix = ixvalues[ i ]; + iy = iyvalues[ i ]; + out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 1.5 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 1.5 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 1.5 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + } + t.end(); +}); + tape( 'the function supports an `x` stride', function test( t ) { var xe; var ye; @@ -129,10 +240,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); xe = new Float64Array( x.length ); - dcopy( x.length, x, 1, xe, 1, 0.707, 0.707 ); + dcopy( x.length, x, 1, xe, 1 ); ye = new Float64Array( y.length ); - dcopy( y.length, y, 1, ye, 1, 0.707, 0.707 ); + dcopy( y.length, y, 1, ye, 1 ); drot( -1, x, 1, y, 1, 0.707, 0.707 ); t.deepEqual( x, xe, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 31c82ca2822a..69a733432696 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -23,6 +23,8 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); var drot = require( './../lib/ndarray.js' ); @@ -39,6 +41,123 @@ tape( 'the function has an arity of 9', function test( t ) { t.end(); }); +tape( 'the function applies a plane rotation', function test( t ) { + var xexpected; + var yexpected; + var ixvalues; + var iyvalues; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var i; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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 ], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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.020000000000000073], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ -0.06000000000000005, 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.020000000000000073], + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 0.78, 0.10, -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 ] + ]; + yexpected = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.78, 0.54, 0.07999999999999996, -0.6, 0.2, 0.8 ], // eslint-disable-line max-len + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -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.28000000000000014 ], + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -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 ], + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], + [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16000000000000014 ] // eslint-disable-line max-len + + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalues = [ 1, 2, -2, -1 ]; + iyvalues = [ 1, -2, 1, -2 ]; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8] + ]; + + c = 0; + for ( i = 0; i < ixvalues.length; i++ ) { + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalues[ i ] < 0 ) { + xoffset = ( 1 - nvalues[ j ] ) * ixvalues[ i ]; + } else { + xoffset = 0; + } + if ( iyvalues[ i ] < 0 ) { + yoffset = ( 1 - nvalues[ j ] ) * iyvalues[ i ]; + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalues[ i ], xoffset, y, iyvalues[ i ], yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 1.5 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 1.5 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 1.5 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + } + t.end(); +}); + tape( 'the function supports an `x` stride', function test( t ) { var xe; var ye; @@ -191,10 +310,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); xe = new Float64Array( x.length ); - dcopy( x.length, x, 1, 0, xe, 1, 0, 0.707, 0.707 ); + dcopy( x.length, x, 1, 0, xe, 1, 0 ); ye = new Float64Array( y.length ); - dcopy( y.length, y, 1, 0, ye, 1, 0, 0.707, 0.707 ); + dcopy( y.length, y, 1, 0, ye, 1, 0 ); drot( -1, x, 1, 0, y, 1, 0, 0.707, 0.707 ); t.deepEqual( x, xe, 'returns expected value' ); @@ -228,10 +347,10 @@ tape( 'the function supports negative strides', function test( t ) { 10.0 ]); - drot( 5, x, -1, 0, y, -1, 0, 0.707, 0.707 ); + drot( 3, x, -2, 4, y, -1, 3, 0.707, 0.707 ); - xe = new Float64Array( [ 4.949, 2.0, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 3.535, 7.0, 8.0, 9.0, 10.0 ] ); + xe = new Float64Array( [ 5.656, 2.0, 7.776999999999999, 4.0, 9.898 ] ); + ye = new Float64Array( [ 6, 4.242, 3.5349999999999997, 2.828, 10 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); @@ -261,10 +380,10 @@ tape( 'the function supports complex access patterns', function test( t ) { 12.0 // 0 ]); - drot( 4, x, 1, 5, y, -5, 2, 0.707, 0.707 ); + drot( 3, x, 2, 1, y, -1, 5, 0.707, 0.707 ); - xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 10.605 ] ); - ye = new Float64Array( [ 7.0, 8.0, 2.1209999999999996, 10.0, 11.0, 12.0 ] ); + xe = new Float64Array( [ 1.0, 9.898, 3.0, 10.604999999999999, 5.0, 11.312 ] ); // eslint-disable-line max-len + ye = new Float64Array( [ 7.0, 8.0, 9.0, 2.8279999999999994, 4.949, 7.07 ] ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); From de92f4a86ee72dff6bd44925d4c64aee3ad5e8f9 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 12 Mar 2024 16:29:00 +0530 Subject: [PATCH 06/27] chore: apply readme changes --- lib/node_modules/@stdlib/blas/base/drot/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 9047dd7876f7..1597886c028d 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -158,7 +158,7 @@ console.log( y ); ## See Also -- [`@stdlib/blas/drot`][@stdlib/blas/drot]: interchange two double-precision floating-point vectors. +- [`@stdlib/blas/drot`][@stdlib/blas/drot]: applies plane rotation. From 9e371a5bbca71fe5b11e5abbb746ffea5dbe4e76 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 12 Mar 2024 19:55:41 +0530 Subject: [PATCH 07/27] chore: apply review changes --- .../@stdlib/blas/base/drot/README.md | 22 ++++++++++++++++--- .../@stdlib/blas/base/drot/lib/index.js | 3 +-- .../@stdlib/blas/base/drot/test/test.drot.js | 2 +- .../blas/base/drot/test/test.ndarray.js | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 1597886c028d..aa74cd212c47 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -20,7 +20,7 @@ limitations under the License. # drot -> Applies a plane rotation. +> Apply a plane rotation.
@@ -73,9 +73,25 @@ Note that indexing is relative to the first index. To introduce an offset, use [ +```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 + +drot( 3, x1, -2, y1, 1, 0.707, 0.707 ); +// x0 => [ 1.0, 9.898, 3.0, 10.604999999999999, 5.0, 11.312 ] +// y0 => [ 7.0, 8.0, 9.0, 2.8279999999999994, 4.949, 7.07 ] +``` + #### drot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) -Applies a plane rotation. +Applies a plane rotation using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -93,7 +109,7 @@ 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, for offset of two in x rotate every other value in `x` starting from the second value,..., +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 rotation for every other value in `x` starting from second value,..., ```javascript var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index 7ba59459b143..05d591735575 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -40,9 +40,8 @@ * * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); -* var N = 2; * -* drot( N, x, 2, y, 1, 0.707, 0.707 ); +* drot( 2, x, 2, y, 1, 0.707, 0.707 ); * // x => [ 4.949, 2.0, 7.07, 4.0, 5.0 ] * // y => [ 3.535, 2.828, 8.0, 9.0, 10.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index e975ab5d7dbc..67656a24804f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -108,7 +108,7 @@ tape( 'the function applies a plane rotation', function test( t ) { [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8] + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ]; c = 0; diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 69a733432696..c6919e2c42a1 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -108,7 +108,7 @@ tape( 'the function applies a plane rotation', function test( t ) { [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8] + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ]; c = 0; From 25d75424a14150620e872b00d9df2126cf204d3d Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 13 Mar 2024 19:52:55 -0700 Subject: [PATCH 08/27] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/blas/base/drot/README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index aa74cd212c47..babad86f53cc 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -22,6 +22,20 @@ limitations under the License. > Apply a plane rotation. +
+ +This BLAS level 1 routine applies a real plane rotation to real 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 @@ -52,8 +66,8 @@ The function has the following parameters: - **strideX**: index increment for `x`. - **y**: second input [`Float64Array`][mdn-float64array]. - **strideY**: index increment for `y`. -- **c**: double precision cosine. -- **s**: double precision sin. +- **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 plane rotation for the strided arrays in reverse order. From 18681d4f6aac3f73e3eb563e2cbbae65b0efd5ef Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 13 Mar 2024 19:53:31 -0700 Subject: [PATCH 09/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index babad86f53cc..60699716a5bc 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -24,7 +24,7 @@ limitations under the License.
-This BLAS level 1 routine applies a real plane rotation to real 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: +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: From df45a1a4866121dbc8bda576f290aa9c9ffdca96 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 13 Mar 2024 19:56:53 -0700 Subject: [PATCH 10/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 60699716a5bc..87ae8fd014a3 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -69,8 +69,7 @@ The function has the following parameters: - **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 plane rotation for the strided arrays -in reverse order. +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply plane rotation to elements in the strided arrays in reverse order ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -80,7 +79,7 @@ var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); drot( x.length, x, 2, y, 2, 0.707, 0.707 ); // x => [ 5.656, 2.0, 8.484, 4.0, 11.312, 6.0 ] -// y => [ 4.242, 8.0, 4.241999999999999, 10.0, 4.241999999999999, 12.0 ] +// y => [ 4.242, 8.0, ~4.242, 10.0, ~4.242, 12.0 ] ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. From 7fb5d2c815b4797294fa1b480095fd2b2159ef82 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 13 Mar 2024 20:03:47 -0700 Subject: [PATCH 11/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 87ae8fd014a3..0667ac206cca 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -122,7 +122,7 @@ 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 rotation for every other value in `x` starting from second value,..., +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 rotation to every other value in `x` starting from second value, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -169,7 +169,7 @@ console.log( x ); var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); -// Applies a plane rotation : +// Apply a plane rotation : drot( x.length, x, 1, y, 1, 0.707, 0.707 ); console.log( x ); console.log( y ); From fec516f46dba7ddeb86efc27fb48d0e4f9140511 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 13 Mar 2024 20:05:25 -0700 Subject: [PATCH 12/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index 0667ac206cca..b6fcdd46ab5b 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -183,12 +183,6 @@ console.log( y ); @@ -205,12 +199,6 @@ console.log( y ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray - - -[@stdlib/blas/drot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/drot - - -
From fd7978d36b9d49ffc99f7bfc52f7df758407d3c5 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 14 Mar 2024 21:40:52 +0530 Subject: [PATCH 13/27] chore: apply review changes --- .../@stdlib/blas/base/drot/README.md | 24 +- .../@stdlib/blas/base/drot/docs/repl.txt | 41 +- .../blas/base/drot/docs/types/index.d.ts | 32 +- .../@stdlib/blas/base/drot/lib/drot.js | 43 +- .../@stdlib/blas/base/drot/lib/index.js | 10 +- .../@stdlib/blas/base/drot/lib/ndarray.js | 26 +- .../@stdlib/blas/base/drot/package.json | 19 +- .../@stdlib/blas/base/drot/test/test.drot.js | 401 +++++++++++--- .../blas/base/drot/test/test.ndarray.js | 503 ++++++++++++++---- 9 files changed, 838 insertions(+), 261 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index b6fcdd46ab5b..bac83d3905df 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -54,9 +54,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); -drot( x.length, x, 1, y, 1, 1.0, 0.0 ); -// x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -// y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +drot( x.length, x, 1, y, 1, 0.8, 0.6 ); +// x => [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] +// y => [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] ``` The function has the following parameters: @@ -69,7 +69,7 @@ The function has the following parameters: - **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 plane rotation to elements in the strided arrays in reverse order +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply plane rotation to elements skipping every alternate element, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -98,8 +98,8 @@ var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element drot( 3, x1, -2, y1, 1, 0.707, 0.707 ); -// x0 => [ 1.0, 9.898, 3.0, 10.604999999999999, 5.0, 11.312 ] -// y0 => [ 7.0, 8.0, 9.0, 2.8279999999999994, 4.949, 7.07 ] +// x0 => [ 1.0, 9.898, 3.0, ~10.605, 5.0, 11.312 ] +// y0 => [ 7.0, 8.0, 9.0, ~2.828, 4.949, 7.07 ] ``` #### drot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) @@ -112,9 +112,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); -drot.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 0.0 ); -// x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -// y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +// x => [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] +// y => [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] ``` The function has the following additional parameters: @@ -130,9 +130,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); -// x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] -// y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] +drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); +// x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] +// y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] ```
diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index d7944f0acc46..1837f09b7692 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, x, strideX, y, strideY, c, s ) Applies a plane rotation. - The `N` and stride parameters determine how values - from `x` and `y` are rotated. + The `N` and stride parameters determine how values in the strided arrays are + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -27,11 +27,11 @@ strideY: integer Index increment for `y`. - c: float - Cosine of angle for rotation. + c: number + Cosine of the angle of rotation. - s: float - Sin of angle for rotation. + s: number + Sine of the angle of rotation. Returns ------- @@ -43,14 +43,20 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}( x.length, x, 1, y, 1, 1.0, 0.0 ) - [ 6.0, 7.0, 8.0, 9.0, 10.0 ] + > {{alias}}( x.length, x, 1, y, 1, 0.8, 0.6 ) + > x + [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] + > y + [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); > {{alias}}( 2, x, -1, y, 2, 0.707, 0.707 ) - [ 2.8280000000000003, 7.0, 4.949, 9.0, 10.0 ] + > x + [ ~6.363, 5.656, 3.0, 4.0, 5.0 ] + > y + [ ~2.828, 7.0, 4.949, 9.0, 10.0 ] {{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) @@ -84,10 +90,10 @@ Starting index for `y`. c: float - Cosine of angle for rotation. + Cosine of the angle of rotation. s: float - Sin of angle for rotation. + Sine of the angle of rotation. Returns ------- @@ -99,14 +105,19 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0, 1.0, 0.0 ) - [ 6.0, 7.0, 8.0, 9.0, 10.0 ] + > {{alias}}.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ) + > x + [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] + [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > {{alias}}.ndarray( 4, x, 1, 5, y, -5, 2, 0.707, 0.707 ) - [ 7.0, 8.0, 2.1209999999999996, 10.0, 11.0, 12.0 ] + > {{alias}}.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ) + > x + [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] + > y + [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts index 581eb35c8cf0..93c7f0654a08 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -30,8 +30,8 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length - * @param c - double precision floating-point number - * @param s - double precision floating-point number + * @param c - cosine of the angle of rotation + * @param s - sine of the angle of rotation * @returns `y` * * @example @@ -41,8 +41,8 @@ interface Routine { * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); - * // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] - * // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] + * // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] + * // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] */ ( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number, c: number, s: number ): Float64Array; @@ -56,8 +56,8 @@ interface Routine { * @param y - second input array * @param strideY - `y` stride length * @param offsetY - starting index for `y` - * @param c - double precision floating-point number - * @param s - double precision floating-point number + * @param c - cosine of the angle of rotation + * @param s - sine of the angle of rotation * @returns `y` * * @example @@ -67,8 +67,8 @@ interface Routine { * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * * drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); - * // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] - * // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] + * // x => [ 1.0, 2.0, ~-2.998, 4.0, 5.0, 6.0 ] + * // y => [ 7.0, 8.0, ~-8.994, 10.0, 11.0, 12.0 ] */ ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, c: number, s: number ): Float64Array; } @@ -81,8 +81,8 @@ interface Routine { * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length -* @param c - double precision floating-point number -* @param s - double precision floating-point number +* @param c - cosine of the angle of rotation +* @param s - sine of the angle of rotation * @returns `y` * * @example @@ -91,9 +91,9 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 1, y, 1, 1.0, 0.0 ); -* // x => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -* // y => [ 6.0, 7.0, 8.0, 9.0, 10.0 ] +* drot( x.length, x, 1, y, 1, 0.8, 0.6 ); +* // x => [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] +* // y => [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -101,9 +101,9 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * -* drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); -* // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] -* // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] +* drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); +* // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] +* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] */ declare var drot: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index 1a4b2ef72b2b..80dccf1d5f47 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -28,8 +28,8 @@ * @param {integer} strideX - `x` stride length * @param {Float64Array} y - second input array * @param {integer} strideY - `y` stride length -* @param {number} c - double-precision floating-point number -* @param {number} s - double-precision floating-point number +* @param {number} c - cosine of the angle of rotation +* @param {number} s - sine of the angle of rotation * @returns {Float64Array} `y` * * @example @@ -39,8 +39,8 @@ * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] -* // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] +* // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] +* // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] */ function drot( N, x, strideX, y, strideY, c, s ) { var tmp; @@ -58,27 +58,26 @@ function drot( N, x, strideX, y, strideY, c, s ) { y[ i ] = ( c * y[ i ] ) - ( s * x[ i ] ); x[ i ] = tmp; } + return y; } // If both strides are not equal to `1`... - else { - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - 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; - } + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + 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; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index 05d591735575..3f26bf411b55 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -31,8 +31,8 @@ * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ 4.949, 6.3629999999999995, 7.776999999999999, 9.190999999999999, 10.604999999999999 ] -* // y => [ 3.535, 3.535, 3.5349999999999997, 3.5349999999999997, 3.5349999999999997 ] +* // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] +* // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -41,9 +41,9 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( 2, x, 2, y, 1, 0.707, 0.707 ); -* // x => [ 4.949, 2.0, 7.07, 4.0, 5.0 ] -* // y => [ 3.535, 2.828, 8.0, 9.0, 10.0 ] +* drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +* // x => [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] +* // y => [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index 4a1bcd8774a5..9683ed9b29a5 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -30,8 +30,8 @@ * @param {Float64Array} y - second input array * @param {integer} strideY - `y` stride length * @param {NonNegativeInteger} offsetY - starting `y` index -* @param {number} c - double-precision floating-point number -* @param {number} s - double-precision floating-point number +* @param {number} c - cosine of the angle of rotation +* @param {number} s - sine of the angle of rotation * @returns {Float64Array} `y` * * @example @@ -39,11 +39,10 @@ * * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -* var N = 4; * -* drot( N, x, 0, 2, y, 0, 2, 0.707, 0.707 ); -* // x => [ 1.0, 2.0, -2.998188273612, 4.0, 5.0, 6.0 ] -* // y => [ 7.0, 8.0, -8.994564820835999, 10.0, 11.0, 12.0 ] +* drot( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); +* // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] +* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] */ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var tmp; @@ -65,17 +64,16 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { ix += strideX; iy += strideY; } + return y; } // If both strides are not equal to `1`... - else { - 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; - } + 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; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/package.json b/lib/node_modules/@stdlib/blas/base/drot/package.json index 9868fafbb8b7..e7e855f44850 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/package.json +++ b/lib/node_modules/@stdlib/blas/base/drot/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/base/drot", "version": "0.0.0", - "description": "Applies a plane rotation.", + "description": "Apply a plane rotation.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,15 +14,11 @@ } ], "main": "./lib", - "browser": "./lib/main.js", - "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", - "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", @@ -59,20 +55,17 @@ "math", "blas", "level 1", + "drot", + "rotation", "linear", "algebra", "subroutines", - "drot", - "rotation", "vector", "array", "ndarray", "float64", + "float", "double", - "float64array", - "typed array" - ], - "__stdlib__": { - "wasm": false - } + "float64array" + ] } diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index 67656a24804f..a1aa1b0f3ed8 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -41,11 +41,9 @@ tape( 'the function has an arity of 7', function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation', function test( t ) { +tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', function test( t ) { var xexpected; var yexpected; - var ixvalues; - var iyvalues; var nvalues; var xvalues; var yvalues; @@ -57,7 +55,6 @@ tape( 'the function applies a plane rotation', function test( t ) { var ix; var iy; var c; - var i; var j; var k; var x; @@ -67,15 +64,234 @@ tape( 'the function applies a plane rotation', function test( t ) { [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -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 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ix = 1; + iy = 1; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 4.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 2 and y stride as -2', function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var ix; + var iy; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -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.020000000000000073], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ix = 2; + iy = -2; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 20.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -2 and y stride as 1', function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var ix; + var iy; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ -0.06000000000000005, 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.020000000000000073], + [ -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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ix = -2; + iy = 1; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 20.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -1 and y stride as -2', function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var ix; + var iy; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], @@ -83,26 +299,13 @@ tape( 'the function applies a plane rotation', function test( t ) { ]; yexpected = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.78, 0.54, 0.07999999999999996, -0.6, 0.2, 0.8 ], // eslint-disable-line max-len - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -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.28000000000000014 ], - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -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 ], - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16000000000000014 ] // eslint-disable-line max-len - + [ 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 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ixvalues = [ 1, 2, -2, -1 ]; - iyvalues = [ 1, -2, 1, -2 ]; + ix = -1; + iy = -2; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -112,38 +315,34 @@ tape( 'the function applies a plane rotation', function test( t ) { ]; c = 0; - for ( i = 0; i < ixvalues.length; i++ ) { - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - ix = ixvalues[ i ]; - iy = iyvalues[ i ]; - out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 1.5 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 1.5 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 1.5 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 4.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } } @@ -184,11 +383,13 @@ tape( 'the function supports an `x` stride', function test( t ) { }); tape( 'the function supports a `y` stride', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -204,15 +405,29 @@ tape( 'the function supports a `y` stride', function test( t ) { 9.0, 10.0 // 2 ]); - N = 2; - - drot( N, x, 1, y, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 4.949, 7.069999999999999, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); + drot( x.length, x, 2, y, 2, 0.8, 0.6 ); - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 4.4, 2.0, 7.2, 4.0, 10.0 ] ); + ye = new Float64Array( [ 4.2, 7.0, 4.6, 9.0, 5.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); @@ -257,8 +472,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; var N; @@ -281,17 +499,35 @@ tape( 'the function supports negative strides', function test( t ) { drot( N, x, -1, y, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, 5.656, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 2.8280000000000003, 7.0, 4.949, 9.0, 10.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 6.363, 5.656, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 2.828, 7.0, 4.949, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; var N; @@ -316,10 +552,25 @@ tape( 'the function supports complex access patterns', function test( t ) { drot( N, x, 2, y, -1, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, 2.0, 7.07, 4.0, 5.0, 6.0 ] ); + xe = new Float64Array( [ 6.363, 2.0, 7.07, 4.0, 5.0, 6.0 ] ); ye = new Float64Array( [ 2.828, 4.949, 9.0, 10.0, 11.0, 12.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index c6919e2c42a1..442d4c41b65d 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -41,11 +41,11 @@ tape( 'the function has an arity of 9', function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation', function test( t ) { +tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', function test( t ) { var xexpected; var yexpected; - var ixvalues; - var iyvalues; + var ixvalue; + var iyvalue; var nvalues; var xoffset; var xvalues; @@ -57,7 +57,6 @@ tape( 'the function applies a plane rotation', function test( t ) { var ex; var ey; var c; - var i; var j; var k; var x; @@ -67,15 +66,270 @@ tape( 'the function applies a plane rotation', function test( t ) { [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -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 ], + [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = 1; + iyvalue = 1; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = ( 1 - nvalues[ j ] ) * ixvalue; + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = ( 1 - nvalues[ j ] ) * iyvalue; + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 4.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 2 and y stride as -2', function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -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.020000000000000073], + [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = 2; + iyvalue = -2; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = ( 1 - nvalues[ j ] ) * ixvalue; + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = ( 1 - nvalues[ j ] ) * iyvalue; + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 20.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -2 and y stride as 1', function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ -0.06000000000000005, 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.020000000000000073], + [ -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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = -2; + iyvalue = 1; + + xvalues = [ + [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = ( 1 - nvalues[ j ] ) * ixvalue; + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = ( 1 - nvalues[ j ] ) * iyvalue; + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 20.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -1 and y stride as -2', function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ], @@ -83,26 +337,13 @@ tape( 'the function applies a plane rotation', function test( t ) { ]; yexpected = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.78, 0.54, 0.07999999999999996, -0.6, 0.2, 0.8 ], // eslint-disable-line max-len - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -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.28000000000000014 ], - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -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 ], - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ], - [ 0.040000000000000036, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16000000000000014 ] // eslint-disable-line max-len - + [ 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 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ixvalues = [ 1, 2, -2, -1 ]; - iyvalues = [ 1, -2, 1, -2 ]; + ixvalue = -1; + iyvalue = -2; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -112,46 +353,44 @@ tape( 'the function applies a plane rotation', function test( t ) { ]; c = 0; - for ( i = 0; i < ixvalues.length; i++ ) { - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalues[ i ] < 0 ) { - xoffset = ( 1 - nvalues[ j ] ) * ixvalues[ i ]; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = ( 1 - nvalues[ j ] ) * ixvalue; + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = ( 1 - nvalues[ j ] ) * iyvalue; + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); } else { - xoffset = 0; + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( iyvalues[ i ] < 0 ) { - yoffset = ( 1 - nvalues[ j ] ) * iyvalues[ i ]; + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); } else { - yoffset = 0; + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - out = drot( nvalues[ j ], x, ixvalues[ i ], xoffset, y, iyvalues[ i ], yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 1.5 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 1.5 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 1.5 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + if ( out[ k ] === y[ k ] ) { + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } else { + delta = abs( out[ k ] - y[ k ] ); + tol = 4.0 * EPS * abs( y[ k ] ); + t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } } @@ -190,8 +429,11 @@ tape( 'the function supports an `x` stride', function test( t ) { }); tape( 'the function supports an `x` offset', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -212,17 +454,35 @@ tape( 'the function supports an `x` offset', function test( t ) { drot( 2, x, 2, 2, y, 1, 0, 0.707, 0.707 ); - xe = new Float64Array( [ 1.0, 2.0, 6.3629999999999995, 4.0, 8.484 ] ); - ye = new Float64Array( [ 2.121, 1.4140000000000001, 8.0, 9.0, 10.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 1.0, 2.0, 6.363, 4.0, 8.484 ] ); + ye = new Float64Array( [ 2.121, 1.414, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); tape( 'the function supports a `y` stride', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -243,17 +503,35 @@ tape( 'the function supports a `y` stride', function test( t ) { drot( 2, x, 1, 0, y, 2, 0, 0.707, 0.707 ); - xe = new Float64Array( [ 4.949, 7.069999999999999, 3.0, 4.0, 5.0 ] ); + xe = new Float64Array( [ 4.949, 7.07, 3.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); tape( 'the function supports a `y` offset', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -274,15 +552,26 @@ tape( 'the function supports a `y` offset', function test( t ) { drot( 2, x, 1, 0, y, 1, 2, 0.707, 0.707 ); - xe = new Float64Array( [ 6.3629999999999995, - 7.776999999999999, - 3.0, - 4.0, - 5.0 ] ); + xe = new Float64Array( [ 6.363, 7.777, 3.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 6.0, 7.0, 4.949, 4.949, 10.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); @@ -327,8 +616,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -349,17 +641,35 @@ tape( 'the function supports negative strides', function test( t ) { drot( 3, x, -2, 4, y, -1, 3, 0.707, 0.707 ); - xe = new Float64Array( [ 5.656, 2.0, 7.776999999999999, 4.0, 9.898 ] ); - ye = new Float64Array( [ 6, 4.242, 3.5349999999999997, 2.828, 10 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 5.656, 2.0, 7.777, 4.0, 9.898 ] ); + ye = new Float64Array( [ 6, 4.242, 3.535, 2.828, 10 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); tape( 'the function supports complex access patterns', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -382,10 +692,25 @@ tape( 'the function supports complex access patterns', function test( t ) { drot( 3, x, 2, 1, y, -1, 5, 0.707, 0.707 ); - xe = new Float64Array( [ 1.0, 9.898, 3.0, 10.604999999999999, 5.0, 11.312 ] ); // eslint-disable-line max-len - ye = new Float64Array( [ 7.0, 8.0, 9.0, 2.8279999999999994, 4.949, 7.07 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 1.0, 9.898, 3.0, 10.605, 5.0, 11.312 ] ); + ye = new Float64Array( [ 7.0, 8.0, 9.0, 2.828, 4.949, 7.07 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); From 639ea83025e19afddb180f733d976dd7c509d121 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Thu, 14 Mar 2024 22:55:57 +0530 Subject: [PATCH 14/27] chore: apply review changes --- lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 1837f09b7692..baa591549e1b 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -45,9 +45,9 @@ > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); > {{alias}}( x.length, x, 1, y, 1, 0.8, 0.6 ) > x - [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] + [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] > y - [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] + [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); @@ -107,8 +107,8 @@ > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); > {{alias}}.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ) > x - [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] - [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] + [ 1.0, ~5.80, 7.2, 8.6, 10.0 ] + [ 6.0, 4.4, ~4.600, ~4.80, 5.0 ] // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); @@ -117,7 +117,7 @@ > x [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] > y - [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] + [ 7.0, 8.0, 5.4, 10.0, ~5.80, 12.0 ] See Also -------- From e18d1838dd5bbf30a37dd0ba73f0fa95b266294e Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 15 Mar 2024 01:04:38 +0530 Subject: [PATCH 15/27] chore: apply review changes --- .../@stdlib/blas/base/drot/docs/repl.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index baa591549e1b..0271247d39db 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -58,6 +58,17 @@ > y [ ~2.828, 7.0, 4.949, 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. @@ -89,10 +100,10 @@ offsetY: integer Starting index for `y`. - c: float + c: number Cosine of the angle of rotation. - s: float + s: number Sine of the angle of rotation. Returns From 4cf3434ada4f35fcd012d8bc14aadb7f5d80dc0d Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 15 Mar 2024 03:09:44 -0700 Subject: [PATCH 16/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/lib/drot.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index 80dccf1d5f47..c97db7f431ed 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -47,10 +47,10 @@ function drot( N, x, strideX, y, strideY, c, s ) { var ix; var iy; var i; + if ( N <= 0 ) { return y; } - // If both strides are equal to `1`... if ( strideX === 1 && strideY === 1 ) { for ( i = 0; i < N; i++ ) { @@ -60,7 +60,6 @@ function drot( N, x, strideX, y, strideY, c, s ) { } return y; } - // If both strides are not equal to `1`... if ( strideX < 0 ) { ix = ( 1 - N ) * strideX; From 1f34b38b577e11f41ab615112a6fd4f85f6a51b8 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 15 Mar 2024 03:12:34 -0700 Subject: [PATCH 17/27] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index 9683ed9b29a5..6c4c4eb81e46 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -49,6 +49,7 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var ix; var iy; var i; + if ( N <= 0 ) { return y; } @@ -56,7 +57,7 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { iy = offsetY; // If both strides are equal to `1`... - if (strideX === 1 && strideY === 1 ) { + if ( strideX === 1 && strideY === 1 ) { for ( i = 0; i < N; i++ ) { tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); @@ -66,7 +67,6 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { } return y; } - // If both strides are not equal to `1`... for ( i = 0; i < N; i++ ) { tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); From bd544ea9c354d5da9e3371afde4dc59278a99e8e Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sat, 16 Mar 2024 00:48:09 +0530 Subject: [PATCH 18/27] chore: apply review changes --- .../@stdlib/blas/base/drot/README.md | 26 +++++++++---------- .../@stdlib/blas/base/drot/docs/repl.txt | 20 +++++++------- .../blas/base/drot/docs/types/index.d.ts | 22 ++++++++-------- .../@stdlib/blas/base/drot/lib/drot.js | 6 ++--- .../@stdlib/blas/base/drot/lib/index.js | 10 +++---- .../@stdlib/blas/base/drot/lib/ndarray.js | 10 +++---- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index bac83d3905df..dee4c1cf59b0 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -55,8 +55,8 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); drot( x.length, x, 1, y, 1, 0.8, 0.6 ); -// x => [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] -// y => [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] +// 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: @@ -69,7 +69,7 @@ The function has the following parameters: - **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 plane rotation to elements skipping every alternate element, +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 Float64Array = require( '@stdlib/array/float64' ); @@ -78,8 +78,8 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); drot( x.length, x, 2, y, 2, 0.707, 0.707 ); -// x => [ 5.656, 2.0, 8.484, 4.0, 11.312, 6.0 ] -// y => [ 4.242, 8.0, ~4.242, 10.0, ~4.242, 12.0 ] +// x => [ ~5.7, 2.0, ~8.5, 4.0, ~11.3, 6.0 ] +// y => [ ~4.2, 8.0, ~4.2, 10.0, ~4.2, 12.0 ] ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. @@ -97,9 +97,9 @@ var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); 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 -drot( 3, x1, -2, y1, 1, 0.707, 0.707 ); -// x0 => [ 1.0, 9.898, 3.0, ~10.605, 5.0, 11.312 ] -// y0 => [ 7.0, 8.0, 9.0, ~2.828, 4.949, 7.07 ] +drot( 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 ] ``` #### drot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) @@ -113,8 +113,8 @@ var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); -// x => [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] -// y => [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] +// 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: @@ -122,7 +122,7 @@ 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 rotation to every other value in `x` starting from second value, +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 second element, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -132,7 +132,7 @@ var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] -// y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] +// y => [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] ```
@@ -170,7 +170,7 @@ var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); // Apply a plane rotation : -drot( x.length, x, 1, y, 1, 0.707, 0.707 ); +drot( 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/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 0271247d39db..780dbd2e3ce9 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -43,7 +43,7 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}( x.length, x, 1, y, 1, 0.8, 0.6 ) + > {{alias}}( x.length, x, 1, y, 1, 0.8, 0.6 ); > x [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] > y @@ -52,18 +52,18 @@ // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}( 2, x, -1, y, 2, 0.707, 0.707 ) + > {{alias}}( 2, x, -1, y, 2, 0.707, 0.707 ); > x - [ ~6.363, 5.656, 3.0, 4.0, 5.0 ] + [ ~6.36, ~5.66, 3.0, 4.0, 5.0 ] > y - [ ~2.828, 7.0, 4.949, 9.0, 10.0 ] + [ ~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 ) + > {{alias}}( 3, x1, 1, y1, 1, 0.8, 0.6 ); > x0 [ 1.0, 7.6, 9.0, ~10.4, 5.0, 6.0 ] > y0 @@ -116,19 +116,19 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ) + > {{alias}}.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); > x - [ 1.0, ~5.80, 7.2, 8.6, 10.0 ] - [ 6.0, 4.4, ~4.600, ~4.80, 5.0 ] + [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] + [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > {{alias}}.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ) + > {{alias}}.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); > x [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] > y - [ 7.0, 8.0, 5.4, 10.0, ~5.80, 12.0 ] + [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts index 93c7f0654a08..b7ed9fde95e9 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -23,7 +23,7 @@ */ interface Routine { /** - * Applies plane rotation. + * Applies a plane rotation. * * @param N - number of indexed elements * @param x - first input array @@ -40,14 +40,14 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * - * drot( x.length, x, 1, y, 1, 0.707, 0.707 ); - * // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] - * // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] + * drot( 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: Float64Array, strideX: number, y: Float64Array, strideY: number, c: number, s: number ): Float64Array; /** - * Applies plane rotation. + * Applies a plane rotation. * * @param N - number of indexed elements * @param x - first input array @@ -67,14 +67,14 @@ interface Routine { * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * * drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); - * // x => [ 1.0, 2.0, ~-2.998, 4.0, 5.0, 6.0 ] - * // y => [ 7.0, 8.0, ~-8.994, 10.0, 11.0, 12.0 ] + * // 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 ] */ ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, c: number, s: number ): Float64Array; } /** -* Applies plane rotation. +* Applies a plane rotation. * * @param N - number of indexed elements * @param x - first input array @@ -92,8 +92,8 @@ interface Routine { * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot( x.length, x, 1, y, 1, 0.8, 0.6 ); -* // x => [ ~4.400, ~5.800, 7.2, 8.6, 10.0 ] -* // y => [ ~4.200, 4.4, 4.600, 4.800, 5.0 ] +* // x => [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, ~4.6, ~4.8, 5.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); @@ -103,7 +103,7 @@ interface Routine { * * drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); * // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] -* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] +* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] */ declare var drot: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index c97db7f431ed..dff0ec2c6ec9 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -38,9 +38,9 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] -* // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] +* drot( 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 ] */ function drot( N, x, strideX, y, strideY, c, s ) { var tmp; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index 3f26bf411b55..b21b288e5567 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -30,9 +30,9 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 1, y, 1, 0.707, 0.707 ); -* // x => [ 4.949, ~6.363, ~7.777, ~9.191, ~10.605 ] -* // y => [ 3.535, 3.535, ~3.535, ~3.535, ~3.535 ] +* drot( 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 Float64Array = require( '@stdlib/array/float64' ); @@ -42,8 +42,8 @@ * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * * drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); -* // x => [ 1.0, ~5.800, 7.2, 8.6, 10.0 ] -* // y => [ 6.0, 4.4, ~4.600, ~4.800, 5.0 ] +* // x => [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index 6c4c4eb81e46..dc20664a885f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -37,12 +37,12 @@ * @example * var Float64Array = require( '@stdlib/array/float64' ); * -* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); -* // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] -* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.800, 12.0 ] +* drot( x.length, 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 drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { var tmp; From 47361ef569dd66f7f4e6fc46ca2fa4459d87368d Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:14:45 +0530 Subject: [PATCH 19/27] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 780dbd2e3ce9..4e6ef046efdd 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -71,7 +71,7 @@ {{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) - Applies a plane rotation. + 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 From 21002f977d77aaed0bc8024bdda76517fec2aecf Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sun, 17 Mar 2024 14:22:50 +0530 Subject: [PATCH 20/27] chore: apply review changes --- .../@stdlib/blas/base/drot/README.md | 18 +++--- .../@stdlib/blas/base/drot/docs/repl.txt | 8 +-- .../blas/base/drot/docs/types/index.d.ts | 8 +-- .../@stdlib/blas/base/drot/examples/index.js | 2 +- .../@stdlib/blas/base/drot/lib/index.js | 2 +- .../@stdlib/blas/base/drot/lib/ndarray.js | 2 +- .../@stdlib/blas/base/drot/test/test.drot.js | 56 +++---------------- .../blas/base/drot/test/test.ndarray.js | 32 ++--------- 8 files changed, 32 insertions(+), 96 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index dee4c1cf59b0..382b60a2b575 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -77,9 +77,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -drot( x.length, x, 2, y, 2, 0.707, 0.707 ); -// x => [ ~5.7, 2.0, ~8.5, 4.0, ~11.3, 6.0 ] -// y => [ ~4.2, 8.0, ~4.2, 10.0, ~4.2, 12.0 ] +drot( 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. @@ -112,7 +112,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); -drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +drot.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 ] ``` @@ -122,7 +122,7 @@ 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 second element, +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 Float64Array = require( '@stdlib/array/float64' ); @@ -130,9 +130,9 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); -// x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] -// y => [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] +drot.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 ] ``` @@ -169,7 +169,7 @@ console.log( x ); var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); -// Apply a plane rotation : +// Apply a plane rotation: drot( 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/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 4e6ef046efdd..034181ac93de 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -116,7 +116,7 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); > var y = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - > {{alias}}.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); + > {{alias}}.ndarray( 4, x, 1, 1, y, 1, 1, 0.8, 0.6 ); > x [ 1.0, ~5.8, 7.2, 8.6, 10.0 ] [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] @@ -124,11 +124,11 @@ // Advanced Indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > {{alias}}.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); + > {{alias}}.ndarray( 3, x, 2, 1, y, 2, 1, 0.8, 0.6 ); > x - [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] + [ 1.0, 6.4, 3.0, 9.2, 5.0, 12.0 ] > y - [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] + [ 7.0, 5.2, 9.0, 5.6, 11.0, ~6.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts index b7ed9fde95e9..154a4eeea797 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -66,9 +66,9 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * - * drot.ndarray( 4, x, 0, 2, y, 0, 2, 0.707, 0.707 ); - * // 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 ] + * drot.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: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, c: number, s: number ): Float64Array; } @@ -101,7 +101,7 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * -* drot.ndarray( x.length, x, 2, 2, y, 2, 2, 0.8, 0.6 ); +* drot.ndarray( 2, x, 2, 2, y, 2, 2, 0.8, 0.6 ); * // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] * // y => [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js index 2e8fb4720818..7cf0d92dfa6e 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/index.js @@ -30,6 +30,6 @@ console.log( x ); var y = discreteUniform( x.length, 0, 255, opts ); console.log( y ); -drot( x.length, x, 1, y, 1, 0.707, 0.707 ); +drot( 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/drot/lib/index.js b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js index b21b288e5567..6478c46f7d34 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/index.js @@ -41,7 +41,7 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot.ndarray( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +* drot.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 ] */ diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index dc20664a885f..59c44bf6558b 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -40,7 +40,7 @@ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); * -* drot( x.length, x, 1, 1, y, 1, 1, 0.8, 0.6 ); +* drot( 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 ] */ diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index a1aa1b0f3ed8..ab51ec99cf89 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -52,8 +52,6 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as var out; var ex; var ey; - var ix; - var iy; var c; var j; var k; @@ -73,8 +71,6 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ix = 1; - iy = 1; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -87,7 +83,7 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as for ( j = 0; j < nvalues.length; j++ ) { x = new Float64Array( xvalues[ 0 ] ); y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + out = drot( nvalues[ j ], x, 1, y, 1, 0.8, 0.6 ); ex = new Float64Array( xexpected[ c ] ); ey = new Float64Array( yexpected[ c ] ); c += 1; @@ -106,13 +102,7 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as tol = 4.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 4.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -129,8 +119,6 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as var out; var ex; var ey; - var ix; - var iy; var c; var j; var k; @@ -150,8 +138,6 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ix = 2; - iy = -2; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -164,7 +150,7 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as for ( j = 0; j < nvalues.length; j++ ) { x = new Float64Array( xvalues[ 0 ] ); y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + out = drot( nvalues[ j ], x, 2, y, -2, 0.8, 0.6 ); ex = new Float64Array( xexpected[ c ] ); ey = new Float64Array( yexpected[ c ] ); c += 1; @@ -183,13 +169,7 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as tol = 20.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 20.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -206,8 +186,6 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as var out; var ex; var ey; - var ix; - var iy; var c; var j; var k; @@ -227,8 +205,6 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ix = -2; - iy = 1; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -241,7 +217,7 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as for ( j = 0; j < nvalues.length; j++ ) { x = new Float64Array( xvalues[ 0 ] ); y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + out = drot( nvalues[ j ], x, -2, y, 1, 0.8, 0.6 ); ex = new Float64Array( xexpected[ c ] ); ey = new Float64Array( yexpected[ c ] ); c += 1; @@ -260,13 +236,7 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as tol = 20.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 20.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -283,8 +253,6 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as var out; var ex; var ey; - var ix; - var iy; var c; var j; var k; @@ -304,8 +272,6 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] ]; nvalues = [ 0, 1, 2, 4 ]; - ix = -1; - iy = -2; xvalues = [ [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] @@ -318,7 +284,7 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as for ( j = 0; j < nvalues.length; j++ ) { x = new Float64Array( xvalues[ 0 ] ); y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, ix, y, iy, 0.8, 0.6 ); + out = drot( nvalues[ j ], x, -1, y, -2, 0.8, 0.6 ); ex = new Float64Array( xexpected[ c ] ); ey = new Float64Array( yexpected[ c ] ); c += 1; @@ -337,13 +303,7 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as tol = 4.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 4.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 442d4c41b65d..6185f595888b 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -118,13 +118,7 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as tol = 4.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 4.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -207,13 +201,7 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as tol = 20.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 20.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -296,13 +284,7 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as tol = 20.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 20.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); @@ -385,13 +367,7 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as tol = 4.0 * EPS * abs( ey[ k ] ); t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } - if ( out[ k ] === y[ k ] ) { - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } else { - delta = abs( out[ k ] - y[ k ] ); - tol = 4.0 * EPS * abs( y[ k ] ); - t.ok( delta <= tol, 'within tolerance. out: '+out[ k ]+'. expected: '+y[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); } } t.end(); From 3c73b2caa71ce4422bb62051f2d6cf6701e86e00 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 25 Mar 2024 22:00:49 +0530 Subject: [PATCH 21/27] chore: apply review changes --- .../@stdlib/blas/base/drot/test/test.drot.js | 153 +++++++++--------- .../blas/base/drot/test/test.ndarray.js | 98 ++++++----- 2 files changed, 134 insertions(+), 117 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index ab51ec99cf89..d92dfe39c0a4 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -310,44 +310,57 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as }); tape( 'the function supports an `x` stride', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 2.0, 3.0, // 1 4.0, - 5.0 // 2 + 5.0 ]); y = new Float64Array([ 6.0, // 0 7.0, // 1 - 8.0, // 2 + 8.0, 9.0, 10.0 ]); - N = 2; - drot( N, x, 2, y, 1, 0.707, 0.707 ); + drot( 2, x, 2, y, 1, 0.8, 0.6 ); - xe = new Float64Array( [ 4.949, 2.0, 7.07, 4.0, 5.0 ] ); - ye = new Float64Array( [ 3.535, 2.828, 8.0, 9.0, 10.0 ] ); - - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); tape( 'the function supports a `y` stride', function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -359,35 +372,19 @@ tape( 'the function supports a `y` stride', function test( t ) { 5.0 ]); y = new Float64Array([ - 6.0, // 0 - 7.0, - 8.0, // 1 - 9.0, - 10.0 // 2 + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 ]); - drot( x.length, x, 2, y, 2, 0.8, 0.6 ); + drot( 3, x, 1, y, 2, 0.0, -1.0 ); - xe = new Float64Array( [ 4.4, 2.0, 7.2, 4.0, 10.0 ] ); - ye = new Float64Array( [ 4.2, 7.0, 4.6, 9.0, 5.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 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(); }); @@ -420,11 +417,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav ye = new Float64Array( y.length ); dcopy( y.length, y, 1, ye, 1 ); - drot( -1, x, 1, y, 1, 0.707, 0.707 ); + drot( -1, x, 1, y, 1, 0.8, 0.6 ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); - drot( 0, x, 1, y, 1, 0.707, 0.707 ); + drot( 0, x, 1, y, 1, 0.8, 0.6 ); t.deepEqual( x, xe, 'returns expected value' ); t.deepEqual( y, ye, 'returns expected value' ); @@ -439,35 +436,37 @@ tape( 'the function supports negative strides', function test( t ) { var k; var x; var y; - var N; x = new Float64Array([ - 1.0, // 2 - 2.0, - 3.0, // 1 - 4.0, - 5.0 // 0 + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 ]); y = new Float64Array([ - 6.0, // 2 - 7.0, // 1 - 8.0, // 0 - 9.0, - 10.0 + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 ]); - N = 2; - drot( N, x, -1, y, 2, 0.707, 0.707 ); + drot( 4, x, -2, y, 1, 0.8, 0.6 ); - xe = new Float64Array( [ 6.363, 5.656, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 2.828, 7.0, 4.949, 9.0, 10.0 ] ); + xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); + ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); } else { delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); + tol = 20.0 * EPS * abs( xe[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } if ( y[ k ] === ye[ k ] ) { @@ -475,7 +474,7 @@ tape( 'the function supports negative strides', function test( t ) { } else { delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); + tol = 20.0 * EPS * abs( ye[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -490,37 +489,37 @@ tape( 'the function supports complex access patterns', function test( t ) { var k; var x; var y; - var N; x = new Float64Array([ - 1.0, // 0 - 2.0, - 3.0, // 1 - 4.0, - 5.0, // 2 - 6.0 + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 ]); y = new Float64Array([ - 7.0, // 2 - 8.0, // 1 - 9.0, // 0 - 10.0, - 11.0, - 12.0 + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 ]); - N = 2; - drot( N, x, 2, y, -1, 0.707, 0.707 ); + drot( 2, x, -1, y, -2, 0.8, 0.6 ); - xe = new Float64Array( [ 6.363, 2.0, 7.07, 4.0, 5.0, 6.0 ] ); - ye = new Float64Array( [ 2.828, 4.949, 9.0, 10.0, 11.0, 12.0 ] ); + xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); } else { delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); + tol = 5.0 * EPS * abs( xe[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } if ( y[ k ] === ye[ k ] ) { @@ -528,7 +527,7 @@ tape( 'the function supports complex access patterns', function test( t ) { } else { delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); + tol = 5.0 * EPS * abs( ye[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 6185f595888b..230b53143407 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -374,8 +374,11 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as }); tape( 'the function supports an `x` stride', function test( t ) { + var delta; + var tol; var xe; var ye; + var k; var x; var y; @@ -384,27 +387,42 @@ tape( 'the function supports an `x` stride', function test( t ) { 2.0, 3.0, // 1 4.0, - 5.0 // 2 + 5.0 ]); y = new Float64Array([ 6.0, // 0 7.0, // 1 - 8.0, // 2 + 8.0, 9.0, 10.0 ]); - drot( 2, x, 2, 0, y, 1, 0, 0.707, 0.707 ); - - xe = new Float64Array( [ 4.949, 2.0, 7.07, 4.0, 5.0 ] ); - ye = new Float64Array( [ 3.535, 2.828, 8.0, 9.0, 10.0 ] ); + drot( 2, x, 2, 0, y, 1, 0, 0.8, 0.6 ); - t.deepEqual( x, xe, 'returns expected value' ); - t.deepEqual( y, ye, 'returns expected value' ); + xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); -tape( 'the function supports an `x` offset', function test( t ) { +tape( 'the function supports a `x` offset', function test( t ) { var delta; var tol; var xe; @@ -415,30 +433,30 @@ tape( 'the function supports an `x` offset', function test( t ) { x = new Float64Array([ 1.0, - 2.0, - 3.0, // 0 - 4.0, // 1 - 5.0 // 2 + 2.0, // 0 + 3.0, // 1 + 4.0, + 5.0 ]); y = new Float64Array([ 6.0, // 0 7.0, // 1 - 8.0, // 2 + 8.0, 9.0, 10.0 ]); - drot( 2, x, 2, 2, y, 1, 0, 0.707, 0.707 ); + drot( 2, x, 1, 1, y, 1, 0, 0.8, 0.6 ); - xe = new Float64Array( [ 1.0, 2.0, 6.363, 4.0, 8.484 ] ); - ye = new Float64Array( [ 2.121, 1.414, 8.0, 9.0, 10.0 ] ); + xe = new Float64Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); } else { delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } if ( y[ k ] === ye[ k ] ) { @@ -446,7 +464,7 @@ tape( 'the function supports an `x` offset', function test( t ) { } else { delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -470,17 +488,17 @@ tape( 'the function supports a `y` stride', function test( t ) { 5.0 ]); y = new Float64Array([ - 6.0, // 0 - 7.0, - 8.0, // 1 - 9.0, - 10.0 // 2 + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 ]); - drot( 2, x, 1, 0, y, 2, 0, 0.707, 0.707 ); + drot( 3, x, 1, 0, y, 2, 0, 0.0, -1.0 ); - xe = new Float64Array( [ 4.949, 7.07, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 3.535, 7.0, 4.242, 9.0, 10.0 ] ); + xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); @@ -514,7 +532,7 @@ tape( 'the function supports a `y` offset', function test( t ) { x = new Float64Array([ 1.0, // 0 2.0, // 1 - 3.0, // 2 + 3.0, 4.0, 5.0 ]); @@ -523,13 +541,13 @@ tape( 'the function supports a `y` offset', function test( t ) { 7.0, 8.0, // 0 9.0, // 1 - 10.0 // 2 + 10.0 ]); - drot( 2, x, 1, 0, y, 1, 2, 0.707, 0.707 ); + drot( 2, x, 1, 0, y, 1, 2, 0.8, 0.6 ); - xe = new Float64Array( [ 6.363, 7.777, 3.0, 4.0, 5.0 ] ); - ye = new Float64Array( [ 6.0, 7.0, 4.949, 4.949, 10.0 ] ); + xe = new Float64Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); @@ -580,11 +598,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav ye = new Float64Array( y.length ); dcopy( y.length, y, 1, 0, ye, 1, 0 ); - drot( -1, x, 1, 0, y, 1, 0, 0.707, 0.707 ); + drot( -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' ); - drot( 0, x, 1, 0, y, 1, 0, 0.707, 0.707 ); + drot( 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' ); @@ -615,10 +633,10 @@ tape( 'the function supports negative strides', function test( t ) { 10.0 ]); - drot( 3, x, -2, 4, y, -1, 3, 0.707, 0.707 ); + drot( 3, x, -2, 4, y, -1, 3, 0.8, 0.6 ); - xe = new Float64Array( [ 5.656, 2.0, 7.777, 4.0, 9.898 ] ); - ye = new Float64Array( [ 6, 4.242, 3.535, 2.828, 10 ] ); + xe = new Float64Array( [ 5.0, 2.0, 7.2, 4.0, 9.4 ] ); + ye = new Float64Array( [ 6, 5.0, 4.6, 4.2, 10.0 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); @@ -666,10 +684,10 @@ tape( 'the function supports complex access patterns', function test( t ) { 12.0 // 0 ]); - drot( 3, x, 2, 1, y, -1, 5, 0.707, 0.707 ); + drot( 3, x, 2, 1, y, -1, 5, 0.8, 0.6 ); - xe = new Float64Array( [ 1.0, 9.898, 3.0, 10.605, 5.0, 11.312 ] ); - ye = new Float64Array( [ 7.0, 8.0, 9.0, 2.828, 4.949, 7.07 ] ); + xe = new Float64Array( [ 1.0, 8.8, 3.0, 9.8, 5.0, 10.8 ] ); + ye = new Float64Array( [ 7.0, 8.0, 9.0, 4.4, 6.4, 8.4 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); From e0058880147e68df9ce7c863977099abf8491d44 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 26 Mar 2024 14:02:15 +0530 Subject: [PATCH 22/27] chore: apply review changes --- .../@stdlib/blas/base/drot/test/test.drot.js | 24 ++--- .../blas/base/drot/test/test.ndarray.js | 94 ++++++++++--------- 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index d92dfe39c0a4..f6862d6675ba 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -59,8 +59,8 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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 ] ]; @@ -73,7 +73,7 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as nvalues = [ 0, 1, 2, 4 ]; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -126,8 +126,8 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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] ]; @@ -140,7 +140,7 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as nvalues = [ 0, 1, 2, 4 ]; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -193,8 +193,8 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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] ]; @@ -207,7 +207,7 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as nvalues = [ 0, 1, 2, 4 ]; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -260,8 +260,8 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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 ] ]; @@ -274,7 +274,7 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as nvalues = [ 0, 1, 2, 4 ]; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 230b53143407..aae456bd6d6a 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -63,8 +63,8 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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 ] ]; @@ -79,7 +79,7 @@ tape( 'the function applies a plane rotation with x stride as 1 and y stride as iyvalue = 1; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -146,8 +146,8 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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] ]; @@ -162,7 +162,7 @@ tape( 'the function applies a plane rotation with x stride as 2 and y stride as iyvalue = -2; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -229,8 +229,8 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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] ]; @@ -245,7 +245,7 @@ tape( 'the function applies a plane rotation with x stride as -2 and y stride as iyvalue = 1; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -312,8 +312,8 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as var y; xexpected = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], - [ 0.78, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ], + [ 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 ] ]; @@ -328,7 +328,7 @@ tape( 'the function applies a plane rotation with x stride as -1 and y stride as iyvalue = -2; xvalues = [ - [ 0.6, 0.10, -0.5, 0.8, 0.9, -0.3, -0.4 ] + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ]; yvalues = [ [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] @@ -619,31 +619,35 @@ tape( 'the function supports negative strides', function test( t ) { var y; x = new Float64Array([ - 1.0, // 2 - 2.0, - 3.0, // 1 - 4.0, - 5.0 // 0 + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 ]); y = new Float64Array([ - 6.0, - 7.0, // 2 - 8.0, // 1 - 9.0, // 0 - 10.0 + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 ]); - drot( 3, x, -2, 4, y, -1, 3, 0.8, 0.6 ); + drot( 4, x, -2, 6, y, 1, 0, 0.8, 0.6 ); - xe = new Float64Array( [ 5.0, 2.0, 7.2, 4.0, 9.4 ] ); - ye = new Float64Array( [ 6, 5.0, 4.6, 4.2, 10.0 ] ); + xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); + ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); } else { delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); + tol = 20.0 * EPS * abs( xe[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } if ( y[ k ] === ye[ k ] ) { @@ -651,7 +655,7 @@ tape( 'the function supports negative strides', function test( t ) { } else { delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); + tol = 20.0 * EPS * abs( ye[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -668,33 +672,35 @@ tape( 'the function supports complex access patterns', function test( t ) { var y; x = new Float64Array([ - 1.0, - 2.0, // 0 - 3.0, - 4.0, // 1 - 5.0, - 6.0 // 2 + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 ]); y = new Float64Array([ - 7.0, - 8.0, - 9.0, - 10.0, // 2 - 11.0, // 1 - 12.0 // 0 + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 ]); - drot( 3, x, 2, 1, y, -1, 5, 0.8, 0.6 ); + drot( 2, x, -1, 1, y, -2, 2, 0.8, 0.6 ); - xe = new Float64Array( [ 1.0, 8.8, 3.0, 9.8, 5.0, 10.8 ] ); - ye = new Float64Array( [ 7.0, 8.0, 9.0, 4.4, 6.4, 8.4 ] ); + xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); for ( k = 0; k < xe.length; k++ ) { if ( x[ k ] === xe[ k ] ) { t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); } else { delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); + tol = 5.0 * EPS * abs( xe[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } if ( y[ k ] === ye[ k ] ) { @@ -702,7 +708,7 @@ tape( 'the function supports complex access patterns', function test( t ) { } else { delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); + tol = 5.0 * EPS * abs( ye[ k ] ); t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); } } From 23b03d16dad07a15afc1b6985f7fecd8bebfa3c4 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 12 Apr 2024 13:42:34 +0530 Subject: [PATCH 23/27] feat: add C / Fortran implementation for drot --- .../base/drot/benchmark/benchmark.native.js | 108 +++ .../benchmark/benchmark.ndarray.native.js | 108 +++ .../blas/base/drot/benchmark/c/Makefile | 129 ++++ .../base/drot/benchmark/c/benchmark.length.c | 154 ++++ .../blas/base/drot/benchmark/fortran/Makefile | 141 ++++ .../drot/benchmark/fortran/benchmark.length.f | 216 ++++++ .../@stdlib/blas/base/drot/binding.gyp | 265 +++++++ .../blas/base/drot/examples/c/Makefile | 129 ++++ .../blas/base/drot/examples/c/example.c | 45 ++ .../@stdlib/blas/base/drot/include.gypi | 70 ++ .../base/drot/include/stdlib/blas/base/drot.h | 41 + .../include/stdlib/blas/base/drot_cblas.h | 41 + .../include/stdlib/blas/base/drot_fortran.h | 41 + .../@stdlib/blas/base/drot/lib/drot.native.js | 58 ++ .../@stdlib/blas/base/drot/lib/native.js | 35 + .../blas/base/drot/lib/ndarray.native.js | 71 ++ .../@stdlib/blas/base/drot/manifest.json | 175 +++++ .../@stdlib/blas/base/drot/package.json | 4 + .../@stdlib/blas/base/drot/src/Makefile | 70 ++ .../@stdlib/blas/base/drot/src/addon.c | 48 ++ .../@stdlib/blas/base/drot/src/drot.c | 69 ++ .../@stdlib/blas/base/drot/src/drot.f | 97 +++ .../@stdlib/blas/base/drot/src/drot_cblas.c | 35 + .../@stdlib/blas/base/drot/src/drot_f.c | 35 + .../blas/base/drot/test/test.drot.native.js | 544 +++++++++++++ .../blas/base/drot/test/test.ndarray.js | 2 +- .../base/drot/test/test.ndarray.native.js | 726 ++++++++++++++++++ 27 files changed, 3456 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/drot/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h create mode 100644 lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/drot.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/drot.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/drot.f create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.native.js new file mode 100644 index 000000000000..2cebd15c3109 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.native.js @@ -0,0 +1,108 @@ +/** +* @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 resolve = require( 'path' ).resolve; +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 tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drot = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( drot instanceof Error ) +}; +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 = drot( 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+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..e7df95c774e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,108 @@ +/** +* @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 resolve = require( 'path' ).resolve; +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 tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( drot instanceof Error ) +}; +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 = drot( 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+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile new file mode 100644 index 000000000000..e69377585860 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile @@ -0,0 +1,129 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of source files: +c_src := ../../src/drot.c + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..391ebf4b9df2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c @@ -0,0 +1,154 @@ +/** +* @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. +*/ + +/** +* Benchmark `drot`. +*/ +#include "stdlib/blas/base/drot.h" +#include +#include +#include +#include +#include + +#define NAME "drot" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1]. +* +* @return random number +*/ +double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +double benchmark( int iterations, int len ) { + double elapsed; + double x[ len ]; + double y[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + y[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_drot( len, x, 1, y, 1, 0.8, 0.6 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile new file mode 100644 index 000000000000..9f0a6311a8e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile @@ -0,0 +1,141 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling Fortran source files: +ifdef FORTRAN_COMPILER + FC := $(FORTRAN_COMPILER) +else + FC := gfortran +endif + +# Define the command-line options when compiling Fortran files: +FFLAGS ?= \ + -std=f95 \ + -ffree-form \ + -O3 \ + -Wall \ + -Wextra \ + -Wno-compare-reals \ + -Wimplicit-interface \ + -fno-underscoring \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop`): +INCLUDE ?= + +# List of Fortran source files: +SOURCE_FILES ?= ../../src/drot.f + +# List of Fortran targets: +f_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles Fortran source files. +# +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} [FORTRAN_COMPILER] - Fortran compiler +# @param {string} [FFLAGS] - Fortran compiler flags +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code +# +# @example +# make +# +# @example +# make all +#/ +all: $(f_targets) + +.PHONY: all + +#/ +# Compiles Fortran source files. +# +# @private +# @param {string} SOURCE_FILES - list of Fortran source files +# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) +# @param {string} FC - Fortran compiler +# @param {string} FFLAGS - Fortran compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(f_targets): %.out: %.f + $(QUIET) $(FC) $(FFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(f_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/benchmark.length.f new file mode 100644 index 000000000000..c78c9e0f6ee0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/benchmark.length.f @@ -0,0 +1,216 @@ +!> +! @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. +!< + +!> Benchmark `drot`. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(4), parameter :: name = 'drot' ! if changed, be sure to adjust length + integer, parameter :: iterations = 10000000 + integer, parameter :: repeats = 3 + integer, parameter :: min = 1 + integer, parameter :: max = 6 + ! .. + ! Run the benchmarks: + call main() + ! .. + ! Functions: +contains + ! .. + ! Prints the TAP version. + ! .. + subroutine print_version() + print '(A)', 'TAP version 13' + end subroutine print_version + ! .. + ! Prints the TAP summary. + ! + ! @param {integer} total - total number of tests + ! @param {integer} passing - total number of passing tests + ! .. + subroutine print_summary( total, passing ) + ! .. + ! Scalar arguments: + integer, intent(in) :: total, passing + ! .. + ! Local variables: + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + print '(A)', '#' + ! .. + write (str, '(I15)') total ! TAP plan + tmp = adjustl( str ) + print '(A,A)', '1..', trim( tmp ) + ! .. + print '(A,A)', '# total ', trim( tmp ) + ! .. + write (str, '(I15)') passing + tmp = adjustl( str ) + print '(A,A)', '# pass ', trim( tmp ) + ! .. + print '(A)', '#' + print '(A)', '# ok' + end subroutine print_summary + ! .. + ! Prints benchmarks results. + ! + ! @param {integer} iterations - number of iterations + ! @param {double} elapsed - elapsed time in seconds + ! .. + subroutine print_results( iterations, elapsed ) + ! .. + ! Scalar arguments: + double precision, intent(in) :: elapsed + integer, intent(in) :: iterations + ! .. + ! Local variables: + double precision :: rate + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic dble, adjustl, trim + ! .. + rate = dble( iterations ) / elapsed + ! .. + print '(A)', ' ---' + ! .. + write (str, '(I15)') iterations + tmp = adjustl( str ) + print '(A,A)', ' iterations: ', trim( tmp ) + ! .. + write (str, '(f0.9)') elapsed + tmp = adjustl( str ) + print '(A,A)', ' elapsed: ', trim( tmp ) + ! .. + write( str, '(f0.9)') rate + tmp = adjustl( str ) + print '(A,A)', ' rate: ', trim( tmp ) + ! .. + print '(A)', ' ...' + end subroutine print_results + ! .. + ! Runs a benchmark. + ! + ! @param {integer} iterations - number of iterations + ! @param {integer} len - array length + ! @return {double} elapsed time in seconds + ! .. + double precision function benchmark( iterations, len ) + ! .. + ! External functions: + interface + subroutine drot( N, dx, strideX, dy, strideY, c, s ) + double precision :: dx(*), dy(*), c, s + integer :: strideX, strideY, N + end subroutine drot + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, len + ! .. + ! Local scalars: + double precision :: elapsed, r + real :: t1, t2 + integer :: i + ! .. + ! Local arrays: + double precision, allocatable :: x(:), y(:) + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time + ! .. + ! Allocate arrays: + allocate( x(len), y(len) ) + ! .. + do i = 1, len + call random_number( r ) + x( i ) = ( r*200.0d0 ) - 100.0d0 + y( i ) = ( r*200.0d0 ) - 100.0d0 + end do + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call drot( len, x, 1, y, 1, 0.8d0, 0.6d0 ); + if ( y( 1 ) /= y( 1 ) ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( y( 1 ) /= y( 1 ) ) then + print '(A)', 'should not return NaN' + end if + ! .. + ! Deallocate arrays: + deallocate( x, y ) + ! .. + benchmark = elapsed + return + end function benchmark + ! .. + ! Main execution sequence. + ! .. + subroutine main() + ! .. + ! Local variables: + integer :: count, iter, len, i, j + double precision :: elapsed + character(len=999) :: str, tmp + ! .. + ! Intrinsic functions: + intrinsic adjustl, trim + ! .. + call print_version() + count = 0 + do i = min, max + len = 10**i + iter = iterations / 10**(i-1) + do j = 1, repeats + count = count + 1 + ! .. + write (str, '(I15)') len + tmp = adjustl( str ) + print '(A,A,A,A)', '# fortran::', name, ':len=', trim( tmp ) + ! .. + elapsed = benchmark( iter, len ) + ! .. + call print_results( iter, elapsed ) + ! .. + write (str, '(I15)') count + tmp = adjustl( str ) + print '(A,A,A)', 'ok ', trim( tmp ), ' benchmark finished' + end do + end do + call print_summary( count, count ) + end subroutine main +end program bench \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/drot/binding.gyp b/lib/node_modules/@stdlib/blas/base/drot/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/binding.gyp @@ -0,0 +1,265 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile new file mode 100644 index 000000000000..44a5e0918c24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile @@ -0,0 +1,129 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of source files: +c_src := ../../src/drot.c + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c new file mode 100644 index 000000000000..72ccb4467425 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c @@ -0,0 +1,45 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/drot.h" +#include + +int main( void ) { + // Create strided arrays: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; + double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify stride lengths: + const int strideX = 1; + const int strideY = 1; + + // Specify angle of rotation: + const double c = 0.8; + const double s = 0.6; + + // Apply plane rotation: + c_drot( N, x, strideX, y, strideY, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/include.gypi b/lib/node_modules/@stdlib/blas/base/drot/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/include.gypi @@ -0,0 +1,70 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + ' [ ~4.4, ~5.8, 7.2, 8.6, 10.0 ] +* // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] +*/ +function drot( N, x, strideX, y, strideY, c, s ) { + addon( N, x, strideX, y, strideY, c, s ); + return y; +} + + +// EXPORTS // + +module.exports = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/native.js b/lib/node_modules/@stdlib/blas/base/drot/lib/native.js new file mode 100644 index 000000000000..d79684c109f6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/native.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'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var drot = require( './drot.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( drot, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js new file mode 100644 index 000000000000..fd2d583bb322 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js @@ -0,0 +1,71 @@ +/** +* @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 minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var offsetView = require( '@stdlib/strided/base/offset-view' ); +var addon = require( './drot.native.js' ); + + +// MAIN // + +/** +* Applies a plane rotation. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Float64Array} y - output 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 {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +* +* drot( 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 drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { + var viewX; + var viewY; + + offsetX = minViewBufferIndex( N, strideX, offsetX ); + offsetY = minViewBufferIndex( N, strideY, offsetY ); + + viewX = offsetView( x, offsetX ); + viewY = offsetView( y, offsetY ); + + addon( N, viewX, strideX, viewY, strideY, c, s ); + return y; +} + + +// EXPORTS // + +module.exports = drot; diff --git a/lib/node_modules/@stdlib/blas/base/drot/manifest.json b/lib/node_modules/@stdlib/blas/base/drot/manifest.json new file mode 100644 index 000000000000..14fed8a342f4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/manifest.json @@ -0,0 +1,175 @@ +{ + "options": { + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.f", + "./src/drot_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.f", + "./src/drot_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-strided-float64array" + ] + }, + { + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/package.json b/lib/node_modules/@stdlib/blas/base/drot/package.json index e7e855f44850..865bf99effd3 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/package.json +++ b/lib/node_modules/@stdlib/blas/base/drot/package.json @@ -14,11 +14,15 @@ } ], "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, "directories": { "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/Makefile b/lib/node_modules/@stdlib/blas/base/drot/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/addon.c b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c new file mode 100644 index 000000000000..9f3d11073feb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c @@ -0,0 +1,48 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/drot.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, c, argv, 5 ); + STDLIB_NAPI_ARGV_DOUBLE( env, s, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 3 ); + c_drot( N, X, strideX, Y, strideY, c, s ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c new file mode 100644 index 000000000000..a1bda88ba8bb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c @@ -0,0 +1,69 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/drot.h" + +/** +* Applies a plane rotation. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param Y output array +* @param strideY Y stride length +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void c_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s ) { + double tmp; + int ix; + int iy; + int i; + + if ( N <= 0 ) { + return; + } + // If both strides are equal to `1`... + if ( strideX == 1 && strideY == 1 ) { + for ( i = 0; i < N; i++ ) { + tmp = ( c * X[ i ] ) + ( s * Y[ i ] ); + Y[ i ] = ( c * Y[ i ] ) - ( s * X[ i ] ); + X[ i ] = tmp; + } + return; + } + // If both strides are not equal to `1`... + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + 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; +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot.f b/lib/node_modules/@stdlib/blas/base/drot/src/drot.f new file mode 100644 index 000000000000..977ac8880905 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot.f @@ -0,0 +1,97 @@ +!> +! @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. +!< + +!> Apples a plane rotation. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.7.0). Updated to "free form" Fortran 95. +! +! ## Authors +! +! * Univ. of Tennessee +! * Univ. of California Berkeley +! * Univ. of Colorado Denver +! * NAG Ltd. +! +! ## History +! +! * Jack Dongarra, linpack, 3/11/78. +! +! - modified 12/3/93, array(1) declarations changed to array(*) +! +! ## License +! +! From : +! +! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. +! > +! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: +! > +! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. +! > +! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. +! +! @param {integer} N - number of indexed elements +! @param {Array} dx - input array +! @param {integer} strideX - `dx` stride length +! @param {Array} dy - output array +! @param {integer} strideY - `dy` stride length +! @param {double precision} c - cosine term +! @param {double precision} s - sine term +!< +subroutine drot( N, dx, strideX, dy, strideY, c, s ) + implicit none + ! .. + ! Scalar arguments: + double precision :: c, s + integer :: strideX, strideY, N + ! .. + ! Array arguments: + double precision :: dx(*), dy(*) + ! .. + ! Local scalars: + double precision :: dtemp + integer :: i, ix, iy + ! .. + if ( N <= 0 ) then + return + end if + ! .. + ! If both strides are equal to `1`, use unrolled loops... + if ( strideX == 1 .AND. strideY == 1 ) then + do i = 1, N + dtemp = c*dx(i) + s*dy(i) + dy(i) = c*dy(i) - s*dx(i) + dx(i) = dtemp + end do + else + ix = 1 + iy = 1 + if ( strideX < 0 ) ix = ( 1 - N ) * strideX + 1 + if ( strideY < 0 ) iy = ( 1 - N ) * strideY + 1 + do i = 1, N + dtemp = c*dx(ix) + s*dy(iy) + dy(iy) = c*dy(iy) - s*dx(ix) + dx(ix) = dtemp + ix = ix + strideX + iy = iy + strideY + end do + end if + return +end subroutine drot \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c new file mode 100644 index 000000000000..86647fe8f314 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c @@ -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. +*/ + +#include "stdlib/blas/base/drot.h" +#include "stdlib/blas/base/drot_cblas.h" + +/** +* Applies a plane rotation. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param Y output array +* @param strideY Y stride length +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void c_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s ) { + cblas_drot( N, X, strideX, Y, strideY, c, s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c new file mode 100644 index 000000000000..034a78f1a915 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c @@ -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. +*/ + +#include "stdlib/blas/base/drot.h" +#include "stdlib/blas/base/drot_fortran.h" + +/** +* Applies a plane rotation. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param Y output array +* @param strideY Y stride length +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void c_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s ) { + drot( &N, X, &strideX, Y, &strideY, &c, &s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js new file mode 100644 index 000000000000..96e3782c1ade --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js @@ -0,0 +1,544 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var drot = tryRequire( resolve( __dirname, './../lib/drot.native.js' ) ); +var opts = { + 'skip': ( drot instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', opts, function test( t ) { + t.strictEqual( drot.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', opts, function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, 1, y, 1, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 2 and y stride as -2', opts, function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, 2, y, -2, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -2 and y stride as 1', opts, function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, -2, y, 1, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -1 and y stride as -2', opts, function test( t ) { + var xexpected; + var yexpected; + var nvalues; + var xvalues; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + out = drot( nvalues[ j ], x, -1, y, -2, 0.8, 0.6 ); + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]); + + drot( 2, x, 2, y, 1, 0.8, 0.6 ); + + xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + + drot( 3, x, 1, y, 2, 0.0, -1.0 ); + + xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 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', opts, function test( t ) { + var out; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = drot( 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', opts, function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float64Array( x.length ); + dcopy( x.length, x, 1, xe, 1 ); + + ye = new Float64Array( y.length ); + dcopy( y.length, y, 1, ye, 1 ); + + drot( -1, x, 1, y, 1, 0.8, 0.6 ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drot( 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( 'the function supports negative strides', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]); + + drot( 4, x, -2, y, 1, 0.8, 0.6 ); + + xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); + ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 20.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 20.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]); + + drot( 2, x, -1, y, -2, 0.8, 0.6 ); + + xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 5.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 5.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index aae456bd6d6a..2066a0891303 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -577,7 +577,7 @@ tape( 'the function returns a reference to the second input array', function tes x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); - out = drot( x.length, x, 1, 0, y, 1, 0 ); + out = drot( x.length, x, 1, 0, y, 1, 0, 1, 0 ); t.strictEqual( out, y, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js new file mode 100644 index 000000000000..2e684ea07149 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js @@ -0,0 +1,726 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var drot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( drot instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drot, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 9', opts, function test( t ) { + t.strictEqual( drot.length, 9, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', opts, function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = 1; + iyvalue = 1; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = max( ( 1 - nvalues[ j ] ) * iyvalue ); + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as 2 and y stride as -2', opts, function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = 2; + iyvalue = -2; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue); + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -2 and y stride as 1', opts, function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = -2; + iyvalue = 1; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue ); + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 20.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 20.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function applies a plane rotation with x stride as -1 and y stride as -2', opts, function test( t ) { + var xexpected; + var yexpected; + var ixvalue; + var iyvalue; + var nvalues; + var xoffset; + var xvalues; + var yoffset; + var yvalues; + var delta; + var tol; + var out; + var ex; + var ey; + var c; + var j; + var k; + var x; + var y; + + xexpected = [ + [ 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 ] + ]; + yexpected = [ + [ 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 ] + ]; + nvalues = [ 0, 1, 2, 4 ]; + ixvalue = -1; + iyvalue = -2; + + xvalues = [ + [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ]; + yvalues = [ + [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ]; + + c = 0; + for ( j = 0; j < nvalues.length; j++ ) { + x = new Float64Array( xvalues[ 0 ] ); + y = new Float64Array( yvalues[ 0 ] ); + if ( ixvalue < 0 ) { + xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); + } else { + xoffset = 0; + } + if ( iyvalue < 0 ) { + yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue ); + } else { + yoffset = 0; + } + out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len + ex = new Float64Array( xexpected[ c ] ); + ey = new Float64Array( yexpected[ c ] ); + c += 1; + for ( k = 0; k < ex.length; k++ ) { + if ( x[ k ] === ex[ k ] ) { + t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); + } else { + delta = abs( x[ k ] - ex[ k ] ); + tol = 4.0 * EPS * abs( ex[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ey[ k ] ) { + t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); + } else { + delta = abs( y[ k ] - ey[ k ] ); + tol = 4.0 * EPS * abs( ey[ k ] ); + t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]); + + drot( 2, x, 2, 0, y, 1, 0, 0.8, 0.6 ); + + xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `x` offset', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, + 9.0, + 10.0 + ]); + + drot( 2, x, 1, 1, y, 1, 0, 0.8, 0.6 ); + + xe = new Float64Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); + ye = new Float64Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 2.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 2.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]); + y = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + + drot( 3, x, 1, 0, y, 2, 0, 0.0, -1.0 ); + + xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `y` offset', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, + 4.0, + 5.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, // 0 + 9.0, // 1 + 10.0 + ]); + + drot( 2, x, 1, 0, y, 1, 2, 0.8, 0.6 ); + + xe = new Float64Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 1.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 1.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the second input array', opts, function test( t ) { + var out; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + out = drot( 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', opts, function test( t ) { + var xe; + var ye; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + + xe = new Float64Array( x.length ); + dcopy( x.length, x, 1, 0, xe, 1, 0 ); + + ye = new Float64Array( y.length ); + dcopy( y.length, y, 1, 0, ye, 1, 0 ); + + drot( -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' ); + + drot( 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( 'the function supports negative strides', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 0.6, // 3 + 0.1, + -0.5, // 2 + 0.8, + 0.9, // 1 + -0.3, + -0.4 // 0 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, // 2 + 0.7, // 3 + -0.6, + 0.2, + 0.8 + ]); + + drot( 4, x, -2, 6, y, 1, 0, 0.8, 0.6 ); + + xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); + ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 20.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 20.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var delta; + var tol; + var xe; + var ye; + var k; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, // 0 + -0.5, + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 1 + -0.9, + 0.3, // 0 + 0.7, + -0.6, + 0.2, + 0.8 + ]); + + drot( 2, x, -1, 1, y, -2, 2, 0.8, 0.6 ); + + xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); + for ( k = 0; k < xe.length; k++ ) { + if ( x[ k ] === xe[ k ] ) { + t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); + } + else { + delta = abs( x[ k ] - xe[ k ] ); + tol = 5.0 * EPS * abs( xe[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( y[ k ] === ye[ k ] ) { + t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); + } + else { + delta = abs( y[ k ] - ye[ k ] ); + tol = 5.0 * EPS * abs( ye[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); From 7e375136780b0ac7d3390088f8772f26a67b548b Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 12 Apr 2024 14:23:15 +0530 Subject: [PATCH 24/27] chore: apply review changes --- lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile | 2 +- .../@stdlib/blas/base/drot/benchmark/c/benchmark.length.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile index e69377585860..de40787d2d3d 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c index 391ebf4b9df2..b7f3b4a2d440 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c @@ -30,7 +30,7 @@ #define ITERATIONS 10000000 #define REPEATS 3 #define MIN 1 -#define MAX 6 +#define MAX 5 /** * Prints the TAP version. From 818ede6b4c2571e697c0df54bba8223cdb6f92f0 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Fri, 12 Apr 2024 22:15:38 +0530 Subject: [PATCH 25/27] chore: resolve lint errors --- .../@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h | 2 +- .../blas/base/drot/include/stdlib/blas/base/drot_cblas.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h index 415a17d1cd7c..6a7e4563508a 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h +++ b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h @@ -32,7 +32,7 @@ extern "C" { /** * Applies a plane rotation. */ -void c_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double s, const double c ); +void c_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_cblas.h b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_cblas.h index 5793b2ed4ec1..2340918b7c21 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_cblas.h +++ b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot_cblas.h @@ -32,7 +32,7 @@ extern "C" { /** * Applies a plane rotation. */ -void cblas_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s); +void cblas_drot( const int N, double *X, const int strideX, double *Y, const int strideY, const double c, const double s ); #ifdef __cplusplus } From c8e7deaac7761103cff483772bd4872acb877931 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 18 Apr 2024 18:50:47 -0700 Subject: [PATCH 26/27] refactor: replace use of 'double precision' and update tests --- .../blas/base/drot/benchmark/c/Makefile | 31 +- .../base/drot/benchmark/c/benchmark.length.c | 2 +- .../blas/base/drot/benchmark/fortran/Makefile | 2 +- .../@stdlib/blas/base/drot/docs/repl.txt | 1 + .../blas/base/drot/docs/types/index.d.ts | 8 +- .../blas/base/drot/examples/c/Makefile | 35 +- .../blas/base/drot/examples/c/example.c | 1 + .../@stdlib/blas/base/drot/lib/ndarray.js | 12 - .../@stdlib/blas/base/drot/manifest.json | 234 ++++++- .../@stdlib/blas/base/drot/src/drot.f | 40 +- .../@stdlib/blas/base/drot/test/test.drot.js | 452 +++++-------- .../blas/base/drot/test/test.drot.native.js | 452 +++++-------- .../blas/base/drot/test/test.ndarray.js | 610 ++++++----------- .../base/drot/test/test.ndarray.native.js | 611 ++++++------------ 14 files changed, 1012 insertions(+), 1479 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile index de40787d2d3d..9f97140e7cb0 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/Makefile @@ -69,8 +69,17 @@ else fPIC ?= -fPIC endif +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + # List of source files: -c_src := ../../src/drot.c +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= # List of C targets: c_targets := benchmark.length.out @@ -79,11 +88,15 @@ c_targets := benchmark.length.out # RULES # #/ -# Compiles C source files. +# Compiles source files. # # @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) # @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) # # @example # make @@ -99,12 +112,16 @@ all: $(c_targets) # Compiles C source files. # # @private -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) #/ $(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) #/ # Runs compiled benchmarks. diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c index b7f3b4a2d440..391ebf4b9df2 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c @@ -30,7 +30,7 @@ #define ITERATIONS 10000000 #define REPEATS 3 #define MIN 1 -#define MAX 5 +#define MAX 6 /** * Prints the TAP version. diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile index 9f0a6311a8e5..85aeb94b5f59 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/fortran/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# 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. diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt index 034181ac93de..1920e219ba6a 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/repl.txt @@ -119,6 +119,7 @@ > {{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: diff --git a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts index 154a4eeea797..393d2e5d425c 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/drot/docs/types/index.d.ts @@ -47,7 +47,7 @@ interface Routine { ( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number, c: number, s: number ): Float64Array; /** - * Applies a plane rotation. + * Applies a plane rotation using alternative indexing semantics. * * @param N - number of indexed elements * @param x - first input array @@ -101,9 +101,9 @@ interface Routine { * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); * -* drot.ndarray( 2, x, 2, 2, y, 2, 2, 0.8, 0.6 ); -* // x => [ 1.0, 2.0, 7.8, 4.0, 10.6, 6.0 ] -* // y => [ 7.0, 8.0, 5.4, 10.0, ~5.8, 12.0 ] +* drot.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 drot: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile index 44a5e0918c24..6aed70daf167 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2020 The Stdlib Authors. +# 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. @@ -69,8 +69,17 @@ else fPIC ?= -fPIC endif +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + # List of source files: -c_src := ../../src/drot.c +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= # List of C targets: c_targets := example.out @@ -79,11 +88,15 @@ c_targets := example.out # RULES # #/ -# Compiles C source files. +# Compiles source files. # # @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) # @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) # # @example # make @@ -99,15 +112,19 @@ all: $(c_targets) # Compiles C source files. # # @private -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) #/ $(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) #/ -# Runs compiled benchmarks. +# Runs compiled examples. # # @example # make run diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c index 72ccb4467425..e5ef27118027 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c @@ -40,6 +40,7 @@ int main( void ) { // Print the result: for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); printf( "y[ %i ] = %lf\n", i, y[ i ] ); } } diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js index 59c44bf6558b..0ec4a3a238ed 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.js @@ -56,18 +56,6 @@ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { ix = offsetX; iy = offsetY; - // If both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - 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; - } - // If both strides are not equal to `1`... for ( i = 0; i < N; i++ ) { tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); diff --git a/lib/node_modules/@stdlib/blas/base/drot/manifest.json b/lib/node_modules/@stdlib/blas/base/drot/manifest.json index 14fed8a342f4..fb727276068f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/drot/manifest.json @@ -1,5 +1,6 @@ { "options": { + "task": "build", "os": "linux", "blas": "", "wasm": false @@ -28,6 +29,7 @@ ], "confs": [ { + "task": "build", "os": "linux", "blas": "", "wasm": false, @@ -44,11 +46,43 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "linux", "blas": "openblas", "wasm": false, @@ -67,11 +101,49 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "mac", "blas": "", "wasm": false, @@ -88,11 +160,43 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "mac", "blas": "apple_accelerate_framework", "wasm": false, @@ -110,11 +214,47 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "mac", "blas": "openblas", "wasm": false, @@ -133,11 +273,49 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drot_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "win", "blas": "", "wasm": false, @@ -153,11 +331,43 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-double" ] }, { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drot.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + + { + "task": "build", "os": "", "blas": "", "wasm": true, diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot.f b/lib/node_modules/@stdlib/blas/base/drot/src/drot.f index 977ac8880905..b79b5f197303 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot.f +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot.f @@ -52,43 +52,51 @@ ! @param {integer} strideX - `dx` stride length ! @param {Array} dy - output array ! @param {integer} strideY - `dy` stride length -! @param {double precision} c - cosine term -! @param {double precision} s - sine term +! @param {double} c - cosine of the angle of rotation +! @param {double} s - sine of the angle of rotation !< subroutine drot( N, dx, strideX, dy, strideY, c, s ) implicit none ! .. + ! Internal parameters: + integer, parameter :: dp=kind(0.0d0) ! double-precision + ! .. ! Scalar arguments: - double precision :: c, s integer :: strideX, strideY, N + real(dp) :: c, s ! .. ! Array arguments: - double precision :: dx(*), dy(*) + real(dp) :: dx(*), dy(*) ! .. ! Local scalars: - double precision :: dtemp + real(dp) :: dtemp integer :: i, ix, iy ! .. if ( N <= 0 ) then return end if ! .. - ! If both strides are equal to `1`, use unrolled loops... if ( strideX == 1 .AND. strideY == 1 ) then do i = 1, N - dtemp = c*dx(i) + s*dy(i) - dy(i) = c*dy(i) - s*dx(i) - dx(i) = dtemp + dtemp = ( c*dx(i) ) + ( s*dy(i) ) + dy( i ) = ( c*dy(i) ) - ( s*dx(i) ) + dx( i ) = dtemp end do else - ix = 1 - iy = 1 - if ( strideX < 0 ) ix = ( 1 - N ) * strideX + 1 - if ( strideY < 0 ) iy = ( 1 - N ) * strideY + 1 + if ( strideX < 0 ) then + ix = ((1-N)*strideX) + 1 + else + ix = 1 + end if + if ( strideY < 0 ) then + iy = ((1-N)*strideY) + 1 + else + iy = 1 + end if do i = 1, N - dtemp = c*dx(ix) + s*dy(iy) - dy(iy) = c*dy(iy) - s*dx(ix) - dx(ix) = dtemp + dtemp = ( c*dx(ix) ) + ( s*dy(iy) ) + dy( iy ) = ( c*dy(iy) ) - ( s*dx(ix) ) + dx( ix ) = dtemp ix = ix + strideX iy = iy + strideY end do diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js index f6862d6675ba..8f0ea53bf556 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.js @@ -28,6 +28,35 @@ var abs = require( '@stdlib/math/base/special/abs' ); var drot = require( './../lib/drot.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 ) { @@ -41,280 +70,169 @@ tape( 'the function has an arity of 7', function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + N = [ 0, 1, 2, 4 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.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 = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, 1, y, 1, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as 2 and y stride as -2', function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, 2, y, -2, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -2 and y stride as 1', function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + N = [ 0, 1, 2, 4 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.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 = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, -2, y, 1, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -1 and y stride as -2', function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, -1, y, -2, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 supports an `x` stride', function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -337,24 +255,10 @@ tape( 'the function supports an `x` stride', function test( t ) { xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + t.end(); }); @@ -376,15 +280,17 @@ tape( 'the function supports a `y` stride', function test( t ) { 2.0, 3.0, // 1 4.0, - 5.0 // 2 + 5.0 // 2 ]); drot( 3, x, 1, y, 2, 0.0, -1.0 ); xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 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(); }); @@ -429,28 +335,25 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; x = new Float64Array([ - 0.6, // 3 + 0.6, // 3 0.1, -0.5, // 2 0.8, - 0.9, // 1 + 0.9, // 1 -0.3, - -0.4 // 0 + -0.4 // 0 ]); y = new Float64Array([ - 0.5, // 0 + 0.5, // 0 -0.9, // 1 - 0.3, // 2 - 0.7, // 3 + 0.3, // 2 + 0.7, // 3 -0.6, 0.2, 0.8 @@ -460,33 +363,16 @@ tape( 'the function supports negative strides', function test( t ) { xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 20.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 20.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + 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 delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -513,23 +399,9 @@ tape( 'the function supports complex access patterns', function test( t ) { xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 5.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 5.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js index 96e3782c1ade..3b8378039c8f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.drot.native.js @@ -37,6 +37,35 @@ var opts = { }; +// 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', opts, function test( t ) { @@ -50,280 +79,169 @@ tape( 'the function has an arity of 7', opts, function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', opts, function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + N = [ 0, 1, 2, 4 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.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 = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, 1, y, 1, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as 2 and y stride as -2', opts, function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, 2, y, -2, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -2 and y stride as 1', opts, function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + N = [ 0, 1, 2, 4 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.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 = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, -2, y, 1, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -1 and y stride as -2', opts, function test( t ) { - var xexpected; - var yexpected; - var nvalues; - var xvalues; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - out = drot( nvalues[ j ], x, -1, y, -2, 0.8, 0.6 ); - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 supports an `x` stride', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -346,24 +264,10 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + t.end(); }); @@ -385,15 +289,17 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 2.0, 3.0, // 1 4.0, - 5.0 // 2 + 5.0 // 2 ]); drot( 3, x, 1, y, 2, 0.0, -1.0 ); xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 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(); }); @@ -438,28 +344,25 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; x = new Float64Array([ - 0.6, // 3 + 0.6, // 3 0.1, -0.5, // 2 0.8, - 0.9, // 1 + 0.9, // 1 -0.3, - -0.4 // 0 + -0.4 // 0 ]); y = new Float64Array([ - 0.5, // 0 + 0.5, // 0 -0.9, // 1 - 0.3, // 2 - 0.7, // 3 + 0.3, // 2 + 0.7, // 3 -0.6, 0.2, 0.8 @@ -469,33 +372,16 @@ tape( 'the function supports negative strides', opts, function test( t ) { xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 20.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 20.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + t.end(); }); tape( 'the function supports complex access patterns', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -522,23 +408,9 @@ tape( 'the function supports complex access patterns', opts, function test( t ) xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 5.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 5.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js index 2066a0891303..e5456f9cb67a 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.js @@ -28,6 +28,35 @@ var abs = require( '@stdlib/math/base/special/abs' ); var drot = require( './../lib/ndarray.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 ) { @@ -41,344 +70,188 @@ tape( 'the function has an arity of 9', function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=1, sy=1)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = 1; - iyvalue = 1; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = ( 1 - nvalues[ j ] ) * ixvalue; - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = ( 1 - nvalues[ j ] ) * iyvalue; - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as 2 and y stride as -2', function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=2, sy=-2)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = 2; - iyvalue = -2; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = ( 1 - nvalues[ j ] ) * ixvalue; - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = ( 1 - nvalues[ j ] ) * iyvalue; - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -2 and y stride as 1', function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-2, sy=1)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = -2; - iyvalue = 1; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 2, 6 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ) ]; - - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = ( 1 - nvalues[ j ] ) * ixvalue; - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = ( 1 - nvalues[ j ] ) * iyvalue; - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -1 and y stride as -2', function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = -1; - iyvalue = -2; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = ( 1 - nvalues[ j ] ) * ixvalue; - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = ( 1 - nvalues[ j ] ) * iyvalue; - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 supports an `x` stride', function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -401,33 +274,16 @@ tape( 'the function supports an `x` stride', function test( t ) { xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + t.end(); }); -tape( 'the function supports a `x` offset', function test( t ) { - var delta; - var tol; +tape( 'the function supports an `x` offset', function test( t ) { var xe; var ye; - var k; var x; var y; @@ -450,33 +306,16 @@ tape( 'the function supports a `x` offset', function test( t ) { xe = new Float64Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + 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 delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -499,33 +338,16 @@ tape( 'the function supports a `y` stride', function test( t ) { xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + 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 delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -548,24 +370,10 @@ tape( 'the function supports a `y` offset', function test( t ) { xe = new Float64Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + t.end(); }); @@ -610,28 +418,25 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; x = new Float64Array([ - 0.6, // 3 + 0.6, // 3 0.1, -0.5, // 2 0.8, - 0.9, // 1 + 0.9, // 1 -0.3, - -0.4 // 0 + -0.4 // 0 ]); y = new Float64Array([ - 0.5, // 0 + 0.5, // 0 -0.9, // 1 - 0.3, // 2 - 0.7, // 3 + 0.3, // 2 + 0.7, // 3 -0.6, 0.2, 0.8 @@ -641,33 +446,16 @@ tape( 'the function supports negative strides', function test( t ) { xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 20.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 20.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + 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 delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -694,23 +482,9 @@ tape( 'the function supports complex access patterns', function test( t ) { xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 5.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 5.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js index 2e684ea07149..c7cd296d3093 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/drot/test/test.ndarray.native.js @@ -26,7 +26,6 @@ var Float64Array = require( '@stdlib/array/float64' ); var dcopy = require( '@stdlib/blas/base/dcopy' ).ndarray; var EPS = require( '@stdlib/constants/float64/eps' ); var abs = require( '@stdlib/math/base/special/abs' ); -var max = require( '@stdlib/math/base/special/max' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -38,6 +37,35 @@ var opts = { }; +// 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', opts, function test( t ) { @@ -51,344 +79,188 @@ tape( 'the function has an arity of 9', opts, function test( t ) { t.end(); }); -tape( 'the function applies a plane rotation with x stride as 1 and y stride as 1', opts, function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=1, sy=1)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = 1; - iyvalue = 1; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, -0.46, -0.22, 1.06, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.78, 0.54, 0.08, -0.6, 0.2, 0.8 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = max( ( 1 - nvalues[ j ] ) * iyvalue ); - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as 2 and y stride as -2', opts, function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=2, sy=-2)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = 2; - iyvalue = -2; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 0, 0 ]; + oy = [ 0, 0, 2, 6 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.66, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.96, 0.1, -0.76, 0.8, 0.9, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -0.9, -0.12, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -0.9, -0.3, 0.7, -0.18, 0.2, 0.28 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue); - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -2 and y stride as 1', opts, function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-2, sy=1)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = -2; - iyvalue = 1; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + ox = [ 0, 0, 2, 6 ]; + oy = [ 0, 0, 0, 0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.06, 0.1, -0.1, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.7, -1.08, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ) ]; - - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue ); - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 20.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 20.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 with x stride as -1 and y stride as -2', opts, function test( t ) { - var xexpected; - var yexpected; - var ixvalue; - var iyvalue; - var nvalues; - var xoffset; - var xvalues; - var yoffset; - var yvalues; - var delta; - var tol; +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function test( t ) { + var xbuf; + var ybuf; var out; - var ex; - var ey; - var c; - var j; - var k; + var xe; + var ye; + var ox; + var oy; + var N; var x; var y; + var i; - xexpected = [ - [ 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 ] - ]; - yexpected = [ - [ 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 ] - ]; - nvalues = [ 0, 1, 2, 4 ]; - ixvalue = -1; - iyvalue = -2; + 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 ]; - xvalues = [ - [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 0.78, 0.26, -0.76, 1.12, 0.9, -0.3, -0.4 ] ) ]; - yvalues = [ - [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.18, 0.2, 0.16 ] ) ]; - c = 0; - for ( j = 0; j < nvalues.length; j++ ) { - x = new Float64Array( xvalues[ 0 ] ); - y = new Float64Array( yvalues[ 0 ] ); - if ( ixvalue < 0 ) { - xoffset = max( 0, ( 1 - nvalues[ j ] ) * ixvalue ); - } else { - xoffset = 0; - } - if ( iyvalue < 0 ) { - yoffset = max( 0, ( 1 - nvalues[ j ] ) * iyvalue ); - } else { - yoffset = 0; - } - out = drot( nvalues[ j ], x, ixvalue, xoffset, y, iyvalue, yoffset, 0.8, 0.6 ); // eslint-disable-line max-len - ex = new Float64Array( xexpected[ c ] ); - ey = new Float64Array( yexpected[ c ] ); - c += 1; - for ( k = 0; k < ex.length; k++ ) { - if ( x[ k ] === ex[ k ] ) { - t.strictEqual( x[ k ], ex[ k ], 'returns expected value' ); - } else { - delta = abs( x[ k ] - ex[ k ] ); - tol = 4.0 * EPS * abs( ex[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+ex[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ey[ k ] ) { - t.strictEqual( y[ k ], ey[ k ], 'returns expected value' ); - } else { - delta = abs( y[ k ] - ey[ k ] ); - tol = 4.0 * EPS * abs( ey[ k ] ); - t.ok( delta <= tol, 'within tolerance. y: '+y[ k ]+'. expected: '+ey[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - t.strictEqual( out[ k ], y[ k ], 'returns expected value' ); - } + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drot( 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 supports an `x` stride', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -411,33 +283,16 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { xe = new Float64Array( [ 4.4, 2.0, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 4.2, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + t.end(); }); -tape( 'the function supports a `x` offset', opts, function test( t ) { - var delta; - var tol; +tape( 'the function supports an `x` offset', opts, function test( t ) { var xe; var ye; - var k; var x; var y; @@ -460,33 +315,16 @@ tape( 'the function supports a `x` offset', opts, function test( t ) { xe = new Float64Array( [ 1.0, 5.2, 6.6, 4.0, 5.0 ] ); ye = new Float64Array( [ 3.6, 3.8, 8.0, 9.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 2.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 2.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + t.end(); }); tape( 'the function supports a `y` stride', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -509,33 +347,16 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { xe = new Float64Array( [ -1.0, -3.0, -5.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 1.0, 2.0, 2.0, 4.0, 3.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + t.end(); }); tape( 'the function supports a `y` offset', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -558,24 +379,10 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { xe = new Float64Array( [ 5.6, 7.0, 3.0, 4.0, 5.0 ] ); ye = new Float64Array( [ 6.0, 7.0, 5.8, 6.0, 10.0 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 1.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 1.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 1.0 ); + isApprox( t, y, ye, 1.0 ); + t.end(); }); @@ -620,28 +427,25 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function leav }); tape( 'the function supports negative strides', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; x = new Float64Array([ - 0.6, // 3 + 0.6, // 3 0.1, -0.5, // 2 0.8, - 0.9, // 1 + 0.9, // 1 -0.3, - -0.4 // 0 + -0.4 // 0 ]); y = new Float64Array([ - 0.5, // 0 + 0.5, // 0 -0.9, // 1 - 0.3, // 2 - 0.7, // 3 + 0.3, // 2 + 0.7, // 3 -0.6, 0.2, 0.8 @@ -651,33 +455,16 @@ tape( 'the function supports negative strides', opts, function test( t ) { xe = new Float64Array( [ 0.9, 0.1, -0.22, 0.8, 0.18, -0.3, -0.02 ] ); ye = new Float64Array( [ 0.64, -1.26, 0.54, 0.2, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 20.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 20.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 20.0 ); + isApprox( t, y, ye, 20.0 ); + t.end(); }); tape( 'the function supports complex access patterns', opts, function test( t ) { - var delta; - var tol; var xe; var ye; - var k; var x; var y; @@ -704,23 +491,9 @@ tape( 'the function supports complex access patterns', opts, function test( t ) xe = new Float64Array( [ 0.78, 0.26, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); ye = new Float64Array( [ 0.04, -0.9, 0.18, 0.7, -0.6, 0.2, 0.8 ] ); - for ( k = 0; k < xe.length; k++ ) { - if ( x[ k ] === xe[ k ] ) { - t.strictEqual( x[ k ], xe[ k ], 'returns expected value' ); - } - else { - delta = abs( x[ k ] - xe[ k ] ); - tol = 5.0 * EPS * abs( xe[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ k ]+'. expected: '+xe[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( y[ k ] === ye[ k ] ) { - t.strictEqual( y[ k ], ye[ k ], 'returns expected value' ); - } - else { - delta = abs( y[ k ] - ye[ k ] ); - tol = 5.0 * EPS * abs( ye[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+y[ k ]+'. expected: '+ye[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + t.end(); }); From 43f62d88cd1babe6409458a33654e017fad4e395 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 18 Apr 2024 18:54:24 -0700 Subject: [PATCH 27/27] docs: update example --- lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c index e5ef27118027..86c9fd5c41be 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c @@ -40,7 +40,6 @@ int main( void ) { // Print the result: for ( int i = 0; i < 5; i++ ) { - printf( "x[ %i ] = %lf\n", i, x[ i ] ); - printf( "y[ %i ] = %lf\n", i, y[ i ] ); + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } }