From 51608dce38bc73594242644c3b732c37ed3dfbe8 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Tue, 25 Jun 2024 06:44:17 +0530 Subject: [PATCH] feat: add `blas/base/drotm` PR-URL: https://github.com/stdlib-js/stdlib/pull/2266 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Reviewed-by: Pranav Goswami --- .../@stdlib/blas/base/drotm/README.md | 303 ++++++++++ .../blas/base/drotm/benchmark/benchmark.js | 105 ++++ .../base/drotm/benchmark/benchmark.native.js | 110 ++++ .../base/drotm/benchmark/benchmark.ndarray.js | 105 ++++ .../benchmark/benchmark.ndarray.native.js | 110 ++++ .../blas/base/drotm/benchmark/c/Makefile | 146 +++++ .../base/drotm/benchmark/c/benchmark.length.c | 153 +++++ .../base/drotm/benchmark/fortran/Makefile | 141 +++++ .../benchmark/fortran/benchmark.length.f | 215 +++++++ .../@stdlib/blas/base/drotm/binding.gyp | 265 ++++++++ .../@stdlib/blas/base/drotm/docs/repl.txt | 135 +++++ .../blas/base/drotm/docs/types/index.d.ts | 115 ++++ .../blas/base/drotm/docs/types/test.ts | 298 +++++++++ .../blas/base/drotm/examples/c/Makefile | 146 +++++ .../blas/base/drotm/examples/c/example.c | 44 ++ .../@stdlib/blas/base/drotm/examples/index.js | 38 ++ .../@stdlib/blas/base/drotm/include.gypi | 70 +++ .../drotm/include/stdlib/blas/base/drotm.h | 43 ++ .../include/stdlib/blas/base/drotm_cblas.h | 43 ++ .../include/stdlib/blas/base/drotm_fortran.h | 41 ++ .../@stdlib/blas/base/drotm/lib/drotm.js | 154 +++++ .../blas/base/drotm/lib/drotm.native.js | 58 ++ .../@stdlib/blas/base/drotm/lib/index.js | 74 +++ .../@stdlib/blas/base/drotm/lib/main.js | 35 ++ .../@stdlib/blas/base/drotm/lib/native.js | 35 ++ .../@stdlib/blas/base/drotm/lib/ndarray.js | 147 +++++ .../blas/base/drotm/lib/ndarray.native.js | 71 +++ .../@stdlib/blas/base/drotm/manifest.json | 417 +++++++++++++ .../@stdlib/blas/base/drotm/package.json | 78 +++ .../@stdlib/blas/base/drotm/src/Makefile | 70 +++ .../@stdlib/blas/base/drotm/src/addon.c | 48 ++ .../@stdlib/blas/base/drotm/src/drotm.c | 136 +++++ .../@stdlib/blas/base/drotm/src/drotm.f | 166 +++++ .../@stdlib/blas/base/drotm/src/drotm_cblas.c | 35 ++ .../@stdlib/blas/base/drotm/src/drotm_f.c | 35 ++ .../blas/base/drotm/test/test.drotm.js | 467 ++++++++++++++ .../blas/base/drotm/test/test.drotm.native.js | 480 +++++++++++++++ .../@stdlib/blas/base/drotm/test/test.js | 82 +++ .../blas/base/drotm/test/test.ndarray.js | 562 +++++++++++++++++ .../base/drotm/test/test.ndarray.native.js | 571 ++++++++++++++++++ 40 files changed, 6347 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/include/stdlib/blas/base/drotm_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/drotm.f create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/base/drotm/README.md b/lib/node_modules/@stdlib/blas/base/drotm/README.md new file mode 100644 index 00000000000..cb081be59f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/README.md @@ -0,0 +1,303 @@ + + +# drotm + +> Apply a modified Givens plane rotation. + +
+ +## Usage + +```javascript +var drotm = require( '@stdlib/blas/base/drotm' ); +``` + +#### drotm( N, x, strideX, y, strideY, param ) + +Applies a modified Givens 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 ] ); +var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + +drotm( 2, x, 2, y, 1, param ); +// x => [ ~-17.0, 2.0, ~-18.0, 4.0, 5.0 ] +// y => [ ~8.0, ~13.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`. +- **param**: parameters for the modified Givens transformation + +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply a modified Givens plane rotation to every other element, + +```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 ] ); +var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + +drotm( 3, x, 2, y, 2, param ); +// x => [ ~-20.0, 2.0, ~-24.0, 4.0, ~-28.0, 6.0 ] +// y => [ ~9.0, 8.0, ~15.0, 10.0, ~21.0, 12.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var y0 = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); +var param = new Float64Array( [ 1.0, 0.0, 2.0, 3.0, 0.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 + +drotm( 2, x1, 1, y1, 1, param ); +// x0 => [ 1.0, ~9.0, ~10.0, 4.0, 5.0 ] +// y0 => [ 6.0, 7.0, 8.0, ~-2.0, ~-3.0 ] +``` + +#### drotm.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param ) + +Applies a modified Givens plane rotation using alternative indexing semantics. + +```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 ] ); +var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + +drotm.ndarray( 2, x, 1, 0, y, 2, 1, param ); +// x => [ ~-20.0, ~-25.0, 3.0, 4.0, 5.0 ] +// y => [ 6.0, ~9.0, 8.0, ~13.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, to apply a modified Givens plane rotation to every other element starting from the second element, + +```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 ] ); +var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + +drotm.ndarray( 3, x, 2, 1, y, 2, 1, param ); +// x => [ 1.0, ~-22.0, 3.0, ~-26.0, 5.0, ~-30.0 ] +// y => [ 7.0, ~12.0, 9.0, ~18.0, 11.0, ~24.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions leave `x` and `y` unchanged. +- `drotm()` corresponds to the [BLAS][blas] level 1 function [`drotm`][drotm]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var drotm = require( '@stdlib/blas/base/drotm' ); + +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 ); + +var param = discreteUniform( 5, -5, 5, opts ); +console.log( param ); + +// Apply a plane rotation: +drotm( x.length, x, 1, y, 1, param ); +console.log( x ); +console.log( y ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/drotm.h" +``` + +#### c_drotm( N, \*X, strideX, \*Y, strideY, param ) + +Applies a modified Givens plane rotation. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; +double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; +const double param[5] = { 0.0, 0.0, 2.0, -3.0, 0.0 }; + +c_drotm( 5, x, 1, y, 1, param ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **Y**: `[inout] double*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **param**: `[in] double` parameters for the modified Givens transformation. + +```c +void c_drotm( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/drotm.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 parameters for the modified Givens transformation: + const double param[5] = { 0.0, 0.0, 2.0, -3.0, 0.0 }; + + // Apply plane rotation: + c_drotm( N, x, strideX, y, strideY, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.js new file mode 100644 index 00000000000..58bc64efa90 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var drotm = require( './../lib/drotm.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 param = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = drotm( x.length, x, 1, y, 1, param ); + 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/drotm/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.native.js new file mode 100644 index 00000000000..c5d4f7b3e91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.native.js @@ -0,0 +1,110 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drotm = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( drotm 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 param = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = drotm( x.length, x, 1, y, 1, param ); + 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/drotm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..dcffeb06bbe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var drotm = 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 param = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = drotm( x.length, x, 1, 0, y, 1, 0, param ); + 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/drotm/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.native.js new file mode 100644 index 00000000000..c9f7bbddb29 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,110 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var drotm = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( drotm 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 param = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + var x = uniform( len, -10.0, 10.0, options ); + var y = uniform( len, -10.0, 10.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 = drotm( x.length, x, 1, 0, y, 1, 0, param ); + 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/drotm/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/Makefile new file mode 100644 index 00000000000..9f97140e7cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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 + +# 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 includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +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 + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - 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 -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 +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @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) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# 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/drotm/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c new file mode 100644 index 00000000000..bee6c06c430 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/c/benchmark.length.c @@ -0,0 +1,153 @@ +/** +* @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/drotm.h" +#include +#include +#include +#include +#include + +#define NAME "drotm" +#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; + + const double param[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 }; + 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_drotm( len, x, 1, y, 1, param ); + 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/drotm/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/Makefile new file mode 100644 index 00000000000..8fe9d6771df --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/Makefile @@ -0,0 +1,141 @@ +#/ +# @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 + +# 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/drotm.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/drotm/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/benchmark.length.f new file mode 100644 index 00000000000..d4fefc6735b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/benchmark/fortran/benchmark.length.f @@ -0,0 +1,215 @@ +!> +! @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. +!< + +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'drotm' ! 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 drotm( N, dx, strideX, dy, strideY, dparam ) + double precision :: dparam(5), dx(*), dy(*) + integer :: strideX, strideY, N + end subroutine drotm + 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(:) + double precision :: param(5) + ! .. + ! 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 + param(1) = 0.0d0 + param(2) = 0.0d0 + param(3) = 0.0d0 + param(4) = 0.0d0 + param(5) = 0.0d0 + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call drotm( len, x, 1, y, 1, param ); + 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/drotm/binding.gyp b/lib/node_modules/@stdlib/blas/base/drotm/binding.gyp new file mode 100644 index 00000000000..02a2799da09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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/drotm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/drotm/docs/repl.txt new file mode 100644 index 00000000000..f2af006c03b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/docs/repl.txt @@ -0,0 +1,135 @@ + +{{alias}}( N, x, strideX, y, strideY, param ) + Applies a modified Givens plane rotation. + + 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. + + 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`. + + param: Float64Array + Parameters for the modified Givens transformation. + + 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 ] ); + > var param = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + > {{alias}}( 2, x, 2, y, 1, param ); + > x + [ ~-17.0, 2.0, ~-18.0, 4.0, 5.0 ] + > y + [ ~8.0, ~13.0, 8.0, 9.0, 10.0 ] + + // Advanced Indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 0.6, 0.1, -0.5, 0.8, 0.9 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 0.5, -0.9, 0.3, 0.7, -0.6 ] ); + > param = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + > {{alias}}( 2, x, -2, y, 1, param ); + > x + [ ~3.3, 0.1, ~-2.0, 0.8, 0.9 ] + > y + [ ~-0.5, ~0.3, 0.3, 0.7, -0.6 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + > param = new {{alias:@stdlib/array/float64}}( [ 1.0, 0.0, 2.0, 3.0, 0.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}}( 2, x1, 1, y1, 1, param ); + > x0 + [ 1.0, ~9.0, ~10.0, 4.0, 5.0 ] + > y0 + [ 6.0, 7.0, 8.0, ~-2.0, ~-3.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param ) + Applies a modified Givens plane rotation using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: 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`. + + param: Float64Array + Parameters for the modified Givens transformation. + + 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 ] ); + > param = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + > {{alias}}.ndarray( 2, x, 1, 0, y, 2, 1, param ); + > x + [ ~-20.0, ~-25.0, 3.0, 4.0, 5.0 ] + > y + [ 6.0, ~9.0, 8.0, ~13.0, 10.0 ] + + // Advanced Indexing: + > x = new {{alias:@stdlib/array/float64}}( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); + > param = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + > {{alias}}.ndarray( 2, x, -1, 1, y, -2, 2, param ); + > x + [ ~-0.9, ~-0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] + > y + [ ~1.7, -0.9, ~0.5, 0.7, -0.6, 0.2, 0.8 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/base/drotm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/drotm/docs/types/index.d.ts new file mode 100644 index 00000000000..a3be02b5970 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/docs/types/index.d.ts @@ -0,0 +1,115 @@ +/* +* @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 `drotm`. +*/ +interface Routine { + /** + * Applies a modified Givens 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 param - parameters for the modified Givens transformation + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + * var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); + * var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + * + * drotm( 4, x, -1, y, -2, param ); + * // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] + * // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] + */ + ( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number, param: Float64Array ): Float64Array; + + /** + * Applies a modified Givens plane rotation using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @param param - parameters for the modified Givens transformation + * @returns `y` + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * var drotm = require( '@stdlib/blas/base/drotm' ); + * + * var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + * var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); + * var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + * + * drotm.ndarray( 4, x, -1, 3, y, -2, 6, param ); + * // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] + * // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number, param: Float64Array ): Float64Array; +} + +/** +* Applies a modified Givens 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 param - parameters for the modified Givens transformation +* @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 param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm( 2, x, 2, y, 1, param ); +* // x => [ ~-17.0, 2.0, ~-18.0, 4.0, 5.0 ] +* // y => [ ~8.0, ~13.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 param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm.ndarray( 2, x, 1, 0, y, 2, 1, param ); +* // x => [ ~-20.0, ~-25.0, 3.0, 4.0, 5.0 ] +* // y => [ 6.0, ~9.0, 8.0, ~13.0, 10.0 ] +*/ +declare var drotm: Routine; + + +// EXPORTS // + +export = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/drotm/docs/types/test.ts new file mode 100644 index 00000000000..d3418c5b351 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/docs/types/test.ts @@ -0,0 +1,298 @@ +/* +* @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 drotm = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const param = new Float64Array( 5 ); + + drotm( x.length, x, 1, y, 1, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm( '10', x, 1, y, 1, param ); // $ExpectError + drotm( true, x, 1, y, 1, param ); // $ExpectError + drotm( false, x, 1, y, 1, param ); // $ExpectError + drotm( null, x, 1, y, 1, param ); // $ExpectError + drotm( undefined, x, 1, y, 1, param ); // $ExpectError + drotm( [], x, 1, y, 1, param ); // $ExpectError + drotm( {}, x, 1, y, 1, param ); // $ExpectError + drotm( ( x: number ): number => x, x, 1, y, 1, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm( x.length, 10, 1, y, 1, param ); // $ExpectError + drotm( x.length, '10', 1, y, 1, param ); // $ExpectError + drotm( x.length, true, 1, y, 1, param ); // $ExpectError + drotm( x.length, false, 1, y, 1, param ); // $ExpectError + drotm( x.length, null, 1, y, 1, param ); // $ExpectError + drotm( x.length, undefined, 1, y, 1, param ); // $ExpectError + drotm( x.length, [], 1, y, 1, param ); // $ExpectError + drotm( x.length, {}, 1, y, 1, param ); // $ExpectError + drotm( x.length, ( x: number ): number => x, 1, y, 1, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm( x.length, x, '10', y, 1, param ); // $ExpectError + drotm( x.length, x, true, y, 1, param ); // $ExpectError + drotm( x.length, x, false, y, 1, param ); // $ExpectError + drotm( x.length, x, null, y, 1, param ); // $ExpectError + drotm( x.length, x, undefined, y, 1, param ); // $ExpectError + drotm( x.length, x, [], y, 1, param ); // $ExpectError + drotm( x.length, x, {}, y, 1, param ); // $ExpectError + drotm( x.length, x, ( x: number ): number => x, y, 1, param ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const param = new Float64Array( 5 ); + + drotm( x.length, x, 1, 10, 1, param ); // $ExpectError + drotm( x.length, x, 1, '10', 1, param ); // $ExpectError + drotm( x.length, x, 1, true, 1, param ); // $ExpectError + drotm( x.length, x, 1, false, 1, param ); // $ExpectError + drotm( x.length, x, 1, null, 1, param ); // $ExpectError + drotm( x.length, x, 1, undefined, 1, param ); // $ExpectError + drotm( x.length, x, 1, [], 1, param ); // $ExpectError + drotm( x.length, x, 1, {}, 1, param ); // $ExpectError + drotm( x.length, x, 1, ( x: number ): number => x, 1, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm( x.length, x, 1, y, '10', param ); // $ExpectError + drotm( x.length, x, 1, y, true, param ); // $ExpectError + drotm( x.length, x, 1, y, false, param ); // $ExpectError + drotm( x.length, x, 1, y, null, param ); // $ExpectError + drotm( x.length, x, 1, y, undefined, param ); // $ExpectError + drotm( x.length, x, 1, y, [], param ); // $ExpectError + drotm( x.length, x, 1, y, {}, param ); // $ExpectError + drotm( x.length, x, 1, y, ( x: number ): number => x, param ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drotm( x.length, x, 1, y, 1, 10 ); // $ExpectError + drotm( x.length, x, 1, y, 1, '10' ); // $ExpectError + drotm( x.length, x, 1, y, 1, true ); // $ExpectError + drotm( x.length, x, 1, y, 1, false ); // $ExpectError + drotm( x.length, x, 1, y, 1, null ); // $ExpectError + drotm( x.length, x, 1, y, 1, undefined ); // $ExpectError + drotm( x.length, x, 1, y, 1, [] ); // $ExpectError + drotm( x.length, x, 1, y, 1, {} ); // $ExpectError + drotm( x.length, x, 1, y, 1, ( 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 ); + const param = new Float64Array( 5 ); + + drotm(); // $ExpectError + drotm( x.length ); // $ExpectError + drotm( x.length, x ); // $ExpectError + drotm( x.length, x, 1 ); // $ExpectError + drotm( x.length, x, 1, y ); // $ExpectError + drotm( x.length, x, 1, y, 1 ); // $ExpectError + drotm( x.length, x, 1, y, 1, param, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( '10', x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( true, x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( false, x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( null, x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( undefined, x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( [], x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( {}, x, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, 10, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, '10', 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, true, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, false, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, null, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, undefined, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, [], 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, {}, 1, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, '10', 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, true, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, false, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, null, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, undefined, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, [], 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, {}, 0, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, 1, '10', y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, true, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, false, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, null, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, undefined, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, [], y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, {}, y, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, 1, 0, 10, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, '10', 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, true, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, false, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, null, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, undefined, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, [], 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, {}, 1, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, 1, 0, y, '10', 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, true, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, false, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, null, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, undefined, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, [], 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, {}, 0, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0, param ); // $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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray( x.length, x, 1, 0, y, 1, '10', param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, true, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, false, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, null, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, undefined, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, [], param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, {}, param ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x, param ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, '10' ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, true ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, false ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, null ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, undefined ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, [] ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, {} ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 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 ); + const param = new Float64Array( 5 ); + + drotm.ndarray(); // $ExpectError + drotm.ndarray( x.length ); // $ExpectError + drotm.ndarray( x.length, x ); // $ExpectError + drotm.ndarray( x.length, x, 1 ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0 ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectError + drotm.ndarray( x.length, x, 1, 0, y, 1, 0, param, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/Makefile new file mode 100644 index 00000000000..6aed70daf16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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 + +# 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 includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +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 + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - 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 -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 +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @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) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @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/drotm/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c new file mode 100644 index 00000000000..41f1bada0a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/examples/c/example.c @@ -0,0 +1,44 @@ +/** +* @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/drotm.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 parameters for the modified Givens transformation: + const double param[5] = { 0.0, 0.0, 2.0, -3.0, 0.0 }; + + // Apply plane rotation: + c_drotm( N, x, strideX, y, strideY, param ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/examples/index.js b/lib/node_modules/@stdlib/blas/base/drotm/examples/index.js new file mode 100644 index 00000000000..a939206d70f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 drotm = 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 ); + +var param = discreteUniform( 5, -5, 5, opts ); +console.log( param ); + +drotm( x.length, x, 1, y, 1, param ); +console.log( x ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/base/drotm/include.gypi b/lib/node_modules/@stdlib/blas/base/drotm/include.gypi new file mode 100644 index 00000000000..497aeca1532 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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)', + ' [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +*/ +function drotm( N, x, strideX, y, strideY, param ) { + var dflag; + var dh11; + var dh12; + var dh21; + var dh22; + var ix; + var iy; + var i; + var w; + var z; + + dflag = param[ 0 ]; + if ( N <= 0 || dflag === -2.0 ) { + return y; + } + if ( strideX === strideY && strideX > 0 ) { + ix = 0; + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = ( w * dh11 ) + ( z * dh12 ); + y[ ix ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + } + return y; + } + if ( dflag === 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = w + ( z * dh12 ); + y[ ix ] = ( w * dh21 ) + z; + ix += strideX; + } + return y; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = ( w * dh11 ) + z; + y[ ix ] = -w + ( z * dh22 ); + ix += strideX; + } + return y; + } + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = ( w * dh11 ) + ( z * dh12 ); + y[ iy ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return y; + } + if ( dflag === 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = w + ( z * dh12 ); + y[ iy ] = ( w * dh21 ) + z; + ix += strideX; + iy += strideY; + } + return y; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = ( w * dh11 ) + z; + y[ iy ] = -w + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.native.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.native.js new file mode 100644 index 00000000000..7c8421068b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.native.js @@ -0,0 +1,58 @@ +/** +* @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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Applies a modified Givens 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 {Float64Array} param - parameters for the modified Givens transformation +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); +* var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); +* var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm( 4, x, -1, y, -2, param ); +* // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +*/ +function drotm( N, x, strideX, y, strideY, param ) { + addon( N, x, strideX, y, strideY, param ); + return y; +} + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/index.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/index.js new file mode 100644 index 00000000000..6be02e24e22 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/index.js @@ -0,0 +1,74 @@ +/** +* @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 modified Givens plane rotation. +* +* @module @stdlib/blas/base/drotm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var drotm = require( '@stdlib/blas/base/drotm' ); +* +* var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); +* var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); +* var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm( 4, x, -1, y, -2, param ); +* // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var drotm = require( '@stdlib/blas/base/drotm' ); +* +* var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); +* var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); +* var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm.ndarray( 4, x, -1, 3, y, -2, 6, param ); +* // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +*/ + +// 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 drotm; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + drotm = main; +} else { + drotm = tmp; +} + + +// EXPORTS // + +module.exports = drotm; + +// exports: { "ndarray": "drotm.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/main.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/main.js new file mode 100644 index 00000000000..88b007bf2d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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 drotm = require( './drotm.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( drotm, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/native.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/native.js new file mode 100644 index 00000000000..0c0b3f20e06 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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 drotm = require( './drotm.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( drotm, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js new file mode 100644 index 00000000000..d2bafae0c0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js @@ -0,0 +1,147 @@ +/** +* @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 modified Givens 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 {Float64Array} param - parameters for the modified Givens transformation +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); +* var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); +* var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm( 4, x, -1, 3, y, -2, 6, param ); +* // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +*/ +function drotm( N, x, strideX, offsetX, y, strideY, offsetY, param ) { + var dflag; + var dh11; + var dh12; + var dh21; + var dh22; + var ix; + var iy; + var i; + var w; + var z; + + dflag = param[ 0 ]; + if ( N <= 0 || dflag === -2.0 ) { + return y; + } + ix = offsetX; + iy = offsetY; + if ( strideX === strideY && strideX > 0 ) { + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = ( w * dh11 ) + ( z * dh12 ); + y[ ix ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + } + return y; + } + if ( dflag === 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = w + ( z * dh12 ); + y[ ix ] = ( w * dh21 ) + z; + ix += strideX; + } + return y; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ ix ]; + x[ ix ] = ( w * dh11 ) + z; + y[ ix ] = -w + ( z * dh22 ); + ix += strideX; + } + return y; + } + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = ( w * dh11 ) + ( z * dh12 ); + y[ iy ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return y; + } + if ( dflag === 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = w + ( z * dh12 ); + y[ iy ] = ( w * dh21 ) + z; + ix += strideX; + iy += strideY; + } + return y; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = x[ ix ]; + z = y[ iy ]; + x[ ix ] = ( w * dh11 ) + z; + y[ iy ] = -w + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return y; +} + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js new file mode 100644 index 00000000000..fde49ad2efb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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( './drotm.native.js' ); + + +// MAIN // + +/** +* Applies a modified Givens 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 {Float64Array} param - parameters for the modified Givens transformation +* @returns {Float64Array} `y` +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); +* var y = new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ); +* var param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); +* +* drotm( 4, x, -1, 3, y, -2, 6, param ); +* // x => [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] +* // y => [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] +*/ +function drotm( N, x, strideX, offsetX, y, strideY, offsetY, param ) { + 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, param ); + return y; +} + + +// EXPORTS // + +module.exports = drotm; diff --git a/lib/node_modules/@stdlib/blas/base/drotm/manifest.json b/lib/node_modules/@stdlib/blas/base/drotm/manifest.json new file mode 100644 index 00000000000..c4a0be751a6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/manifest.json @@ -0,0 +1,417 @@ +{ + "options": { + "task": "build", + "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": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.f", + "./src/drotm_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.f", + "./src/drotm_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/drotm_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/argv-float64array" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/drotm.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/package.json b/lib/node_modules/@stdlib/blas/base/drotm/package.json new file mode 100644 index 00000000000..8a96562ae34 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/package.json @@ -0,0 +1,78 @@ +{ + "name": "@stdlib/blas/base/drotm", + "version": "0.0.0", + "description": "Apply a modified Givens transformation.", + "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", + "drotm", + "modified", + "givens", + "rotation", + "matrix", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "float64", + "float", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/Makefile b/lib/node_modules/@stdlib/blas/base/drotm/src/Makefile new file mode 100644 index 00000000000..bcf18aa4665 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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/drotm/src/addon.c b/lib/node_modules/@stdlib/blas/base/drotm/src/addon.c new file mode 100644 index 00000000000..5e26c60a565 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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/drotm.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_float64array.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, 6 ); + 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_FLOAT64ARRAY( env, param, paramlen, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 3 ); + API_SUFFIX(c_drotm)( N, X, strideX, Y, strideY, param ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c new file mode 100644 index 00000000000..f568ab1de61 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.c @@ -0,0 +1,136 @@ +/** +* @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/drotm.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param Y second input array +* @param strideY Y stride length +* @param param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { + CBLAS_INT ix; + CBLAS_INT iy; + double dflag; + double dh11; + double dh12; + double dh21; + double dh22; + CBLAS_INT i; + double w; + double z; + + dflag = param[ 0 ]; + if ( N <= 0 || dflag == -2.0 ) { + return; + } + if ( strideX == strideY && strideX > 0 ) { + ix = 0; + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * dh11 ) + ( z * dh12 ); + Y[ ix ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + } + return; + } + if ( dflag == 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = w + ( z * dh12 ); + Y[ ix ] = ( w * dh21 ) + z; + ix += strideX; + } + return; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ ix ]; + X[ ix ] = ( w * dh11 ) + z; + Y[ ix ] = -w + ( z * dh22 ); + ix += strideX; + } + return; + } + if ( strideX < 0 ) { + ix = ( 1 - N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = ( 1 - N ) * strideY; + } else { + iy = 0; + } + if ( dflag < 0.0 ) { + dh11 = param[ 1 ]; + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * dh11 ) + ( z * dh12 ); + Y[ iy ] = ( w * dh21 ) + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return; + } + if ( dflag == 0.0 ) { + dh12 = param[ 3 ]; + dh21 = param[ 2 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = w + ( z * dh12 ); + Y[ iy ] = ( w * dh21 ) + z; + ix += strideX; + iy += strideY; + } + return; + } + dh11 = param[ 1 ]; + dh22 = param[ 4 ]; + for ( i = 0; i < N; i++ ) { + w = X[ ix ]; + z = Y[ iy ]; + X[ ix ] = ( w * dh11 ) + z; + Y[ iy ] = -w + ( z * dh22 ); + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.f b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.f new file mode 100644 index 00000000000..10336f0cb8f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm.f @@ -0,0 +1,166 @@ +!> +! @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. +!< + +!> Applies a modified Givens plane rotation. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.12.0). Updated to "free form" Fortran 95. +! +! * Apply the modified givens transformation, H, to the 2 by N matrix `(DX**T)`, where `**T` indicates transpose. The elements of `DX` are in `(DX**T)` +! +! `DX(LX+I*INCX)`, `I = 0` to `N-1`, where `LX = 1` if `INCX .GE. 0`, else `LX = (-INCX)*N`, and similarly for `DY` using using `LY` and `INCY`. +! +! With `DPARAM(1)=DFLAG`, `H` has one of the following forms.. +! +! ``` +! DFLAG=-1.D0 DFLAG=0.D0 DFLAG=1.D0 DFLAG=-2.D0 +! +! (DH11 DH12) (1.D0 DH12) (DH11 1.D0) (1.D0 0.D0) +! H=( ) ( ) ( ) ( ) +! (DH21 DH22), (DH21 1.D0), (-1.D0 DH22), (0.D0 1.D0). +! ``` +! +! ## Authors +! +! * Univ. of Tennessee +! * Univ. of California Berkeley +! * Univ. of Colorado Denver +! * NAG Ltd. +! +! ## 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 - first input array +! @param {integer} strideX - `dx` stride length +! @param {Array} dy - second input array +! @param {integer} strideY - `dy` stride length +! @param {Array} dparam - parameters for the modified Givens transformation +!< +subroutine drotm( N, dx, strideX, dy, strideY, dparam ) + implicit none + ! .. + ! Internal parameters: + integer, parameter :: dp=kind(0.0d0) ! double-precision + ! .. + ! Scalar arguments: + integer :: strideX, strideY, N + ! .. + ! Array arguments: + real(dp) :: dparam(5), dx(*), dy(*) + ! .. + ! Local scalars: + real(dp) :: dflag, dh11, dh12, dh21, dh22, w, z + integer :: i, kx, ky, nsteps + ! .. + dflag = dparam(1) + if( n <= 0 .OR. ( dflag + 2.0d0 == 0.0d0 ) ) then + return + end if + if( strideX == strideY .AND. strideX > 0 ) then + nsteps = n * strideX + if( dflag < 0.0d0 ) then + dh11 = dparam( 2 ) + dh21 = dparam( 3 ) + dh12 = dparam( 4 ) + dh22 = dparam( 5 ) + do i = 1, nsteps, strideX + w = dx( i ) + z = dy( i ) + dx( i ) = ( dh11 * w ) + ( dh12 * z ) + dy( i ) = ( dh21 * w ) + ( dh22 * z ) + end do + else if( dflag == 0.0d0 ) then + dh12 = dparam( 4 ) + dh21 = dparam( 3 ) + do i = 1, nsteps, strideX + w = dx( i ) + z = dy( i ) + dx( i ) = w + ( z * dh12 ) + dy( i ) = ( w * dh21 ) + z + end do + else + dh11 = dparam( 2 ) + dh22 = dparam( 5 ) + do i = 1, nsteps, strideX + w = dx( i ) + z = dy( i ) + dx( i ) = ( dh11 * w ) + z + dy( i ) = -w + ( dh22 * z ) + end do + end if + else + if( strideX < 0 ) then + kx = ( ( 1 - n ) * strideX ) + 1 + else + kx = 1 + end if + if( strideY < 0 ) then + ky = ( ( 1 - n ) * strideY ) + 1 + else + ky = 1 + end if + if( dflag < 0.0d0 ) then + dh11 = dparam( 2 ) + dh21 = dparam( 3 ) + dh12 = dparam( 4 ) + dh22 = dparam( 5 ) + do i = 1, n + w = dx( kx ) + z = dy( ky ) + dx( kx ) = ( dh11 * w ) + ( dh12 * z ) + dy( ky ) = ( dh21 * w ) + ( dh22 * z ) + kx = kx + strideX + ky = ky + strideY + end do + else if( dflag == 0.0d0 ) then + dh12 = dparam( 4 ) + dh21 = dparam( 3 ) + do i = 1, n + w = dx( kx ) + z = dy( ky ) + dx( kx ) = w + ( z * dh12 ) + dy( ky ) = ( w * dh21 ) + z + kx = kx + strideX + ky = ky + strideY + end do + else + dh11 = dparam( 2 ) + dh22 = dparam( 5 ) + do i = 1, n + w = dx( kx ) + z = dy( ky ) + dx( kx ) = ( dh11 * w ) + z + dy( ky ) = -w + ( dh22 * z ) + kx = kx + strideX + ky = ky + strideY + end do + end if + end if + return +end subroutine drotm \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_cblas.c new file mode 100644 index 00000000000..5dc04f172c0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_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/drotm.h" +#include "stdlib/blas/base/drotm_cblas.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a modified Givens 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 param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { + API_SUFFIX(cblas_drotm)( N, X, strideX, Y, strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_f.c new file mode 100644 index 00000000000..b1c3bcb3583 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/src/drotm_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/drotm.h" +#include "stdlib/blas/base/drotm_fortran.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a modified Givens 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 param parameters for the modified Givens transformation +*/ +void API_SUFFIX(c_drotm)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param ) { + drotm( &N, X, &strideX, Y, &strideY, param ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.js b/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.js new file mode 100644 index 00000000000..24b0d69977a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.js @@ -0,0 +1,467 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var drotm = require( './../lib/drotm.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( drotm.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=1, sy=1)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -1.4, -1.3, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, -0.7, 2.3, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 1, y, 1, param ); + isApprox( t, x, xe[ i ], 5.0 ); + isApprox( t, y, ye[ i ], 5.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=2, sy=-2)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + param = [ 1.0, 5.0, 2.0, 0.0, -4.0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.5, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.8, 0.1, -3.1, 0.8, 4.8, -0.3, -1.5 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -2.6, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.5, -0.9, -1.8, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.6, -0.9, -2.1, 0.7, 2.9, 0.2, -3.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 2, y, -2, param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=-2, sy=1)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -1.5, 0.1, -1.4, 0.8, 3.6, -0.3, -1.9 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.5, 0.3, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.3, 0.9, -0.7, 1.9, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -2, y, 1, param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -1, y, -2, param ); + 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 param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 2, y, 1, param ); + + xe = new Float64Array( [ + -17.0, // 0 + 2.0, + -18.0, // 1 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 13.0, // 1 + 8.0, + 9.0, + 10.0 + ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var param; + 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([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 3, x, 1, y, 2, param ); + + xe = new Float64Array( [ + -17.0, // 0 + -22.0, // 1 + -27.0, // 2 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 7.0, + 12.0, // 1 + 9.0, + 16.0 // 2 + ] ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + out = drotm( x.length, x, 1, y, 1, param ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.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 ); + + drotm( -1, x, 1, y, 1, param ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drotm( 0, x, 1, y, 1, param ); + 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 param; + var xe; + var ye; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, + -0.5, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -2, y, 1, param ); + + xe = new Float64Array( [ + 3.3, // 1 + 0.1, + -2.0, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ] ); + ye = new Float64Array( [ + -0.5, // 0 + 0.3, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ] ); + + isApprox( t, x, xe, 10.0 ); + isApprox( t, y, ye, 10.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -1, y, -2, param ); + + xe = new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ); + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.native.js b/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.native.js new file mode 100644 index 00000000000..86cf7539503 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/test/test.drotm.native.js @@ -0,0 +1,480 @@ +/** +* @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 drotm = tryRequire( resolve( __dirname, './../lib/drotm.native.js' ) ); +var opts = { + 'skip': ( drotm instanceof Error ) +}; + + +// 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 ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', opts, function test( t ) { + t.strictEqual( drotm.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=1, sy=1)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -1.4, -1.3, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, -0.7, 2.3, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 1, y, 1, param ); + isApprox( t, x, xe[ i ], 5.0 ); + isApprox( t, y, ye[ i ], 5.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=2, sy=-2)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 1.0, 5.0, 2.0, 0.0, -4.0 ] ); + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.5, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.8, 0.1, -3.1, 0.8, 4.8, -0.3, -1.5 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -2.6, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.5, -0.9, -1.8, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.6, -0.9, -2.1, 0.7, 2.9, 0.2, -3.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 2, y, -2, param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=-2, sy=1)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -1.5, 0.1, -1.4, 0.8, 3.6, -0.3, -1.9 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.5, 0.3, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.3, 0.9, -0.7, 1.9, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -2, y, 1, param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + xe = [ + new Float64Array( [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -1, y, -2, param ); + 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 param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 2, y, 1, param ); + + xe = new Float64Array( [ + -17.0, // 0 + 2.0, + -18.0, // 1 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 13.0, // 1 + 8.0, + 9.0, + 10.0 + ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var param; + 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([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 3, x, 1, y, 2, param ); + + xe = new Float64Array( [ + -17.0, // 0 + -22.0, // 1 + -27.0, // 2 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 7.0, + 12.0, // 1 + 9.0, + 16.0 // 2 + ] ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + out = drotm( x.length, x, 1, y, 1, param ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.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 ); + + drotm( -1, x, 1, y, 1, param ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drotm( 0, x, 1, y, 1, param ); + 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 param; + var xe; + var ye; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, + -0.5, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -2, y, 1, param ); + + xe = new Float64Array( [ + 3.3, // 1 + 0.1, + -2.0, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ] ); + ye = new Float64Array( [ + -0.5, // 0 + 0.3, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ] ); + + isApprox( t, x, xe, 10.0 ); + isApprox( t, y, ye, 10.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -1, y, -2, param ); + + xe = new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ); + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/drotm/test/test.js b/lib/node_modules/@stdlib/blas/base/drotm/test/test.js new file mode 100644 index 00000000000..7f22e143523 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/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 drotm = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotm, '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 drotm.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 drotm = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( drotm, 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 drotm; + var main; + + main = require( './../lib/drotm.js' ); + + drotm = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( drotm, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.js new file mode 100644 index 00000000000..5bb2b80f7d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.js @@ -0,0 +1,562 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var drotm = 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 ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( drotm.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=1, sy=1)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -1.4, -1.3, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, -0.7, 2.3, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 1, ox[ i ], y, 1, oy[ i ], param ); + isApprox( t, x, xe[ i ], 5.0 ); + isApprox( t, y, ye[ i ], 5.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=2, sy=-2)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = [ 1.0, 5.0, 2.0, 0.0, -4.0 ]; + + 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( [ 3.5, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.8, 0.1, -3.1, 0.8, 4.8, -0.3, -1.5 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -2.6, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.5, -0.9, -1.8, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.6, -0.9, -2.1, 0.7, 2.9, 0.2, -3.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 2, ox[ i ], y, -2, oy[ i ], param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=-2, sy=1)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -1.5, 0.1, -1.4, 0.8, 3.6, -0.3, -1.9 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.5, 0.3, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.3, 0.9, -0.7, 1.9, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -2, ox[ i ], y, 1, oy[ i ], param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = [ 0.0, 0.0, 2.0, -3.0, 0.0 ]; + + ox = [ 0, 0, 1, 3 ]; + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -1, ox[ i ], y, -2, oy[ i ], param ); + 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 param; + var xe; + var ye; + 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 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 2, 0, y, 1, 0, param ); + + xe = new Float64Array( [ + -17.0, // 0 + 2.0, + -18.0, // 1 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 13.0, // 1 + 8.0, + 9.0, + 10.0 + ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var param; + var xe; + var ye; + 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, + 8.0, // 1 + 9.0, + 10.0 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 1, 1, y, 2, 0, param ); + + xe = new Float64Array( [ 1.0, -16.0, -21.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 10.0, 7.0, 14.0, 9.0, 10.0 ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var param; + 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([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 3, x, 1, 0, y, 2, 0, param ); + + xe = new Float64Array( [ + -17.0, // 0 + -22.0, // 1 + -27.0, // 2 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 7.0, + 12.0, // 1 + 9.0, + 16.0 // 2 + ] ); + + 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 param; + var xe; + var ye; + 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, // 0 + 8.0, + 9.0, // 1 + 10.0 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 1, 0, y, 2, 1, param ); + + xe = new Float64Array( [ -20.0, -25.0, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 9.0, 8.0, 13.0, 10.0 ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input array', function test( t ) { + var param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + out = drotm( x.length, x, 1, 0, y, 1, 0, param ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.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 ); + + drotm( -1, x, 1, 0, y, 1, 0, param ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drotm( 0, x, 1, 0, y, 1, 0, param ); + 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 param; + var xe; + var ye; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, + -0.5, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -2, 2, y, 1, 0, param ); + + xe = new Float64Array( [ + 3.3, // 1 + 0.1, + -2.0, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ] ); + ye = new Float64Array( [ + -0.5, // 0 + 0.3, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ] ); + + isApprox( t, x, xe, 10.0 ); + isApprox( t, y, ye, 10.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -1, 1, y, -2, 2, param ); + + xe = new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ); + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.native.js new file mode 100644 index 00000000000..72e01f12b01 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drotm/test/test.ndarray.native.js @@ -0,0 +1,571 @@ +/** +* @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 drotm = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( drotm instanceof Error ) +}; + + +// 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 ) { + t.ok( true, __filename ); + t.strictEqual( typeof drotm, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', opts, function test( t ) { + t.strictEqual( drotm.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=1, sy=1)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, 2.8, -1.4, -1.3, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.7, -0.7, 2.3, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 1, ox[ i ], y, 1, oy[ i ], param ); + isApprox( t, x, xe[ i ], 5.0 ); + isApprox( t, y, ye[ i ], 5.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=2, sy=-2)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 1.0, 5.0, 2.0, 0.0, -4.0 ] ); + + 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( [ 3.5, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.8, 0.1, -3.1, 0.8, 4.8, -0.3, -1.5 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -2.6, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.5, -0.9, -1.8, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -1.6, -0.9, -2.1, 0.7, 2.9, 0.2, -3.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, 2, ox[ i ], y, -2, oy[ i ], param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a modified Givens plane rotation (sx=-2, sy=1)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ 3.3, 0.1, -2.0, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -1.5, 0.1, -1.4, 0.8, 3.6, -0.3, -1.9 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.5, 0.3, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ -0.3, 0.9, -0.7, 1.9, -0.6, 0.2, 0.8 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -2, ox[ i ], y, 1, oy[ i ], param ); + isApprox( t, x, xe[ i ], 10.0 ); + isApprox( t, y, ye[ i ], 10.0 ); + t.strictEqual( out, y, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function applies a plane rotation (sx=-1, sy=-2)', opts, function test( t ) { + var param; + var xbuf; + var ybuf; + var out; + var ox; + var oy; + var xe; + var ye; + var N; + var x; + var y; + var i; + + N = [ 0, 1, 2, 4 ]; + + xbuf = [ 0.6, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ]; + ybuf = [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ]; + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + ox = [ 0, 0, 1, 3 ]; + 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.9, 0.1, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ), + new Float64Array( [ -0.9, -0.8, 1.3, -1.6, 0.9, -0.3, -0.4 ] ) + ]; + ye = [ + new Float64Array( [ 0.5, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.3, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ), + new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ] ) + ]; + + for ( i = 0; i < N.length; i++ ) { + x = new Float64Array( xbuf ); + y = new Float64Array( ybuf ); + out = drotm( N[ i ], x, -1, ox[ i ], y, -2, oy[ i ], param ); + 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 param; + var xe; + var ye; + 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 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 2, 0, y, 1, 0, param ); + + xe = new Float64Array( [ + -17.0, // 0 + 2.0, + -18.0, // 1 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 13.0, // 1 + 8.0, + 9.0, + 10.0 + ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', opts, function test( t ) { + var param; + var xe; + var ye; + 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, + 8.0, // 1 + 9.0, + 10.0 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 1, 1, y, 2, 0, param ); + + xe = new Float64Array( [ 1.0, -16.0, -21.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 10.0, 7.0, 14.0, 9.0, 10.0 ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var param; + 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([ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 3, x, 1, 0, y, 2, 0, param ); + + xe = new Float64Array( [ + -17.0, // 0 + -22.0, // 1 + -27.0, // 2 + 4.0, + 5.0 + ] ); + ye = new Float64Array( [ + 8.0, // 0 + 7.0, + 12.0, // 1 + 9.0, + 16.0 // 2 + ] ); + + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` offset', opts, function test( t ) { + var param; + var xe; + var ye; + 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, // 0 + 8.0, + 9.0, // 1 + 10.0 + ]); + + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, 1, 0, y, 2, 1, param ); + + xe = new Float64Array( [ -20.0, -25.0, 3.0, 4.0, 5.0 ] ); + ye = new Float64Array( [ 6.0, 9.0, 8.0, 13.0, 10.0 ] ); + + isApprox( t, x, xe, 2.0 ); + isApprox( t, y, ye, 2.0 ); + + t.end(); +}); + +tape( 'the function returns a reference to the second input array', opts, function test( t ) { + var param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + out = drotm( x.length, x, 1, 0, y, 1, 0, param ); + + 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 param; + 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 ] ); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.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 ); + + drotm( -1, x, 1, 0, y, 1, 0, param ); + t.deepEqual( x, xe, 'returns expected value' ); + t.deepEqual( y, ye, 'returns expected value' ); + + drotm( 0, x, 1, 0, y, 1, 0, param ); + 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 param; + var xe; + var ye; + var x; + var y; + + x = new Float64Array([ + 0.6, // 1 + 0.1, + -0.5, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ]); + y = new Float64Array([ + 0.5, // 0 + -0.9, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -2, 2, y, 1, 0, param ); + + xe = new Float64Array( [ + 3.3, // 1 + 0.1, + -2.0, // 0 + 0.8, + 0.9, + -0.3, + -0.4 + ] ); + ye = new Float64Array( [ + -0.5, // 0 + 0.3, // 1 + 0.3, + 0.7, + -0.6, + 0.2, + 0.8 + ] ); + + isApprox( t, x, xe, 10.0 ); + isApprox( t, y, ye, 10.0 ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var param; + var xe; + var ye; + 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 + ]); + param = new Float64Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); + + drotm( 2, x, -1, 1, y, -2, 2, param ); + + xe = new Float64Array( [ -0.9, -0.8, -0.5, 0.8, 0.9, -0.3, -0.4 ] ); + ye = new Float64Array( [ 1.7, -0.9, 0.5, 0.7, -0.6, 0.2, 0.8 ] ); + + isApprox( t, x, xe, 5.0 ); + isApprox( t, y, ye, 5.0 ); + + t.end(); +});