From b40f5c33aaf2113c73f8f0811c8d1cdc9fbfde53 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sun, 9 Jun 2024 05:09:11 +0530 Subject: [PATCH] feat: add `blas/base/cscal` PR-URL: https://github.com/stdlib-js/stdlib/pull/2104 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines --- .../@stdlib/blas/base/cscal/README.md | 346 ++++++++++++++ .../blas/base/cscal/benchmark/benchmark.js | 111 +++++ .../base/cscal/benchmark/benchmark.native.js | 116 +++++ .../base/cscal/benchmark/benchmark.ndarray.js | 111 +++++ .../benchmark/benchmark.ndarray.native.js | 116 +++++ .../blas/base/cscal/benchmark/c/Makefile | 146 ++++++ .../base/cscal/benchmark/c/benchmark.length.c | 156 ++++++ .../base/cscal/benchmark/fortran/Makefile | 141 ++++++ .../benchmark/fortran/benchmark.length.f | 222 +++++++++ .../@stdlib/blas/base/cscal/binding.gyp | 265 +++++++++++ .../@stdlib/blas/base/cscal/docs/repl.txt | 124 +++++ .../blas/base/cscal/docs/types/index.d.ts | 148 ++++++ .../blas/base/cscal/docs/types/test.ts | 202 ++++++++ .../blas/base/cscal/examples/c/Makefile | 146 ++++++ .../blas/base/cscal/examples/c/example.c | 43 ++ .../@stdlib/blas/base/cscal/examples/index.js | 38 ++ .../@stdlib/blas/base/cscal/include.gypi | 70 +++ .../cscal/include/stdlib/blas/base/cscal.h | 44 ++ .../include/stdlib/blas/base/cscal_cblas.h | 44 ++ .../include/stdlib/blas/base/cscal_fortran.h | 43 ++ .../@stdlib/blas/base/cscal/lib/cscal.js | 83 ++++ .../blas/base/cscal/lib/cscal.native.js | 67 +++ .../@stdlib/blas/base/cscal/lib/index.js | 92 ++++ .../@stdlib/blas/base/cscal/lib/main.js | 35 ++ .../@stdlib/blas/base/cscal/lib/native.js | 35 ++ .../@stdlib/blas/base/cscal/lib/ndarray.js | 76 +++ .../blas/base/cscal/lib/ndarray.native.js | 71 +++ .../@stdlib/blas/base/cscal/manifest.json | 445 ++++++++++++++++++ .../@stdlib/blas/base/cscal/package.json | 81 ++++ .../@stdlib/blas/base/cscal/src/Makefile | 70 +++ .../@stdlib/blas/base/cscal/src/addon.c | 45 ++ .../@stdlib/blas/base/cscal/src/cscal.c | 48 ++ .../@stdlib/blas/base/cscal/src/cscal.f | 85 ++++ .../@stdlib/blas/base/cscal/src/cscal_cblas.c | 34 ++ .../@stdlib/blas/base/cscal/src/cscal_f.c | 34 ++ .../blas/base/cscal/test/test.cscal.js | 254 ++++++++++ .../blas/base/cscal/test/test.cscal.native.js | 263 +++++++++++ .../@stdlib/blas/base/cscal/test/test.js | 82 ++++ .../blas/base/cscal/test/test.ndarray.js | 319 +++++++++++++ .../base/cscal/test/test.ndarray.native.js | 328 +++++++++++++ 40 files changed, 5179 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/benchmark.length.f create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal.h create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal_cblas.h create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal_fortran.h create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/cscal.f create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/blas/base/cscal/README.md b/lib/node_modules/@stdlib/blas/base/cscal/README.md new file mode 100644 index 00000000000..2bbab5171f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/README.md @@ -0,0 +1,346 @@ + + +# cscal + +> Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. + +
+ +## Usage + +```javascript +var cscal = require( '@stdlib/blas/base/cscal' ); +``` + +#### cscal( N, ca, cx, strideX ) + +Scales values from `cx` by `ca`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var ca = new Complex64( 2.0, 0.0 ); + +cscal( 3, ca, cx, 1 ); + +var z = cx.get( 0 ); +// returns + +var re = realf( z ); +// returns 2.0 + +var im = imagf( z ); +// returns 2.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **ca**: scalar [`Complex64`][@stdlib/complex/float32/ctor] constant. +- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `cx`. + +The `N` and stride parameters determine how values from `cx` are scaled by `ca`. For example, to scale every other value in `cx` by `ca`, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var ca = new Complex64( 2.0, 0.0 ); + +cscal( 2, ca, cx, 2 ); + +var z = cx.get( 2 ); +// returns + +var re = realf( z ); +// returns 10.0 + +var im = imagf( z ); +// returns 12.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +// Initial array: +var cx0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + +// Define a scalar constant: +var ca = new Complex64( 2.0, 2.0 ); + +// Create an offset view: +var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Scales every other value from `cx1` by `ca`... +cscal( 3, ca, cx1, 1 ); + +var z = cx0.get( 1 ); +// returns + +var re = realf( z ); +// returns -2.0 + +var im = imagf( z ); +// returns 14.0 +``` + +#### cscal.ndarray( N, ca, cx, strideX, offsetX ) + +Scales values from `cx` by `ca` using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +cscal.ndarray( 3, ca, cx, 1, 0 ); + +var z = cx.get( 0 ); +// returns + +var re = realf( z ); +// returns -2.0 + +var im = imagf( z ); +// returns 6.0 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `cx`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to scale every other value in the input strided array starting from the second element, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/realf' ); +var imagf = require( '@stdlib/complex/imagf' ); + +var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var ca = new Complex64( 2.0, 2.0 ); + +cscal.ndarray( 2, ca, cx, 2, 1 ); + +var z = cx.get( 3 ); +// returns + +var re = realf( z ); +// returns -2.0 + +var im = imagf( z ); +// returns 30.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0` or `strideX <= 0` , both functions return `cx` unchanged. +- `cscal()` corresponds to the [BLAS][blas] level 1 function [`cscal`][cscal]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var cscal = require( '@stdlib/blas/base/cscal' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +var ca = new Complex64( 2.0, 2.0 ); +console.log( ca.toString() ); + +// Scale elements from `cx` by `ca`: +cscal( cx.length, ca, cx, 1 ); +console.log( cx.get( cx.length-1 ).toString() ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/cscal.h" +``` + +#### c_cscal( N, ca, \*CX, strideX ) + +Scales values from `CX` by `ca`. + +```c +#include "stdlib/complex/float32/ctor.h" + +float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; +const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + +c_dscal( 4, ca, (void *)cx, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **ca**: `[in] stdlib_complex64_t` scalar constant. +- **CX**: `[inout] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. + +```c +void c_dscal( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/cscal.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Create a complex scalar: + const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + + // Specify the number of elements: + const int N = 4; + + // Specify stride length: + const int strideX = 1; + + // Scale the elements of the array: + c_cscal( N, ca, (void *)cx, strideX ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.js new file mode 100644 index 00000000000..e928a96f95d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.js @@ -0,0 +1,111 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var pkg = require( './../package.json' ).name; +var cscal = require( './../lib/cscal.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var z; + var x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + z = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cscal( x.length, z, x, 1 ); + if ( isnanf( xbuf[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( xbuf[ 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/cscal/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.native.js new file mode 100644 index 00000000000..441eb1061b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.native.js @@ -0,0 +1,116 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cscal = tryRequire( resolve( __dirname, './../lib/cscal.native.js' ) ); +var opts = { + 'skip': ( cscal instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var z; + var x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + z = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cscal( x.length, z, x, 1 ); + if ( isnanf( xbuf[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( xbuf[ 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/cscal/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..63985c92b31 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.js @@ -0,0 +1,111 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var pkg = require( './../package.json' ).name; +var cscal = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var z; + var x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + z = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cscal( x.length, z, x, 1, 0 ); + if ( isnanf( xbuf[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( xbuf[ 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/cscal/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.native.js new file mode 100644 index 00000000000..1cca4e3e8e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,116 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cscal = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( cscal instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var z; + var x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + z = new Complex64( 1.0, 0.0 ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + cscal( x.length, z, x, 1, 0 ); + if ( isnanf( xbuf[ i%(len*2) ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( xbuf[ 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/cscal/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/Makefile new file mode 100644 index 00000000000..9f97140e7cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c new file mode 100644 index 00000000000..314b66dcb4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c @@ -0,0 +1,156 @@ +/** +* @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 `cscal`. +*/ +#include "stdlib/blas/base/cscal.h" +#include "stdlib/complex/float32/ctor.h" +#include +#include +#include +#include +#include + +#define NAME "cscal" +#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 +*/ +float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +double benchmark( int iterations, int len ) { + stdlib_complex64_t ca; + float cx[ len*2 ]; + double elapsed; + double t; + int i; + + ca = stdlib_complex64( rand_float()*5.0f, rand_float()*2.0f ); + for ( i = 0; i < len*2; i += 2 ) { + cx[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + cx[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_cscal( len, ca, (void *)cx, 1 ); + if ( cx[ 0 ] != cx[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cx[ 0 ] != cx[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/Makefile b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/Makefile new file mode 100644 index 00000000000..7b2b685b4b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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/cscal.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/cscal/benchmark/fortran/benchmark.length.f b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/benchmark.length.f new file mode 100644 index 00000000000..c09a1d29628 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/fortran/benchmark.length.f @@ -0,0 +1,222 @@ +!> +! @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 `cscal`. +! +! ## Notes +! +! - Written in "free form" Fortran 95. +! +!< +program bench + implicit none + ! .. + ! Local constants: + character(5), parameter :: name = 'cscal' ! 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 cscal( N, ca, cx, strideX ) + complex :: ca, cx(*) + integer :: strideX, N + end subroutine cscal + end interface + ! .. + ! Scalar arguments: + integer, intent(in) :: iterations, len + ! .. + ! Local scalars: + double precision :: elapsed, r1, r2 + real :: t1, t2 + integer :: i + ! .. + ! Local array: + complex, allocatable :: x(:) + ! .. + ! Local scalar: + complex :: ca + ! .. + ! Intrinsic functions: + intrinsic random_number, cpu_time, cmplx + ! .. + ! Allocate array: + allocate( x(len) ) + ! .. + call random_number( r1 ) + call random_number( r2 ) + ca = cmplx( (real(r1)*5.0), (real(r2)*5.0) ) + do i = 1, len + call random_number( r1 ) + call random_number( r2 ) + x( i ) = cmplx( (real(r1)*10000.0)-5000.0, (real(r2)*10000.0)-5000.0 ) + end do + ! .. + call cpu_time( t1 ) + ! .. + do i = 1, iterations + call cscal( len, ca, x, 1 ); + if ( x( 1 ) /= x( 1 ) ) then + print '(A)', 'should not return NaN' + exit + end if + end do + ! .. + call cpu_time( t2 ) + ! .. + elapsed = t2 - t1 + ! .. + if ( x( 1 ) /= x( 1 ) ) then + print '(A)', 'should not return NaN' + end if + ! .. + ! Deallocate array: + deallocate( x ) + ! .. + 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/cscal/binding.gyp b/lib/node_modules/@stdlib/blas/base/cscal/binding.gyp new file mode 100644 index 00000000000..02a2799da09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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/cscal/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt new file mode 100644 index 00000000000..33416ab23fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt @@ -0,0 +1,124 @@ + +{{alias}}( N, ca, cx, strideX ) + Scales a single-precision complex floating-point vector by a single- + precision complex floating-point constant. + + The `N` and stride parameters determine how values from `cx` are scaled by + `ca`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N` or `strideX` is less than or equal to `0`, the function returns `cx` + unchanged. + + + Parameters + ---------- + N: integer + Number of indexed elements. + + ca: Complex64 + Complex constant. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + Returns + ------- + cx: Complex64Array + Input array. + + Examples + -------- + // Standard usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 2.0 ); + > {{alias}}( 2, ca, cx, 1 ); + > var z = cx.get( 0 ); + > var re = {{alias:@stdlib/complex/realf}}( z ) + -3.0 + > var im = {{alias:@stdlib/complex/imagf}}( z ) + 4.0 + + // Advanced indexing: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > ca = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 1.0 ); + > {{alias}}( 2, ca, cx, 2 ); + > z = cx.get( 0 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -1.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 3.0 + + // Using typed array views: + > var cx0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var cx1 = new {{alias:@stdlib/array/complex64}}( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); + > {{alias}}( 2, ca, cx1, 1 ); + > z = cx0.get( 1 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -2.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 14.0 + + +{{alias}}.ndarray( N, ca, cx, strideX, offsetX ) + Scales a single-precision complex floating-point vector by a single- + precision complex floating-point constant using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + ca: Complex64 + Complex constant. + + cx: Complex64Array + Input array. + + strideX: integer + Index increment for `cx`. + + offsetX: integer + Starting index for `cx`. + + Returns + ------- + cx: Complex64Array + Input array. + + Examples + -------- + // Standard usage: + > var cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var ca = new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 2.0 ); + > {{alias}}.ndarray( 2, ca, cx, 1, 0 ); + > var z = cx.get( 0 ); + > var re = {{alias:@stdlib/complex/realf}}( z ) + -2.0 + > var im = {{alias:@stdlib/complex/imagf}}( z ) + 6.0 + + // Advanced indexing: + > cx = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + > ca = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 2.0 ); + > {{alias}}.ndarray( 2, ca, cx, 1, 2 ); + > z = cx.get( 2 ); + > re = {{alias:@stdlib/complex/realf}}( z ) + -7.0 + > im = {{alias:@stdlib/complex/imagf}}( z ) + 16.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/cscal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/cscal/docs/types/index.d.ts new file mode 100644 index 00000000000..10555581e62 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/docs/types/index.d.ts @@ -0,0 +1,148 @@ +/* +* @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 { Complex64Array } from '@stdlib/types/array'; +import { Complex64 } from '@stdlib/types/complex'; + +/** +* Interface describing `cscal`. +*/ +interface Routine { + /** + * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. + * + * @param N - number of indexed elements + * @param ca - scalar constant + * @param cx - input array + * @param strideX - `cx` stride length + * @returns input array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var realf = require( '@stdlib/complex/realf' ); + * var imagf = require( '@stdlib/complex/imagf' ); + * + * var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var ca = new Complex64( 2.0, 2.0 ); + * + * cscal( 3, ca, cx, 1 ); + * + * var z = cx.get( 0 ); + * // returns + * + * var re = realf( z ); + * // returns -2.0 + * + * var im = imagf( z ); + * // returns 6.0 + */ + ( N: number, ca: Complex64, cx: Complex64Array, strideX: number ): Complex64Array; + + /** + * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. + * + * @param N - number of indexed elements + * @param ca - scalar constant + * @param cx - input array + * @param strideX - `cx` stride length + * @param offsetX - starting index for `cx` + * @returns input array + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var realf = require( '@stdlib/complex/realf' ); + * var imagf = require( '@stdlib/complex/imagf' ); + * + * var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var ca = new Complex64( 2.0, 2.0 ); + * + * cscal.ndarray( 3, ca, cx, 1, 0 ); + * + * var z = cx.get( 0 ); + * // returns + * + * var re = realf( z ); + * // returns -2.0 + * + * var im = imagf( z ); + * // returns 6.0 + */ + ndarray( N: number, ca: Complex64, cx: Complex64Array, strideX: number, offsetX: number ): Complex64Array; +} + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N - number of indexed elements +* @param ca - scalar constant +* @param cx - input array +* @param strideX - `cx` stride length +* @returns input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal( 3, ca, cx, 1 ); +* +* var z = cx.get( 1 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal.ndarray( 2, ca, cx, 1, 0 ); +* +* var z = cx.get( 1 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +*/ +declare var cscal: Routine; + + +// EXPORTS // + +export = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/cscal/docs/types/test.ts new file mode 100644 index 00000000000..62b00fcd725 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/docs/types/test.ts @@ -0,0 +1,202 @@ +/* +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import cscal = require( './index' ); + + +// TESTS // + +// The function returns a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal( cx.length, ca, cx, 1 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal( '10', ca, cx, 1 ); // $EcxpectError + cscal( true, ca, cx, 1 ); // $ExpectError + cscal( false, ca, cx, 1 ); // $ExpectError + cscal( null, ca, cx, 1 ); // $ExpectError + cscal( undefined, ca, cx, 1 ); // $ExpectError + cscal( [], ca, cx, 1 ); // $ExpectError + cscal( {}, ca, cx, 1 ); // $ExpectError + cscal( ( cx: number ): number => cx, ca, cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a complex number... +{ + const cx = new Complex64Array( 10 ); + + cscal( cx.length, 10, cx, 1 ); // $ExpectError + cscal( cx.length, '10', cx, 1 ); // $ExpectError + cscal( cx.length, true, cx, 1 ); // $ExpectError + cscal( cx.length, false, cx, 1 ); // $ExpectError + cscal( cx.length, null, cx, 1 ); // $ExpectError + cscal( cx.length, undefined, cx, 1 ); // $ExpectError + cscal( cx.length, [ '1' ], cx, 1 ); // $ExpectError + cscal( cx.length, {}, cx, 1 ); // $ExpectError + cscal( cx.length, ( cx: number ): number => cx, cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal( cx.length, ca, 10, 1 ); // $ExpectError + cscal( cx.length, ca, '10', 1 ); // $ExpectError + cscal( cx.length, ca, true, 1 ); // $ExpectError + cscal( cx.length, ca, false, 1 ); // $ExpectError + cscal( cx.length, ca, null, 1 ); // $ExpectError + cscal( cx.length, ca, undefined, 1 ); // $ExpectError + cscal( cx.length, ca, [ '1' ], 1 ); // $ExpectError + cscal( cx.length, ca, {}, 1 ); // $ExpectError + cscal( cx.length, ca, ( cx: number ): number => cx, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal( cx.length, ca, cx, '10' ); // $ExpectError + cscal( cx.length, ca, cx, true ); // $ExpectError + cscal( cx.length, ca, cx, false ); // $ExpectError + cscal( cx.length, ca, cx, null ); // $ExpectError + cscal( cx.length, ca, cx, undefined ); // $ExpectError + cscal( cx.length, ca, cx, [] ); // $ExpectError + cscal( cx.length, ca, cx, {} ); // $ExpectError + cscal( cx.length, ca, cx, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal(); // $ExpectError + cscal( cx.length ); // $ExpectError + cscal( cx.length, ca ); // $ExpectError + cscal( cx.length, ca, cx ); // $ExpectError + cscal( cx.length, ca, cx, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal.ndarray( cx.length, ca, cx, 1, 0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal.ndarray( '10', ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( true, ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( false, ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( null, ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( undefined, ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( [], ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( {}, ca, cx, 1, 0 ); // $ExpectError + cscal.ndarray( ( cx: number ): number => cx, ca, cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a complex number... +{ + const cx = new Complex64Array( 10 ); + + cscal.ndarray( cx.length, 10, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, '10', cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, true, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, false, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, null, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, undefined, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, [ '1' ], cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, {}, cx, 1, 0 ); // $ExpectError + cscal.ndarray( cx.length, ( cx: number ): number => cx, cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Complex64Array... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal( cx.length, ca, 10, 1, 0 ); // $ExpectError + cscal( cx.length, ca, '10', 1, 0 ); // $ExpectError + cscal( cx.length, ca, true, 1, 0 ); // $ExpectError + cscal( cx.length, ca, false, 1, 0 ); // $ExpectError + cscal( cx.length, ca, null, 1, 0 ); // $ExpectError + cscal( cx.length, ca, undefined, 1, 0 ); // $ExpectError + cscal( cx.length, ca, [ '1' ], 1, 0 ); // $ExpectError + cscal( cx.length, ca, {}, 1, 0 ); // $ExpectError + cscal( cx.length, ca, ( cx: number ): number => cx, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal.ndarray( cx.length, ca, cx, '10', 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, true, 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, false, 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, null, 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, undefined, 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, [], 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, {}, 0 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, ( cx: number ): number => cx, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal.ndarray( cx.length, ca, cx, 1, '10' ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, true ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, false ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, null ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, undefined ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, [] ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, {} ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, ( cx: number ): number => cx ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const cx = new Complex64Array( 10 ); + const ca = new Complex64( 2.0, 2.0 ); + + cscal.ndarray(); // $ExpectError + cscal.ndarray( cx.length ); // $ExpectError + cscal.ndarray( cx.length, ca ); // $ExpectError + cscal.ndarray( cx.length, ca, cx ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1 ); // $ExpectError + cscal.ndarray( cx.length, ca, cx, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/examples/c/Makefile b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/Makefile new file mode 100644 index 00000000000..6aed70daf16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c new file mode 100644 index 00000000000..67ff6e14b88 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c @@ -0,0 +1,43 @@ +/** +* @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/cscal.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create a strided array of interleaved real and imaginary components: + float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Create a complex scalar: + const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + + // Specify the number of elements: + const int N = 4; + + // Specify stride length: + const int strideX = 1; + + // Scale the elements of the array: + c_cscal( N, ca, (void *)cx, strideX ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); + } +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/examples/index.js b/lib/node_modules/@stdlib/blas/base/cscal/examples/index.js new file mode 100644 index 00000000000..cdb9533c2d2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var cscal = require( '@stdlib/blas/base/cscal' ); + +function rand() { + return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +var cx = filledarrayBy( 10, 'complex64', rand ); +console.log( cx.toString() ); + +var ca = new Complex64( 2.0, 2.0 ); +console.log( ca.toString() ); + +// Scale elements from `cx` by `ca`: +cscal( cx.length, ca, cx, 1 ); +console.log( cx.get( cx.length-1 ).toString() ); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/include.gypi b/lib/node_modules/@stdlib/blas/base/cscal/include.gypi new file mode 100644 index 00000000000..497aeca1532 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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 = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +*/ +function cscal( N, ca, cx, strideX ) { + var ix; + var i; + + if ( N <= 0 || strideX <= 0 ) { + return cx; + } + if ( strideX === 1 ) { + // Code for stride equal to `1`... + for ( i = 0; i < N; i++ ) { + cx.set( cmulf( ca, cx.get( i ) ), i ); + } + return cx; + } + // Code for stride not equal to `1`... + ix = 0; + for ( i = 0; i < N; i++ ) { + cx.set( cmulf( ca, cx.get( ix ) ), ix ); + ix += strideX; + } + return cx; +} + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.native.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.native.js new file mode 100644 index 00000000000..49c6e554136 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.native.js @@ -0,0 +1,67 @@ +/** +* @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-complex64' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - input array +* @param {integer} strideX - `x` stride length +* @returns {Complex64Array} input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal( cx.length, ca, cx, 1 ); +* +* var z = cx.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +*/ +function cscal( N, ca, cx, strideX ) { + var viewCX = reinterpret( cx, 0 ); + addon( N, ca, viewCX, strideX ); + return cx; +} + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/index.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/index.js new file mode 100644 index 00000000000..6e2b086182b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/index.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* BLAS level 1 routine to scale a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @module @stdlib/blas/base/cscal +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* var cscal = require( '@stdlib/blas/base/cscal' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal( 3, ca, cx, 1 ); +* +* var z = cx.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* var cscal = require( '@stdlib/blas/base/cscal' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal.ndarray( 3, ca cx, 1, 0 ); +* +* var z = y.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.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 cscal; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + cscal = main; +} else { + cscal = tmp; +} + + +// EXPORTS // + +module.exports = cscal; + +// exports: { "ndarray": "cscal.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/main.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/main.js new file mode 100644 index 00000000000..6c75f446f40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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 cscal = require( './cscal.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( cscal, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/native.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/native.js new file mode 100644 index 00000000000..ed3c87d084b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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 cscal = require( './cscal.native.js' ); +var ndarray = require( './ndarray.native.js' ); + + +// MAIN // + +setReadOnly( cscal, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js new file mode 100644 index 00000000000..f3f2dd2f80b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var cmulf = require( '@stdlib/math/base/ops/cmulf' ); + + +// MAIN // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - constant +* @param {Complex64Array} cx - input array +* @param {integer} strideX - `cx` stride length +* @param {NonNegativeInteger} offsetX - starting `cx` index +* @returns {Complex64Array} input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal( 3, ca, cx, 1, 0 ); +* +* var z = cx.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +*/ +function cscal( N, ca, cx, strideX, offsetX ) { + var ix; + var i; + + if ( N <= 0 || strideX <= 0 ) { + return cx; + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + cx.set( cmulf( ca, cx.get( ix ) ), ix ); + ix += strideX; + } + return cx; +} + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js new file mode 100644 index 00000000000..e180cdfb59e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64} ca - scalar constant +* @param {Complex64Array} cx - input array +* @param {integer} strideX - `cx` stride length +* @param {NonNegativeInteger} offsetX - starting `cx` index +* @returns {Complex64Array} input array +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var realf = require( '@stdlib/complex/realf' ); +* var imagf = require( '@stdlib/complex/imagf' ); +* +* var cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ca = new Complex64( 2.0, 2.0 ); +* +* cscal( cx.length, ca, cx, 1, 0 ); +* +* var z = cx.get( 0 ); +* // returns +* +* var re = realf( z ); +* // returns -2.0 +* +* var im = imagf( z ); +* // returns 6.0 +*/ +function cscal( N, ca, cx, strideX, offsetX ) { + var viewCX; + offsetX = minViewBufferIndex( N, strideX, offsetX ); + viewCX = reinterpret( cx, offsetX ); + addon( N, ca, viewCX, strideX ); + return cx; +} + + +// EXPORTS // + +module.exports = cscal; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/manifest.json b/lib/node_modules/@stdlib/blas/base/cscal/manifest.json new file mode 100644 index 00000000000..09069ba90d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/manifest.json @@ -0,0 +1,445 @@ +{ + "options": { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.f", + "./src/cscal_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor", + "@stdlib/math/base/ops/cmulf" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.f", + "./src/cscal_f.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "apple_accelerate_framework", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lblas" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "openblas", + "wasm": false, + "src": [ + "./src/cscal_cblas.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lopenblas", + "-lpthread" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-complex64array", + "@stdlib/napi/argv-complex64", + "@stdlib/complex/float32/ctor", + "@stdlib/math/base/ops/cmulf" + ] + }, + { + "task": "benchmark", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + { + "task": "examples", + "os": "win", + "blas": "", + "wasm": false, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + }, + + { + "task": "build", + "os": "", + "blas": "", + "wasm": true, + "src": [ + "./src/cscal.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/math/base/ops/cmulf", + "@stdlib/complex/float32/ctor" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/package.json b/lib/node_modules/@stdlib/blas/base/cscal/package.json new file mode 100644 index 00000000000..41a60259eea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/package.json @@ -0,0 +1,81 @@ +{ + "name": "@stdlib/blas/base/cscal", + "version": "0.0.0", + "description": "Scale a single-precision complex floating-point vector by a single-precision complex floating-point constant.", + "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", + "cscal", + "scale", + "vector", + "typed", + "array", + "ndarray", + "complex", + "complex64", + "float", + "float32", + "single", + "float32array" + ], + "__stdlib__": { + "wasm": false + } +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/Makefile b/lib/node_modules/@stdlib/blas/base/cscal/src/Makefile new file mode 100644 index 00000000000..bcf18aa4665 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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/cscal/src/addon.c b/lib/node_modules/@stdlib/blas/base/cscal/src/addon.c new file mode 100644 index 00000000000..1391deddb02 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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/cscal.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_complex64.h" +#include "stdlib/napi/argv_strided_complex64array.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, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, ca, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); + c_cscal( N, ca, (void *)CX, strideX ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c new file mode 100644 index 00000000000..04597809eb7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/cscal.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/math/base/ops/cmulf.h" +#include + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +*/ +void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { + stdlib_complex64_t z; + CBLAS_INT i; + + uint8_t *ip1 = (uint8_t *)CX; + int64_t is1 = 8 * strideX; + + if ( N <= 0 || strideX <= 0 ) { + return; + } + for ( i = 0; i < N; i++, ip1 += is1 ) { + z = *( (stdlib_complex64_t *)ip1 ); + *( (stdlib_complex64_t *)ip1 ) = stdlib_base_cmulf( ca, z ); + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.f b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.f new file mode 100644 index 00000000000..e54c86ce083 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.f @@ -0,0 +1,85 @@ +!> +! @license Apache-2.0 +! +! Copyright (c) 2024 The Stdlib Authors. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. +!< + +!> Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +! +! ## 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 3/93 to return if incx .le. 0. +! - 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 {complex} ca - scalar constant +! @param {Array} cx - input array +! @param {integer} strideX - `cx` stride length +!< +subroutine cscal( N, ca, cx, strideX ) + implicit none + ! .. + ! Scalar arguments: + complex :: ca + integer :: strideX, N + ! .. + ! Array arguments: + complex :: cx(*) + ! .. + ! Local scalars: + integer :: ix, i + ! .. + if ( N <= 0 .OR. strideX <= 0 ) then + return + end if + ! .. + if ( strideX == 1 ) then + do i = 1, N + cx(i) = ca * cx(i) + end do + else + ix = 1 + do i = 1, N + cx(ix) = ca * cx(ix) + ix = ix + strideX + end do + end if + return +end subroutine cscal \ No newline at end of file diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c new file mode 100644 index 00000000000..49e95da7586 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c @@ -0,0 +1,34 @@ +/** +* @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/cscal.h" +#include "stdlib/blas/base/cscal_cblas.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +*/ +void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { + cblas_cscal( N, ca, CX, strideX ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c new file mode 100644 index 00000000000..07f2a070e3d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c @@ -0,0 +1,34 @@ +/** +* @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/cscal.h" +#include "stdlib/blas/base/cscal_fortran.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +*/ +void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { + cscal( &N, &ca, CX, &strideX ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js new file mode 100644 index 00000000000..ec3e73c922c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js @@ -0,0 +1,254 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var cscal = require( './../lib/cscal.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cscal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( cscal.length, 4, 'arity of 4' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca`', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 4, ca, cx, 1 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.19, // 1 + -0.17, // 1 + 0.2, // 2 + -0.35, // 2 + 0.35, // 3 + 0.2, // 3 + 0.14, // 4 + 0.08 // 4 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` stride', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 3 + -0.3, // 3 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 2 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 1 + -0.03, // 1 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 3 + -0.19, // 3 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = cscal( 4, ca, cx, 1 ); + + t.strictEqual( out, cx, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( -1, ca, cx, 1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 0, ca, cx, 1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( 4, ca, cx, -1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 4, ca, cx, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var cx0; + var cx1; + var ca; + var k; + + // Initial arrays... + cx0 = new Complex64Array( [ + 0.1, + -0.3, + 8.0, // 1 + 9.0, // 1 + 0.5, // 2 + -0.1, // 2 + 2.0, // 3 + 5.0, // 3 + 2.0, + 3.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + // Create offset views... + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + cscal( 3, ca, cx1, 1 ); + + viewX = new Float32Array( cx0.buffer ); + expected = new Float32Array( [ + 0.1, + -0.3, + 9.5, // 1 + -2.0, // 1 + 0.13, // 2 + -0.39, // 2 + 4.3, // 3 + 0.6, // 3 + 2.0, + 3.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js new file mode 100644 index 00000000000..56a2f8ad84f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js @@ -0,0 +1,263 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cscal = tryRequire( resolve( __dirname, './../lib/cscal.native.js' ) ); +var opts = { + 'skip': ( cscal instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cscal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( cscal.length, 4, 'arity of 4' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca`', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2 // 4 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 4, ca, cx, 1 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.19, // 1 + -0.17, // 1 + 0.2, // 2 + -0.35, // 2 + 0.35, // 3 + 0.2, // 3 + 0.14, // 4 + 0.08 // 4 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` stride', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 3 + -0.3, // 3 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 2 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 1 + -0.03, // 1 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 3 + -0.19, // 3 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = cscal( 4, ca, cx, 1 ); + + t.strictEqual( out, cx, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( -1, ca, cx, 1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 0, ca, cx, 1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( 4, ca, cx, -1 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 4, ca, cx, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var cx0; + var cx1; + var ca; + var k; + + // Initial arrays... + cx0 = new Complex64Array( [ + 0.1, + -0.3, + 8.0, // 1 + 9.0, // 1 + 0.5, // 2 + -0.1, // 2 + 2.0, // 3 + 5.0, // 3 + 2.0, + 3.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + // Create offset views... + cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + cscal( 3, ca, cx1, 1 ); + + viewX = new Float32Array( cx0.buffer ); + expected = new Float32Array( [ + 0.1, + -0.3, + 9.5, // 1 + -2.0, // 1 + 0.13, // 2 + -0.39, // 2 + 4.3, // 3 + 0.6, // 3 + 2.0, + 3.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.js new file mode 100644 index 00000000000..e512f8ae175 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/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 cscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': isBrowser +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cscal, '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 cscal.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 cscal = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( cscal, 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 cscal; + var main; + + main = require( './../lib/cscal.js' ); + + cscal = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( cscal, main, 'returns JavaScript implementation' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js new file mode 100644 index 00000000000..4ccc29d9455 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js @@ -0,0 +1,319 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var cscal = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cscal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( cscal.length, 5, 'arity of 5' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca`', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0, + 2.0, + 3.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 4, ca, cx, 1, 0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.19, // 1 + -0.17, // 1 + 0.2, // 2 + -0.35, // 2 + 0.35, // 3 + 0.2, // 3 + 0.14, // 4 + 0.08, // 4 + 2.0, + 3.0, + 2.0, + 3.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` stride', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 3 + -0.3, // 3 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 2, 0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 1 + -0.03, // 1 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 3 + -0.19, // 3 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` offset', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 4.0, // 1 + 6.0, // 1 + 0.1, // 2 + -0.3, // 2 + 7.0, // 3 + 2.0 // 3 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 1, 3 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 5.8, // 1 + -0.4, // 1 + -0.17, // 2 + -0.19, // 2 + 4.2, // 3 + -4.1 // 3 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = cscal( 4, ca, cx, 1, 0 ); + + t.strictEqual( out, cx, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( -1, ca, cx, 1, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 0, ca, cx, 1, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( 4, ca, cx, -1, 3 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 4, ca, cx, 0, 3 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 4.0, // 1 + 6.0, // 1 + 0.1, + -0.3, + 7.0, + 2.0, + 2.0, // 2 + 3.0 // 2 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 2, ca, cx, 3, 3 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 5.8, // 1 + -0.4, // 1 + 0.1, + -0.3, + 7.0, + 2.0, + 2.9, // 2 + -0.2 // 2 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js new file mode 100644 index 00000000000..be323851bc5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js @@ -0,0 +1,328 @@ +/** +* @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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var cscal = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( cscal instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cscal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( cscal.length, 5, 'arity of 5' ); + t.end(); +}); + +tape( 'the function scales elements from `cx` by `ca`', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.3, // 1 + 0.1, // 1 + 0.5, // 2 + 0.0, // 2 + 0.0, // 3 + 0.5, // 3 + 0.0, // 4 + 0.2, // 4 + 2.0, + 3.0, + 2.0, + 3.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 4, ca, cx, 1, 0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.19, // 1 + -0.17, // 1 + 0.2, // 2 + -0.35, // 2 + 0.35, // 3 + 0.2, // 3 + 0.14, // 4 + 0.08, // 4 + 2.0, + 3.0, + 2.0, + 3.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` stride', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 1 + 0.1, // 1 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 3 + -0.3, // 3 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 2, 0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 1 + -0.03, // 1 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 3 + -0.19, // 3 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function supports a `cx` offset', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 4.0, // 1 + 6.0, // 1 + 0.1, // 2 + -0.3, // 2 + 7.0, // 3 + 2.0 // 3 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, 1, 3 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 5.8, // 1 + -0.4, // 1 + -0.17, // 2 + -0.19, // 2 + 4.2, // 3 + -4.1 // 3 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + out = cscal( 4, ca, cx, 1, 0 ); + + t.strictEqual( out, cx, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( -1, ca, cx, 1, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 0, ca, cx, 1, 0 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { + var expected; + var viewX; + var ca; + var cx; + + cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + ca = new Complex64( 2.0, 2.0 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + cscal( 4, ca, cx, -1, 3 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + cscal( 4, ca, cx, 0, 3 ); + t.deepEqual( viewX, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 4.0, // 1 + 6.0, // 1 + 0.1, + -0.3, + 7.0, + 2.0, + 2.0, // 2 + 3.0 // 2 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 2, ca, cx, 3, 3 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.1, + 0.1, + 3.0, + 6.0, + -0.6, + 0.1, + 5.8, // 1 + -0.4, // 1 + 0.1, + -0.3, + 7.0, + 2.0, + 2.9, // 2 + -0.2 // 2 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 5.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +});