From 7155e52806a52b6918d0de96ea2fe5da2c19bcd0 Mon Sep 17 00:00:00 2001 From: Rutam <138517416+performant23@users.noreply.github.com> Date: Thu, 4 Apr 2024 03:13:33 +0530 Subject: [PATCH] feat: add `blas/base/zswap` PR-URL: https://github.com/stdlib-js/stdlib/pull/2075 Closes: https://github.com/stdlib-js/stdlib/issues/2047 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Ref: https://netlib.org/lapack/explore-html-3.6.1/d2/df9/group__complex16__blas__level1_ga13a187010a0cae1fef2820072404e857.html#ga13a187010a0cae1fef2820072404e857 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- .../@stdlib/blas/base/zswap/README.md | 290 ++++++++++++ .../blas/base/zswap/benchmark/benchmark.js | 115 +++++ .../base/zswap/benchmark/benchmark.native.js | 120 +++++ .../base/zswap/benchmark/benchmark.ndarray.js | 115 +++++ .../benchmark/benchmark.ndarray.native.js | 120 +++++ .../blas/base/zswap/benchmark/c/Makefile | 129 ++++++ .../base/zswap/benchmark/c/benchmark.length.c | 161 +++++++ .../base/zswap/benchmark/fortran/Makefile | 141 ++++++ .../benchmark/fortran/benchmark.length.f | 217 +++++++++ .../@stdlib/blas/base/zswap/binding.gyp | 265 +++++++++++ .../@stdlib/blas/base/zswap/docs/repl.txt | 155 +++++++ .../blas/base/zswap/docs/types/index.d.ts | 183 ++++++++ .../blas/base/zswap/docs/types/test.ts | 249 +++++++++++ .../blas/base/zswap/examples/c/Makefile | 129 ++++++ .../blas/base/zswap/examples/c/example.c | 35 ++ .../@stdlib/blas/base/zswap/examples/index.js | 39 ++ .../@stdlib/blas/base/zswap/include.gypi | 70 +++ .../zswap/include/stdlib/blas/base/zswap.h | 41 ++ .../include/stdlib/blas/base/zswap_cblas.h | 41 ++ .../include/stdlib/blas/base/zswap_fortran.h | 41 ++ .../@stdlib/blas/base/zswap/lib/index.js | 108 +++++ .../@stdlib/blas/base/zswap/lib/main.js | 35 ++ .../@stdlib/blas/base/zswap/lib/native.js | 35 ++ .../@stdlib/blas/base/zswap/lib/ndarray.js | 105 +++++ .../blas/base/zswap/lib/ndarray.native.js | 87 ++++ .../@stdlib/blas/base/zswap/lib/zswap.js | 125 ++++++ .../blas/base/zswap/lib/zswap.native.js | 77 ++++ .../@stdlib/blas/base/zswap/manifest.json | 169 +++++++ .../@stdlib/blas/base/zswap/package.json | 83 ++++ .../@stdlib/blas/base/zswap/src/Makefile | 70 +++ .../@stdlib/blas/base/zswap/src/addon.c | 45 ++ .../@stdlib/blas/base/zswap/src/zswap.c | 76 ++++ .../@stdlib/blas/base/zswap/src/zswap.f | 99 +++++ .../@stdlib/blas/base/zswap/src/zswap_cblas.c | 33 ++ .../@stdlib/blas/base/zswap/src/zswap_f.c | 33 ++ .../@stdlib/blas/base/zswap/test/test.js | 82 ++++ .../blas/base/zswap/test/test.ndarray.js | 407 +++++++++++++++++ .../base/zswap/test/test.ndarray.native.js | 416 ++++++++++++++++++ .../blas/base/zswap/test/test.zswap.js | 372 ++++++++++++++++ .../blas/base/zswap/test/test.zswap.native.js | 381 ++++++++++++++++ 40 files changed, 5494 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/include/stdlib/blas/base/zswap.h create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/include/stdlib/blas/base/zswap_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/include/stdlib/blas/base/zswap_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/zswap.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/zswap.f create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/zswap_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/zswap_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.js create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.native.js diff --git a/lib/node_modules/@stdlib/blas/base/zswap/README.md b/lib/node_modules/@stdlib/blas/base/zswap/README.md new file mode 100644 index 000000000000..4f3e2a982905 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/README.md @@ -0,0 +1,290 @@ + + +# zswap + +> Interchange two complex double-precision floating-point vectors. + +
+ +This BLAS level 1 routine interchanges complex double-precision floating-point vectors `x` and `y`. The operation is performed in-place, with `x` being overwritten with the values from `y`, and `y` being overwritten with the values from `x`. + +
+ + + +
+ +## Usage + +```javascript +var zswap = require( '@stdlib/blas/base/zswap' ); +``` + +#### zswap( N, x, strideX, y, strideY ) + +Interchange two complex double-precision floating-point vectors. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +zswap( x.length, x, 1, y, 1 ); + +var z = y.get( 0 ); +// returns + +var re = real( z ); +// returns 1.0 + +var im = imag( z ); +// returns 2.0 + +z = x.get( 0 ); +// returns + +re = real( z ); +// returns 0.0 + +im = imag( z ); +// returns 0.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input [`Complex128Array`][@stdlib/array/complex128]. +- **strideX**: index increment for `x`. +- **y**: second input [`Complex128Array`][@stdlib/array/complex128]. +- **strideY**: index increment for `y`. + +The `N` and stride parameters determine how values from `x` are interchanged with values from `y`. For example, to interchange in reverse order every other value in `x` into the first `N` elements of `y`, + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +zswap( 2, x, -2, y, 1 ); + +var z = y.get( 0 ); +// returns + +var re = real( z ); +// returns 5.0 + +var im = imag( z ); +// returns 6.0 + +z = x.get( 0 ); +// returns + +re = real( z ); +// returns 0.0 + +im = imag( z ); +// returns 0.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); + +// Initial arrays... +var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var y0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create offset views... +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element + +// Interchange in reverse order every other value from `x1` into `y1`... +zswap( 2, x1, -2, y1, 1 ); + +var z = y0.get( 2 ); +// returns + +var re = real( z ); +// returns 7.0 + +var im = imag( z ); +// returns 8.0 + +z = x0.get( 1 ); +// returns + +re = real( z ); +// returns 0.0 + +im = imag( z ); +// returns 0.0 +``` + +#### zswap.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Interchange two complex double-precision floating-point vectors using alternative indexing semantics. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +zswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + +var z = y.get( 0 ); +// returns + +var re = real( z ); +// returns 1.0 + +var im = imag( z ); +// returns 2.0 + +z = x.get( 0 ); +// returns + +re = real( z ); +// returns 0.0 + +im = imag( z ); +// returns 0.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 interchange every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`, and so on, + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var real = require( '@stdlib/complex/real' ); +var imag = require( '@stdlib/complex/imag' ); + +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +zswap.ndarray( 2, x, 2, 1, y, -1, y.length-1 ); + +var z = y.get( y.length-1 ); +// returns + +var re = real( z ); +// returns 3.0 + +var im = imag( z ); +// returns 4.0 + +z = x.get( x.length-1 ); +// returns + +re = real( z ); +// returns 0.0 + +im = imag( z ); +// returns 0.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions leave `x` and `y` unchanged. +- `zswap()` corresponds to the [BLAS][blas] level 1 function [`zswap`][zswap]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float64' ); +var zswap = require( '@stdlib/blas/base/zswap' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.get( 0 ).toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.get( 0 ).toString() ); + +// Swap elements in `x` into `y` starting from the end of `y`: +zswap( x.length, x, 1, y, -1 ); +console.log( x.get( x.length-1 ).toString() ); +console.log( y.get( y.length-1 ).toString() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.js new file mode 100644 index 000000000000..8f41e2840a4b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var pkg = require( './../package.json' ).name; +var zswap = require( './../lib/zswap.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 viewY; + var x; + var y; + + x = uniform( len*2, -100.0, 100.0, options ); + x = new Complex128Array( x.buffer ); + + y = new Complex128Array( len ); + viewY = reinterpret( y, 0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + for ( i = 0; i < len*2; i++ ) { + viewY[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + zswap( x.length, x, 1, y, 1 ); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + 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/zswap/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.native.js new file mode 100644 index 000000000000..601d0233ba1c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.native.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var zswap = tryRequire( resolve( __dirname, './../lib/zswap.native.js' ) ); +var opts = { + 'skip': ( zswap 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 viewY; + var x; + var y; + + x = uniform( len*2, -100.0, 100.0, options ); + x = new Complex128Array( x.buffer ); + + y = new Complex128Array( len ); + viewY = reinterpret( y, 0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + for ( i = 0; i < len*2; i++ ) { + viewY[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + zswap( x.length, x, 1, y, 1 ); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + 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/zswap/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..9111300c1c3d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var pkg = require( './../package.json' ).name; +var zswap = 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 viewY; + var x; + var y; + + x = uniform( len*2, -100.0, 100.0, options ); + x = new Complex128Array( x.buffer ); + + y = new Complex128Array( len ); + viewY = reinterpret( y, 0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + for ( i = 0; i < len*2; i++ ) { + viewY[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + zswap( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + 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/zswap/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..61bbe36efec8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var zswap = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( zswap 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 viewY; + var x; + var y; + + x = uniform( len*2, -100.0, 100.0, options ); + x = new Complex128Array( x.buffer ); + + y = new Complex128Array( len ); + viewY = reinterpret( y, 0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + for ( i = 0; i < len*2; i++ ) { + viewY[ i ] = 0.0; + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + zswap( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( viewY[ i%( len*2 ) ] ) ) { + 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/zswap/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/Makefile new file mode 100644 index 000000000000..39f21310e425 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/Makefile @@ -0,0 +1,129 @@ +#/ +# @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 source files: +c_src := ../../src/zswap.c + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..357e107241ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/c/benchmark.length.c @@ -0,0 +1,161 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/** +* Benchmark `zswap`. +*/ +#include "stdlib/blas/base/zswap.h" +#include +#include +#include +#include +#include + +#define NAME "zswap" +#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; + double *y; + double t; + int i; + + x = (double *) malloc( len*2 * sizeof( double ) ); + y = (double *) malloc( len*2 * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*10000.0 ) - 5000.0; + x[ i+1 ] = ( rand_double()*10000.0 ) - 5000.0; + y[ i ] = 0.0; + y[ i+1 ] = 0.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_zswap( len, (void *)x, 1, (void *)y, 1 ); + 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" ); + } + free( x ); + free( y ); + + 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/zswap/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/fortran/Makefile new file mode 100644 index 000000000000..bcb95e5a9203 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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/zswap.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/zswap/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/fortran/benchmark.length.f new file mode 100644 index 000000000000..14347bf53f4a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/benchmark/fortran/benchmark.length.f @@ -0,0 +1,217 @@ +!> +! @license Apache-2.0 +! +! Copyright (c) 2024 The Stdlib Authors. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. +!< + +!> Benchmark `zswap`. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'zswap' ! 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 zswap( N, zx, strideX, zy, strideY ) + complex(kind=kind(0.0d0)) :: zx(:), zy(:) + integer :: strideX, strideY, N + end subroutine zswap + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, len + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2 + integer :: i + ! .. + ! Local arrays: + complex(kind=kind(0.0d0)), allocatable :: x(:), y(:) + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time, cmplx + ! .. + ! Allocate arrays: + allocate( x(len), y(len) ) + ! .. + do i = 1, len + call random_number( r1 ) + call random_number( r2 ) + x( i ) = cmplx( (r1*10000.0d0)-5000.0d0, (r2*10000.0d0)-5000.0d0, kind=kind(0.0d0) ) + y( i ) = ( 0.0d0, 0.0d0 ) + end do + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call zswap( len, x, 1, y, 1 ); + 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/zswap/binding.gyp b/lib/node_modules/@stdlib/blas/base/zswap/binding.gyp new file mode 100644 index 000000000000..02a2799da097 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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/zswap/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/zswap/docs/repl.txt new file mode 100644 index 000000000000..7213881cc5ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/docs/repl.txt @@ -0,0 +1,155 @@ + +{{alias}}( N, x, strideX, y, strideY ) + Interchanges two complex double-precision floating-point vectors. + + The `N` and stride parameters determine how values from `x` are + swapped with values from `y`. + + 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: Complex128Array + First input array. + + strideX: integer + Index increment for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + y: Complex128Array + Input array `y`. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] ); + > {{alias}}( x.length, x, 1, y, 1 ); + > var z = y.get( 0 ); + > var re = {{alias:@stdlib/complex/real}}( z ) + 1.0 + > var im = {{alias:@stdlib/complex/imag}}( z ) + 2.0 + > z = x.get( 0 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 6.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 7.0 + + // Advanced indexing: + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + > {{alias}}( 2, x, -2, y, 1 ); + > z = y.get( 0 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 5.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 6.0 + > z = x.get( 0 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 0.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 0.0 + + // Using typed array views: + > var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + > var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 1, x1, -1, y1, 1 ); + > z = y0.get( 1 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 3.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 4.0 + > z = x0.get( 1 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 0.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 0.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Interchanges two complex double-precision floating-point vectors using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on + starting indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex128Array + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Complex128Array + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + y: Complex128Array + Input array `y`. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = new {{alias:@stdlib/array/complex128}}( [ 6.0, 7.0, 8.0, 9.0 ] ); + > {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ); + > var z = y.get( 0 ); + > var re = {{alias:@stdlib/complex/real}}( z ) + 1.0 + > var im = {{alias:@stdlib/complex/imag}}( z ) + 2.0 + > z = x.get( 0 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 6.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 7.0 + + // Advanced indexing: + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + > y = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + > {{alias}}.ndarray( 2, x, 2, 1, y, -1, y.length-1 ); + > z = y.get( y.length-1 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 3.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 4.0 + > z = x.get( 1 ); + > re = {{alias:@stdlib/complex/real}}( z ) + 0.0 + > im = {{alias:@stdlib/complex/imag}}( z ) + 0.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/zswap/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/zswap/docs/types/index.d.ts new file mode 100644 index 000000000000..0c5885f55bdb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/docs/types/index.d.ts @@ -0,0 +1,183 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Complex128Array } from '@stdlib/types/array'; + +/** +* Interface describing `zswap`. +*/ +interface Routine { + /** + * Interchanges two complex double-precision floating-point vectors. + * + * @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 + * @returns `y` + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * var real = require( '@stdlib/complex/real' ); + * var imag = require( '@stdlib/complex/imag' ); + * + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + * + * zswap( x.length, x, 1, y, 1 ); + * + * var z = y.get( 0 ); + * // returns + * + * var re = real( z ); + * // returns 1.0 + * + * var im = imag( z ); + * // returns 2.0 + * + * z = x.get( 0 ); + * // returns + * + * re = real( z ); + * // returns 7.0 + * + * im = imag( z ); + * // returns 8.0 + */ + ( N: number, x: Complex128Array, strideX: number, y: Complex128Array, strideY: number ): Complex128Array; + + /** + * Interchanges two complex double-precision floating-point vectors 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` + * @returns `y` + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * var real = require( '@stdlib/complex/real' ); + * var imag = require( '@stdlib/complex/imag' ); + * + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + * + * zswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * + * var z = y.get( 0 ); + * // returns + * + * var re = real( z ); + * // returns 1.0 + * + * var im = imag( z ); + * // returns 2.0 + * + * z = x.get( 0 ); + * // returns + * + * re = real( z ); + * // returns 7.0 + * + * im = imag( z ); + * // returns 8.0 + */ + ndarray( N: number, x: Complex128Array, strideX: number, offsetX: number, y: Complex128Array, strideY: number, offsetY: number ): Complex128Array; +} + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @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 +* @returns `y` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, y, 1 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ +declare var zswap: Routine; + + +// EXPORTS // + +export = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/zswap/docs/types/test.ts new file mode 100644 index 000000000000..350d79a02cca --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/docs/types/test.ts @@ -0,0 +1,249 @@ +/* +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +import zswap = require( './index' ); + + +// TESTS // + +// The function returns a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap( x.length, x, 1, y, 1 ); // $ExpectType Complex128Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap( '10', x, 1, y, 1 ); // $ExpectError + zswap( true, x, 1, y, 1 ); // $ExpectError + zswap( false, x, 1, y, 1 ); // $ExpectError + zswap( null, x, 1, y, 1 ); // $ExpectError + zswap( undefined, x, 1, y, 1 ); // $ExpectError + zswap( [], x, 1, y, 1 ); // $ExpectError + zswap( {}, x, 1, y, 1 ); // $ExpectError + zswap( ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap( x.length, 10, 1, y, 1 ); // $ExpectError + zswap( x.length, '10', 1, y, 1 ); // $ExpectError + zswap( x.length, true, 1, y, 1 ); // $ExpectError + zswap( x.length, false, 1, y, 1 ); // $ExpectError + zswap( x.length, null, 1, y, 1 ); // $ExpectError + zswap( x.length, undefined, 1, y, 1 ); // $ExpectError + zswap( x.length, [ '1' ], 1, y, 1 ); // $ExpectError + zswap( x.length, {}, 1, y, 1 ); // $ExpectError + zswap( x.length, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap( x.length, x, '10', y, 1 ); // $ExpectError + zswap( x.length, x, true, y, 1 ); // $ExpectError + zswap( x.length, x, false, y, 1 ); // $ExpectError + zswap( x.length, x, null, y, 1 ); // $ExpectError + zswap( x.length, x, undefined, y, 1 ); // $ExpectError + zswap( x.length, x, [], y, 1 ); // $ExpectError + zswap( x.length, x, {}, y, 1 ); // $ExpectError + zswap( x.length, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + zswap( x.length, x, 1, 10, 1 ); // $ExpectError + zswap( x.length, x, 1, '10', 1 ); // $ExpectError + zswap( x.length, x, 1, true, 1 ); // $ExpectError + zswap( x.length, x, 1, false, 1 ); // $ExpectError + zswap( x.length, x, 1, null, 1 ); // $ExpectError + zswap( x.length, x, 1, undefined, 1 ); // $ExpectError + zswap( x.length, x, 1, [ '1' ], 1 ); // $ExpectError + zswap( x.length, x, 1, {}, 1 ); // $ExpectError + zswap( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap( x.length, x, 1, y, '10' ); // $ExpectError + zswap( x.length, x, 1, y, true ); // $ExpectError + zswap( x.length, x, 1, y, false ); // $ExpectError + zswap( x.length, x, 1, y, null ); // $ExpectError + zswap( x.length, x, 1, y, undefined ); // $ExpectError + zswap( x.length, x, 1, y, [] ); // $ExpectError + zswap( x.length, x, 1, y, {} ); // $ExpectError + zswap( x.length, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap(); // $ExpectError + zswap( x.length ); // $ExpectError + zswap( x.length, x ); // $ExpectError + zswap( x.length, x, 1 ); // $ExpectError + zswap( x.length, x, 1, y ); // $ExpectError + zswap( x.length, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType Complex128Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, [ '1' ], 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + const y = new Complex128Array( 10 ); + + zswap.ndarray(); // $ExpectError + zswap.ndarray( x.length ); // $ExpectError + zswap.ndarray( x.length, x ); // $ExpectError + zswap.ndarray( x.length, x, 1 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + zswap.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/zswap/examples/c/Makefile new file mode 100644 index 000000000000..4cd6de77733b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/examples/c/Makefile @@ -0,0 +1,129 @@ +#/ +# @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 source files: +c_src := ../../src/zswap.c + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles C source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler +# @param {string} CFLAGS - C compiler flags +# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) -I ../../include -o $@ $(c_src) $< -lm + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/zswap/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/zswap/examples/c/example.c new file mode 100644 index 000000000000..d081ade41e97 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/examples/c/example.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/zswap.h" +#include + +int main( void ) { + // Create strided arrays: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Swap elements: + c_zswap( 4, (void *)x, 1, (void *)y, -1 ); + + // Print the result: + for ( int i = 0; i < 4; i++ ) { + printf( "x[ %i ] = %f + %fj\n", i, x[ i*2 ], x[ ( i*2 )+1 ] ); + printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ ( i*2 )+1 ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/examples/index.js b/lib/node_modules/@stdlib/blas/base/zswap/examples/index.js new file mode 100644 index 000000000000..c8e13f29eea3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float64' ); +var zswap = require( './../lib' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.get( 0 ).toString() ); + +var y = filledarrayBy( 10, 'complex128', rand ); +console.log( y.get( 0 ).toString() ); + +// Swap elements in `x` into `y` starting from the end of `y`: +zswap( x.length, x, 1, y, -1 ); +console.log( x.get( x.length-1 ).toString() ); +console.log( y.get( y.length-1 ).toString() ); diff --git a/lib/node_modules/@stdlib/blas/base/zswap/include.gypi b/lib/node_modules/@stdlib/blas/base/zswap/include.gypi new file mode 100644 index 000000000000..497aeca15320 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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)', + ' +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* var zswap = require( '@stdlib/blas/base/zswap' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, 0, y, 1, 0 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var zswap; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + zswap = main; +} else { + zswap = tmp; +} + + +// EXPORTS // + +module.exports = zswap; + +// exports: { "ndarray": "zswap.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/main.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/main.js new file mode 100644 index 000000000000..5b8d1611eb60 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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 zswap = require( './zswap.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( zswap, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/native.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/native.js new file mode 100644 index 000000000000..598cf955d1a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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 zswap = require( './zswap.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( zswap, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.js new file mode 100644 index 000000000000..e0c3178ba1a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/lib/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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); + + +// MAIN // + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {Complex128Array} `y` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, 0, y, 1, 0 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ +function zswap( N, x, strideX, offsetX, y, strideY, offsetY ) { + var viewX; + var viewY; + var tmp; + var sx; + var sy; + var ix; + var iy; + var i; + + if ( N <= 0 ) { + return y; + } + viewX = reinterpret( x, 0 ); + viewY = reinterpret( y, 0 ); + sx = strideX * 2; + sy = strideY * 2; + ix = offsetX * 2; + iy = offsetY * 2; + for ( i = 0; i < N; i++ ) { + tmp = viewX[ ix ]; + viewX[ ix ] = viewY[ iy ]; + viewY[ iy ] = tmp; + + tmp = viewX[ ix+1 ]; + viewX[ ix+1 ] = viewY[ iy+1 ]; + viewY[ iy+1 ] = tmp; + + ix += sx; + iy += sy; + } + return y; +} + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.native.js new file mode 100644 index 000000000000..91d3f038c9b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/lib/ndarray.native.js @@ -0,0 +1,87 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {Complex128Array} `y` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, 0, y, 1, 0 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ +function zswap( N, x, strideX, offsetX, y, strideY, offsetY ) { + var viewX; + var viewY; + + offsetX = minViewBufferIndex( N, strideX, offsetX ); + offsetY = minViewBufferIndex( N, strideY, offsetY ); + + viewX = reinterpret( x, offsetX ); + viewY = reinterpret( y, offsetY ); + + addon( N, viewX, strideX, viewY, strideY ); + return y; +} + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.js new file mode 100644 index 000000000000..850d500f4ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.js @@ -0,0 +1,125 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); + + +// MAIN // + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @returns {Complex128Array} `y` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, y, 1 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ +function zswap( N, x, strideX, y, strideY ) { + var viewX; + var viewY; + var tmp; + var sx; + var sy; + var ix; + var iy; + var i; + var j; + + if ( N <= 0 ) { + return y; + } + viewX = reinterpret( x, 0 ); + viewY = reinterpret( y, 0 ); + if ( strideX === 1 && strideY === 1 ) { + for ( i = 0; i < N*2; i += 2 ) { + tmp = viewX[ i ]; + viewX[ i ] = viewY[ i ]; + viewY[ i ] = tmp; + + j = i + 1; + tmp = viewX[ j ]; + viewX[ j ] = viewY[ j ]; + viewY[ j ] = tmp; + } + return y; + } + if ( strideX < 0 ) { + ix = 2 * ( 1-N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = 2 * ( 1-N ) * strideY; + } else { + iy = 0; + } + sx = strideX * 2; + sy = strideY * 2; + for ( i = 0; i < N; i++ ) { + tmp = viewX[ ix ]; + viewX[ ix ] = viewY[ iy ]; + viewY[ iy ] = tmp; + + tmp = viewX[ ix+1 ]; + viewX[ ix+1 ] = viewY[ iy+1 ]; + viewY[ iy+1 ] = tmp; + + ix += sx; + iy += sy; + } + return y; +} + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.native.js b/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.native.js new file mode 100644 index 000000000000..b4e667884571 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/lib/zswap.native.js @@ -0,0 +1,77 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Complex128Array} y - second input array +* @param {integer} strideY - `y` stride length +* @returns {Complex128Array} `y` +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var real = require( '@stdlib/complex/real' ); +* var imag = require( '@stdlib/complex/imag' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var y = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* zswap( x.length, x, 1, y, 1 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = real( z ); +* // returns 1.0 +* +* var im = imag( z ); +* // returns 2.0 +* +* z = x.get( 0 ); +* // returns +* +* re = real( z ); +* // returns 7.0 +* +* im = imag( z ); +* // returns 8.0 +*/ +function zswap( N, x, strideX, y, strideY ) { + var viewX = reinterpret( x, 0 ); + var viewY = reinterpret( y, 0 ); + addon( N, viewX, strideX, viewY, strideY ); + return y; +} + + +// EXPORTS // + +module.exports = zswap; diff --git a/lib/node_modules/@stdlib/blas/base/zswap/manifest.json b/lib/node_modules/@stdlib/blas/base/zswap/manifest.json new file mode 100644 index 000000000000..c94a3fc70f40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/manifest.json @@ -0,0 +1,169 @@ +{ + "options": { + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/zswap.f", + "./src/zswap_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/zswap_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/zswap.f", + "./src/zswap_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/zswap_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/zswap_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/zswap.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex128array" + ] + }, + { + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/zswap.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/package.json b/lib/node_modules/@stdlib/blas/base/zswap/package.json new file mode 100644 index 000000000000..836dfd8146b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/package.json @@ -0,0 +1,83 @@ +{ + "name": "@stdlib/blas/base/zswap", + "version": "0.0.0", + "description": "Interchanges two complex double-precision floating-point vectors.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "linear", + "algebra", + "subroutines", + "zswap", + "swap", + "copy", + "interchange", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex128", + "float", + "float64", + "double", + "float64array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/src/Makefile b/lib/node_modules/@stdlib/blas/base/zswap/src/Makefile new file mode 100644 index 000000000000..bcf18aa46655 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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/zswap/src/addon.c b/lib/node_modules/@stdlib/blas/base/zswap/src/addon.c new file mode 100644 index 000000000000..d1382991be3a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/src/addon.c @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/zswap.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_complex128array.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, 5 ); + 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_STRIDED_COMPLEX128ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, Y, N, strideY, argv, 3 ); + c_zswap( N, (void *)X, strideX, (void *)Y, strideY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.c b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.c new file mode 100644 index 000000000000..ea0e25895d57 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.c @@ -0,0 +1,76 @@ +/** +* @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/zswap.h" + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @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 +*/ +void c_zswap( const int N, void *X, const int strideX, void *Y, const int strideY ) { + double *x = (double *)X; + double *y = (double *)Y; + double tmp; + int ix; + int iy; + int i; + + if ( N <= 0 ) { + return; + } + if ( strideX == 1 && strideY == 1 ) { + for ( i = 0; i < N*2; i += 2 ) { + tmp = x[ i ]; + x[ i ] = y[ i ]; + y[ i ] = tmp; + + tmp = x[ i+1 ]; + x[ i+1 ] = y[ i+1 ]; + y[ i+1 ] = tmp; + } + return; + } + if ( strideX < 0 ) { + ix = 2 * ( 1-N ) * strideX; + } else { + ix = 0; + } + if ( strideY < 0 ) { + iy = 2 * ( 1-N ) * strideY; + } else { + iy = 0; + } + for ( i = 0; i < N; i++ ) { + tmp = x[ ix ]; + x[ ix ] = y[ iy ]; + y[ iy ] = tmp; + + tmp = x[ ix+1 ]; + x[ ix+1 ] = y[ iy+1 ]; + y[ iy+1 ] = tmp; + + ix += strideX * 2; + iy += strideY * 2; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.f b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.f new file mode 100644 index 000000000000..6ce96a469c48 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap.f @@ -0,0 +1,99 @@ +!> +! @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. +!< + +!> Interchanges two complex double-precision floating-point vectors. +! +! ## Notes +! +! * Modified version of reference BLAS level1 routine (version 3.9.0). Updated to "free form" Fortran 95. +! +! ## Authors +! +! * Univ. of Tennessee +! * Univ. of California Berkeley +! * Univ. of Colorado Denver +! * NAG Ltd. +! +! ## History +! +! * Jack Dongarra, linpack, 3/11/78. +! +! - modified 12/3/93, array(1) declarations changed to array(*) +! +! ## License +! +! From : +! +! > The reference BLAS is a freely-available software package. It is available from netlib via anonymous ftp and the World Wide Web. Thus, it can be included in commercial software packages (and has been). We only ask that proper credit be given to the authors. +! > +! > Like all software, it is copyrighted. It is not trademarked, but we do ask the following: +! > +! > * If you modify the source for these routines we ask that you change the name of the routine and comment the changes made to the original. +! > +! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. +! +! @param {integer} N - number of indexed elements +! @param {Array>} zx - first input array +! @param {integer} strideX - `zx` stride length +! @param {Array>} zy - second input array +! @param {integer} strideY - `zy` stride length +!< +subroutine zswap( N, zx, strideX, zy, strideY ) + implicit none + ! .. + ! Scalar arguments: + integer :: strideX, strideY, N + ! .. + ! Array arguments: + complex(kind=kind(0.0d0)) :: zx(*), zy(*) + ! .. + ! Local scalars: + integer :: ix, iy, i + complex(kind=kind(0.0d0)) :: tmp + ! .. + if ( N <= 0 ) then + return + end if + ! .. + if ( strideX == 1 .AND. strideY == 1 ) then + do i = 1, N + tmp = zx( i ) + zx( i ) = zy( i ) + zy( i ) = tmp + end do + else + if ( strideX < 0 ) then + ix = ((1-N)*strideX) + 1 + else + ix = 1 + end if + if ( strideY < 0 ) then + iy = ((1-N)*strideY) + 1 + else + iy = 1 + end if + do i = 1, N + tmp = zx( ix ) + zx( ix ) = zy( iy ) + zy( iy ) = tmp + ix = ix + strideX + iy = iy + strideY + end do + end if + return +end subroutine zswap \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_cblas.c b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_cblas.c new file mode 100644 index 000000000000..24cc9c488372 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_cblas.c @@ -0,0 +1,33 @@ +/** +* @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/zswap.h" +#include "stdlib/blas/base/zswap_cblas.h" + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @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 +*/ +void c_zswap( const int N, void *X, const int strideX, void *Y, const int strideY ) { + cblas_zswap( N, X, strideX, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_f.c b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_f.c new file mode 100644 index 000000000000..5963e5fe5448 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/src/zswap_f.c @@ -0,0 +1,33 @@ +/** +* @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/zswap.h" +#include "stdlib/blas/base/zswap_fortran.h" + +/** +* Interchanges two complex double-precision floating-point vectors. +* +* @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 +*/ +void c_zswap( const int N, void *X, const int strideX, void *Y, const int strideY ) { + zswap( &N, X, &strideX, Y, &strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/zswap/test/test.js b/lib/node_modules/@stdlib/blas/base/zswap/test/test.js new file mode 100644 index 000000000000..f1ddc71c61ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/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 zswap = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zswap, '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 zswap.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 zswap = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zswap, mock, 'returns native implementation' ); + 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 zswap; + var main; + + main = require( './../lib/zswap.js' ); + + zswap = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( zswap, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.js new file mode 100644 index 000000000000..6b8afb315213 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.js @@ -0,0 +1,407 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var zswap = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zswap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( zswap.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function swaps elements in `x` and `y`', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.notEqual( y, x, 'different references' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, 0, y, 1, 0 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, // 2 + 8.0 // 2 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 2, y, 1, 0 ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 0, y, 2, 0 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 0, y, 1, 2 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the destination array', function test( t ) { + var out; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns both vectors unchanged', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + zswap( -1, x, 1, 0, y, 1, 0 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + zswap( 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 2 + 2.0, // 2 + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, -2, x.length-2, y, -1, y.length-2 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 5.0, 6.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, + 6.0, + 7.0, // 2 + 8.0 // 2 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0 // 1 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, 1, y, -1, y.length-1 ); + + xe = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently swaps elements in `x` and `y`', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + var i; + + x = new Complex128Array( 100 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i, i ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + x = new Complex128Array( 120 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i*2, i*2 ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.native.js new file mode 100644 index 000000000000..250d29d14354 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/test/test.ndarray.native.js @@ -0,0 +1,416 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var zswap = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( zswap instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zswap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', opts, function test( t ) { + t.strictEqual( zswap.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function swaps elements in `x` and `y`', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.notEqual( y, x, 'different references' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, 0, y, 1, 0 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, // 2 + 8.0 // 2 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 2, y, 1, 0 ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 5.0, 6.0, 7.0, 8.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 0, y, 2, 0 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, 0, y, 1, 2 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the destination array', opts, function test( t ) { + var out; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns both vectors unchanged', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + zswap( -1, x, 1, 0, y, 1, 0 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + zswap( 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 2 + 2.0, // 2 + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, -2, x.length-2, y, -1, y.length-2 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 5.0, 6.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 1 + 4.0, // 1 + 5.0, + 6.0, + 7.0, // 2 + 8.0 // 2 + ]); + y = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0 // 1 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, 1, y, -1, y.length-1 ); + + xe = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently swaps elements in `x` and `y`', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + var i; + + x = new Complex128Array( 100 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i, i ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + x = new Complex128Array( 120 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i*2, i*2 ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, 0, y, 1, 0 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.js b/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.js new file mode 100644 index 000000000000..4b917df427e6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.js @@ -0,0 +1,372 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var zswap = require( './../lib/zswap.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zswap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( zswap.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function swaps elements in `x` and `y`', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.notEqual( y, x, 'different references' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, y, 1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, y, 2 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the destination array', function test( t ) { + var out; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = zswap( x.length, x, 1, y, 1 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns both vectors unchanged', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + zswap( -1, x, 1, y, 1 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + zswap( 0, x, 1, y, 1 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 2 + 2.0, // 2 + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, -2, y, -1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, y, -1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 5.0, 6.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var viewX; + var viewY; + var x0; + var y0; + var x1; + var y1; + var xe; + var ye; + + // Initial arrays... + x0 = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, // 1 + 8.0 // 1 + ]); + y0 = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + + // Create offset views... + x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element + + viewX = new Float64Array( x0.buffer ); + viewY = new Float64Array( y0.buffer ); + + zswap( 2, x1, -2, y1, 1 ); + + xe = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently swaps elements in `x` and `y`', function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + var i; + + x = new Complex128Array( 100 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i, i ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + x = new Complex128Array( 120 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i*2, i*2 ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.native.js b/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.native.js new file mode 100644 index 000000000000..72cd0b1f4699 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zswap/test/test.zswap.native.js @@ -0,0 +1,381 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var dcopy = require( '@stdlib/blas/base/dcopy' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var zswap = tryRequire( resolve( __dirname, './../lib/zswap.native.js' ) ); +var opts = { + 'skip': ( zswap instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof zswap, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( zswap.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function swaps elements in `x` and `y`', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.notEqual( y, x, 'different references' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, y, 1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, // 2 + 0.0, // 2 + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 1, y, 2 ); + + xe = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a reference to the destination array', opts, function test( t ) { + var out; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + out = zswap( x.length, x, 1, y, 1 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns both vectors unchanged', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + y = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + zswap( -1, x, 1, y, 1 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + zswap( 0, x, 1, y, 1 ); + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 2 + 2.0, // 2 + 3.0, + 4.0, + 5.0, // 1 + 6.0, // 1 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, -2, y, -1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + + x = new Complex128Array([ + 1.0, // 1 + 2.0, // 1 + 3.0, + 4.0, + 5.0, // 2 + 6.0, // 2 + 7.0, + 8.0 + ]); + y = new Complex128Array([ + 0.0, // 2 + 0.0, // 2 + 0.0, // 1 + 0.0, // 1 + 0.0, + 0.0, + 0.0, + 0.0 + ]); + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + zswap( 2, x, 2, y, -1 ); + + xe = new Float64Array( [ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0 ] ); + ye = new Float64Array( [ 5.0, 6.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var viewX; + var viewY; + var x0; + var y0; + var x1; + var y1; + var xe; + var ye; + + // Initial arrays... + x0 = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 2 + 4.0, // 2 + 5.0, + 6.0, + 7.0, // 1 + 8.0 // 1 + ]); + y0 = new Complex128Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, // 1 + 0.0, // 1 + 0.0, // 2 + 0.0 // 2 + ]); + + // Create offset views... + x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // begin at the 3rd element + + viewX = new Float64Array( x0.buffer ); + viewY = new Float64Array( y0.buffer ); + + zswap( 2, x1, -2, y1, 1 ); + + xe = new Float64Array( [ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ] ); + ye = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 7.0, 8.0, 3.0, 4.0 ] ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + t.end(); +}); + +tape( 'if both strides are equal to `1`, the function efficiently swaps elements in `x` and `y`', opts, function test( t ) { + var viewX; + var viewY; + var xe; + var ye; + var x; + var y; + var i; + + x = new Complex128Array( 100 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i, i ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + x = new Complex128Array( 120 ); + y = new Complex128Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x.set( [ i*2, i*2 ], i ); + } + + viewX = new Float64Array( x.buffer ); + viewY = new Float64Array( y.buffer ); + + xe = dcopy( viewY.length, viewY, 1, new Float64Array( viewY.length ), 1 ); + ye = dcopy( viewX.length, viewX, 1, new Float64Array( viewY.length ), 1 ); + + zswap( x.length, x, 1, y, 1 ); + + t.deepEqual( viewX, xe, 'returns expected value' ); + t.deepEqual( viewY, ye, 'returns expected value' ); + + t.end(); +});