From 51441c7b61cf352fe4d8285de53ce363ebd06791 Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Wed, 23 Apr 2025 12:35:54 +0530 Subject: [PATCH 01/11] feat: add blas/base/wasm/scnrm2 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/base/wasm/scnrm2/README.md | 315 +++++++++++ .../base/wasm/scnrm2/benchmark/benchmark.js | 111 ++++ .../wasm/scnrm2/benchmark/benchmark.module.js | 66 +++ .../scnrm2/benchmark/benchmark.module.main.js | 138 +++++ .../benchmark/benchmark.module.ndarray.js | 138 +++++ .../scnrm2/benchmark/benchmark.ndarray.js | 111 ++++ .../blas/base/wasm/scnrm2/docs/repl.txt | 500 ++++++++++++++++++ .../base/wasm/scnrm2/docs/types/index.d.ts | 322 +++++++++++ .../blas/base/wasm/scnrm2/docs/types/test.ts | 348 ++++++++++++ .../blas/base/wasm/scnrm2/examples/index.js | 50 ++ .../scnrm2/examples/little_endian_arrays.js | 65 +++ .../blas/base/wasm/scnrm2/examples/module.js | 63 +++ .../base/wasm/scnrm2/lib/binary.browser.js | 33 ++ .../blas/base/wasm/scnrm2/lib/binary.js | 34 ++ .../blas/base/wasm/scnrm2/lib/index.js | 99 ++++ .../@stdlib/blas/base/wasm/scnrm2/lib/main.js | 60 +++ .../blas/base/wasm/scnrm2/lib/module.js | 198 +++++++ .../blas/base/wasm/scnrm2/lib/routine.js | 166 ++++++ .../blas/base/wasm/scnrm2/manifest.json | 36 ++ .../blas/base/wasm/scnrm2/package.json | 79 +++ .../blas/base/wasm/scnrm2/scripts/build.js | 66 +++ .../base/wasm/scnrm2/scripts/template.txt | 33 ++ .../blas/base/wasm/scnrm2/src/Makefile | 243 +++++++++ .../blas/base/wasm/scnrm2/src/exports.json | 4 + .../blas/base/wasm/scnrm2/src/main.wasm | Bin 0 -> 636 bytes .../blas/base/wasm/scnrm2/src/main.wat | 282 ++++++++++ .../blas/base/wasm/scnrm2/test/test.js | 53 ++ .../blas/base/wasm/scnrm2/test/test.main.js | 170 ++++++ .../blas/base/wasm/scnrm2/test/test.module.js | 154 ++++++ .../base/wasm/scnrm2/test/test.module.main.js | 197 +++++++ .../wasm/scnrm2/test/test.module.ndarray.js | 232 ++++++++ .../base/wasm/scnrm2/test/test.ndarray.js | 168 ++++++ .../base/wasm/scnrm2/test/test.routine.js | 71 +++ 33 files changed, 4605 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/exports.json create mode 100755 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md new file mode 100644 index 000000000000..fb48a1d1b9eb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md @@ -0,0 +1,315 @@ + + +# scnrm2 + +> Calculate the L2-norm of a complex single-precision floating-point vector. + +
+ +## Usage + +```javascript +var scnrm2 = require( '@stdlib/blas/base/wasm/scnrm2' ); +``` + +#### scnrm2.main( N, x, strideX ) + +Calculates the L2-norm of a complex single-precision floating-point vector. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var z = scnrm2.main( 3, x, 1 ); +// returns ~9.54 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Complex64Array`][@stdlib/array/complex64]. +- **strideX**: index increment for `x`. + +The `N` and stride parameters determine which elements in the input strided array are accessed at runtime. For example, to compute the L2-norm of every other element in `x`, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var x = new Complex64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); + +var z = scnrm2.main( 2, x, 2 ); +// returns ~4.24 +``` + +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' ); + +// Initial array: +var x0 = new Complex64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, -2.0, 2.0, 3.0 ] ); + +// Create a typed array view: +var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var z = scnrm2.main( 2, x1, 2 ); +// returns ~4.58 +``` + +#### scnrm2.ndarray( N, x, strideX, offsetX ) + +Calculates the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +var z = scnrm2.ndarray( 3, x, 1, 0 ); +// returns ~9.54 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +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 calculate the L2-norm for every other value in `x` starting from the second value, + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); + +var x = new Complex64Array( [ 2.0, 1.0, 2.0, 2.0, -2.0, -2.0, 2.0, 3.0 ] ); + +var z = scnrm2.ndarray( 2, x, 2, 1 ); +// returns ~4.58 +``` + +* * * + +### Module + +#### scnrm2.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new scnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### scnrm2.Module.prototype.main( N, xp, sx ) + +Computes the L2-norm of a complex single-precision floating-point vector. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var Complex64Array = require( '@stdlib/array/complex64' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new scnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'complex64'; + +// Specify a vector length: +var N = 5; + +// Define a pointer (i.e., byte offset) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +var xbuf = oneTo( N*2, 'float32' ); +var x = new Complex64Array( xbuf.buffer ); +mod.write( xptr, x ); + +// Perform computation: +var out = mod.main( N, xptr, 1 ); +// returns ~19.62 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Complex64Array`][@stdlib/array/complex64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. + +#### scnrm2.Module.prototype.ndarray( N, xp, sx, ox ) + +Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var Complex64Array = require( '@stdlib/array/complex64' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new scnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'complex64'; + +// Specify a vector length: +var N = 5; + +// Define a pointer (i.e., byte offset) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +var xbuf = oneTo( N*2, 'float32' ); +var x = new Complex64Array( xbuf.buffer ); +mod.write( xptr, x ); + +// Perform computation: +var out = mod.ndarray( N, xptr, 1, 0 ); +// returns ~19.62 +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both `main` and `ndarray` methods return `0.0`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `scnrm2` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/scnrm2`][@stdlib/blas/base/scnrm2]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/scnrm2`][@stdlib/blas/base/scnrm2]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `scnrm2()` corresponds to the [BLAS][blas] level 1 function [`scnrm2`][scnrm2]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var oneTo = require( '@stdlib/array/one-to' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var scnrm2 = require( '@stdlib/blas/base/wasm/scnrm2' ); + +function main() { + var xbuf; + var out; + var x; + var N; + + // Specify a vector length: + N = 5; + + // Create an input array: + xbuf = oneTo( N*2, 'float32' ); + x = new Complex64Array( xbuf.buffer ); + + // Perform computation: + out = scnrm2.ndarray( N, x, 1, 0 ); + + // Print the result: + console.log( out ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js new file mode 100644 index 000000000000..43c659d38c66 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +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 x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + scnrm2.main( x.length, 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, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js new file mode 100644 index 000000000000..da0a9bbfe514 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new scnrm2.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js new file mode 100644 index 000000000000..2cccd2a84a32 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js @@ -0,0 +1,138 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var byteOffset; + var view; + var xptr; + var mod; + var mem; + var nb; + var N; + var i; + + N = len * 2; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new scnrm2.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing one vector and a complex number: + nb = bytesPerElement( 'complex64' ); + mod.realloc( (N*nb)+nb ); + + // Define a pointer (i.e., byte offset) to the first vector element: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( N, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.main( len, xptr, 1 ); + byteOffset = xptr + ( (i%len)*nb ); + if ( isnanf( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view.getFloat32( byteOffset, true ) ) ) { + 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+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js new file mode 100644 index 000000000000..e3e105316db6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,138 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var byteOffset; + var view; + var xptr; + var mod; + var mem; + var nb; + var N; + var i; + + N = len * 2; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new scnrm2.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing one vector and a complex number: + nb = bytesPerElement( 'complex64' ); + mod.realloc( (N*nb)+nb ); + + // Define a pointer (i.e., byte offset) to the first vector element: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( N, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.ndarray( len, xptr, 1, 0 ); + byteOffset = xptr + ( (i%len)*nb ); + if ( isnanf( view.getFloat32( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( view.getFloat32( byteOffset, true ) ) ) { + 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+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..d3edad77323b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +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 pkg = require( './../package.json' ).name; +var scnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +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 x; + + xbuf = uniform( len*2, -100.0, 100.0, options ); + x = new Complex64Array( xbuf.buffer ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + scnrm2.ndarray( x.length, 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, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt new file mode 100644 index 000000000000..6b1f543fe6e9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt @@ -0,0 +1,500 @@ + +{{alias}}.main( N, x, strideX ) + Computes the L2-norm of a complex single-precision floating-point vector. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `0.0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex64Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 2.0, 1.0 ] ); + > var out = {{alias}}.main( x.length, x, 1 ) + ~3.16 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/complex64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > out = {{alias}}.main( 2, x, 2 ) + ~3.16 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/complex64}}( [ 3.0, 2.0, 1.0, -2.0 ] ); + > var x1 = new {{alias:@stdlib/array/complex64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > out = {{alias}}.main( 1, x1, 1 ) + ~2.24 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Computes the L2-norm of a complex single-precision floating-point vector + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Complex64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/complex64}}( [ 1.0, -2.0, 2.0, 1.0 ] ); + > var out = {{alias}}.ndarray( x.length, x, 1, 0 ) + ~3.16 + + // Using offset parameter: + > var x = new {{alias:@stdlib/array/complex64}}( [ 3.0, 2.0, 3.0, 0.0 ] ); + > out = {{alias}}.ndarray( 1, x, 1, 1 ) + 3.0 + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a + Complex64Array, the function reads each element as a single-precision + floating-point number from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, xp, sx ) + Computes the L2-norm of a complex single-precision floating-point vector. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define a "pointer" (i.e., byte offset) into module memory: + > var xptr = 0; + + // Write data to module memory: + > var xbuf = {{alias:@stdlib/array/one-to}}( 10, 'float32' ); + > var x = new {{alias:@stdlib/array/complex64}}( xbuf.buffer ); + > mod.write( xptr, x ); + + // Perform computation: + > var out = mod.main( 5, xptr, 1 ) + ~19.62 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) + Computes the L2-norm of a complex single-precision floating-point vector + using alternative indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define a "pointer" (i.e., byte offset) into module memory: + > var xptr = 0; + + // Write data to module memory: + > var xbuf = {{alias:@stdlib/array/one-to}}( 10, 'float32' ); + > var x = new {{alias:@stdlib/array/complex64}}( xbuf.buffer ); + > mod.write( xptr, x ); + + // Perform computation: + > var out = mod.ndarray( 5, xptr, 1, 0 ) + ~19.62 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts new file mode 100644 index 000000000000..185d66c15f52 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts @@ -0,0 +1,322 @@ +/* +* @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 { ModuleWrapper, Memory } from '@stdlib/types/wasm'; +import { Complex64Array } from '@stdlib/types/array'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new scnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * var xbuf = oneTo( N*2, 'float32' ); + * var x = new Complex64Array( xbuf.buffer ); + * mod.write( xptr, x ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~19.62 + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = scnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * var xbuf = oneTo( N*2, 'float32' ); + * var x = new Complex64Array( xbuf.buffer ); + * mod.write( xptr, x ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~19.62 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `scnrm2` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the L2-norm of a complex single-precision floating-point vector. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @returns L2-norm + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new scnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * var xbuf = oneTo( N*2, 'float32' ); + * var x = new Complex64Array( xbuf.buffer ); + * mod.write( xptr, x ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~19.62 + */ + main( N: number, xptr: number, strideX: number ): number; + + /** + * Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns L2-norm + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new scnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * var xbuf = oneTo( N*2, 'float32' ); + * var x = new Complex64Array( xbuf.buffer ); + * mod.write( xptr, x ); + * + * // Perform computation: + * var out = mod.ndarray( N, xptr, 1, 0 ); + * // returns ~19.62 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `scnrm2`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the L2-norm of a complex single-precision floating-point vector. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @returns L2-norm + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Define a strided array: + * var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * // Perform operation: + * var out = scnrm2.main( x.length, x, 1 ); + * // returns ~9.53 + */ + main( N: number, x: Complex64Array, strideX: number ): number; + + /** + * Computes the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns L2-norm + * + * @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Define a strided array: + * var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * var out = scnrm2.ndarray( x.length, x, 1, 0 ); + * // returns ~9.53 + */ + ndarray( N: number, x: Complex64Array, strideX: number, offsetX: number ): number; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new scnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * var xbuf = oneTo( N*2, 'float32' ); + * var x = new Complex64Array( xbuf.buffer ); + * mod.write( xptr, x ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~19.62 + */ + Module: ModuleConstructor; +} + +/** +* Computes the L2-norm of a complex single-precision floating-point vector. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - `x` stride length +* @returns L2-norm +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var out = scnrm2.main( x.length, x, 1 ); +* // returns ~9.53 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var out = scnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~9.53 +*/ +declare var scnrm2: Routine; + + +// EXPORTS // + +export = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts new file mode 100644 index 000000000000..6868e0576c74 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts @@ -0,0 +1,348 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import Complex64Array = require( '@stdlib/array/complex64' ); +import Memory = require( '@stdlib/wasm/memory' ); +import scnrm2 = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.main( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.main( '10', x, 1 ); // $ExpectError + scnrm2.main( true, x, 1 ); // $ExpectError + scnrm2.main( false, x, 1 ); // $ExpectError + scnrm2.main( null, x, 1 ); // $ExpectError + scnrm2.main( undefined, x, 1 ); // $ExpectError + scnrm2.main( [], x, 1 ); // $ExpectError + scnrm2.main( {}, x, 1 ); // $ExpectError + scnrm2.main( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Complex64Array... +{ + const x = new Complex64Array( 10 ); + + scnrm2.main( x.length, 10, 1 ); // $ExpectError + scnrm2.main( x.length, '10', 1 ); // $ExpectError + scnrm2.main( x.length, true, 1 ); // $ExpectError + scnrm2.main( x.length, false, 1 ); // $ExpectError + scnrm2.main( x.length, null, 1 ); // $ExpectError + scnrm2.main( x.length, undefined, 1 ); // $ExpectError + scnrm2.main( x.length, [], 1 ); // $ExpectError + scnrm2.main( x.length, {}, 1 ); // $ExpectError + scnrm2.main( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.main( x.length, x, '10' ); // $ExpectError + scnrm2.main( x.length, x, true ); // $ExpectError + scnrm2.main( x.length, x, false ); // $ExpectError + scnrm2.main( x.length, x, null ); // $ExpectError + scnrm2.main( x.length, x, undefined ); // $ExpectError + scnrm2.main( x.length, x, [] ); // $ExpectError + scnrm2.main( x.length, x, {} ); // $ExpectError + scnrm2.main( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Complex64Array( 10 ); + + scnrm2.main(); // $ExpectError + scnrm2.main( x.length ); // $ExpectError + scnrm2.main( x.length, x ); // $ExpectError + scnrm2.main( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray( '10', x, 1, 0 ); // $ExpectError + scnrm2.ndarray( true, x, 1, 0 ); // $ExpectError + scnrm2.ndarray( false, x, 1, 0 ); // $ExpectError + scnrm2.ndarray( null, x, 1, 0 ); // $ExpectError + scnrm2.ndarray( undefined, x, 1, 0 ); // $ExpectError + scnrm2.ndarray( [], x, 1, 0 ); // $ExpectError + scnrm2.ndarray( {}, x, 1, 0 ); // $ExpectError + scnrm2.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex64Array... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray( x.length, 10, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, '10', 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, true, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, false, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, null, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, [], 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, {}, 1, 0 ); // $ExpectError + scnrm2.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray( x.length, x, '10', 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, true, 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, false, 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, null, 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, undefined, 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, [], 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, {}, 0 ); // $ExpectError + scnrm2.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray( x.length, x, 1, '10' ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, true ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, false ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, null ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, undefined ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, [] ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, {} ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Complex64Array( 10 ); + + scnrm2.ndarray(); // $ExpectError + scnrm2.ndarray( x.length ); // $ExpectError + scnrm2.ndarray( x.length, x ); // $ExpectError + scnrm2.ndarray( x.length, x, 1 ); // $ExpectError + scnrm2.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + scnrm2.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + scnrm2.Module( '10' ); // $ExpectError + scnrm2.Module( true ); // $ExpectError + scnrm2.Module( false ); // $ExpectError + scnrm2.Module( null ); // $ExpectError + scnrm2.Module( undefined ); // $ExpectError + scnrm2.Module( [] ); // $ExpectError + scnrm2.Module( {} ); // $ExpectError + scnrm2.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.main( 10, 0, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.main( '10', 0, 10 ); // $ExpectError + mod.main( true, 0, 10 ); // $ExpectError + mod.main( false, 0, 10 ); // $ExpectError + mod.main( null, 0, 10 ); // $ExpectError + mod.main( undefined, 0, 10 ); // $ExpectError + mod.main( [], 0, 10 ); // $ExpectError + mod.main( {}, 0, 10 ); // $ExpectError + mod.main( ( x: number ): number => x, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.main( 10, '10', 1 ); // $ExpectError + mod.main( 10, true, 1 ); // $ExpectError + mod.main( 10, false, 1 ); // $ExpectError + mod.main( 10, null, 1 ); // $ExpectError + mod.main( 10, undefined, 1 ); // $ExpectError + mod.main( 10, [], 1 ); // $ExpectError + mod.main( 10, {}, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.main( 10, 0, '10' ); // $ExpectError + mod.main( 10, 0, true ); // $ExpectError + mod.main( 10, 0, false ); // $ExpectError + mod.main( 10, 0, null ); // $ExpectError + mod.main( 10, 0, undefined ); // $ExpectError + mod.main( 10, 0, [] ); // $ExpectError + mod.main( 10, 0, {} ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray( 10, 0, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray( '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray( 10, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray( 10, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray( 10, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 0, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = scnrm2.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js new file mode 100644 index 000000000000..4da1653dfe87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js @@ -0,0 +1,50 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var scnrm2 = require( './../lib' ); + +function main() { + var xbuf; + var out; + var x; + var N; + + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + N = 5; + + // Create an input array: + xbuf = oneTo( N*2, 'float32' ); + x = new Complex64Array( xbuf.buffer ); + + // Perform computation: + out = scnrm2.ndarray( N, x, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js new file mode 100644 index 000000000000..8e4ae50aa9ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var Float32ArrayLE = require( '@stdlib/array/little-endian-float32' ); +var scnrm2 = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new scnrm2.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define a pointer (i.e., byte offset) for storing the input vector: + var xptr = 0; + + // Create a typed array view over module memory: + var x = new Float32ArrayLE( mod.memory.buffer, xptr, N*2 ); + + // Write values to module memory: + gfillBy( N*2, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + var out = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js new file mode 100644 index 000000000000..1ff0e5ef1101 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js @@ -0,0 +1,63 @@ +/** +* @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 hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var scnrm2 = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new scnrm2.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define a pointer (i.e., byte offset) for storing the input vector: + var xptr = 0; + + // Write vector values to module memory: + var xbuf = oneTo( N*2, 'float32' ); + var x = new Complex64Array( xbuf.buffer ); + mod.write( xptr, x ); + + // Perform computation: + var out = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.browser.js new file mode 100644 index 000000000000..1111b7ea1fb7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGADf39/AX1gBH9/f38BfQIPAQNlbnYGbWVtb3J5AgAAAwQDAAECBzMDEV9fd2FzbV9jYWxsX2N0b3JzAAAIY19zY25ybTIAARBjX3NjbnJtMl9uZGFycmF5AAIK/wMDAwABCxoAIAAgASACQQEgAGsgAmxBACACQQBMGxACC90DAgV9BH8gAEEATARAQwAAAAAPCyADQQF0IQkgAkEBdCELQQAhA0EBIQIDQCAAIANGRQRAAkAgASAJQQJ0aiIMKgIAIgaLIghDAACAWV4EQCAHIAhDAACAGZQiBiAGlJIhB0EAIQIMAQsgCEMAAAAgXQRAIAJBAXEhCkEAIQIgCkUNASAFIAhDAAAAZZQiBSAFlJIhBUEBIQIMAQsgBCAGIAaUkiEECwJAIAwqAgQiBosiCEMAAIBZXgRAIAcgCEMAAIAZlCIGIAaUkiEHQQAhAgwBCyAIQwAAACBdBEAgAkEBcSEKQQAhAiAKRQ0BIAUgCEMAAABllCIFIAWUkiEFQQEhAgwBCyAEIAYgBpSSIQQLIANBAWohAyAJIAtqIQkMAQsLAkAgB0MAAAAAXgRAIARDAACAGZRDAACAGZQgB5IiBSAHIARD//9/f14bIAUgBEMAAAAAXxshBEMAAIBlIQYMAQtDAACAPyEGIAVDAAAAAF5FDQAgBEMAAAAAX0UgBEP//39/XnJFBEAgBSEEQwAAABohBgwBCyAEkSIEIAWRQwAAABqUIgUgBCAFXSIAGyAFIAQgABsiBJUiBSAFlLtEAAAAAAAA8D+gIAQgBJS7orYhBAsgBiAEkZQL' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js new file mode 100644 index 000000000000..6f02393f96e5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js new file mode 100644 index 000000000000..0f68f0682a07 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* WebAssembly routine to calculate the L2-norm of a complex single-precision floating-point vector. +* +* @module @stdlib/blas/base/wasm/scnrm2 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var scnrm2 = require( '@stdlib/blas/base/wasm/scnrm2' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.main( x.length, x, 1 ); +* // returns ~9.53 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var scnrm2 = require( '@stdlib/blas/base/wasm/scnrm2' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~9.53 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var scnrm2 = require( '@stdlib/blas/base/wasm/scnrm2' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new scnrm2.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Specify a vector length: +* var N = 5; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* var xbuf = oneTo( N*2, 'float32' ); +* var x = new Complex64Array( xbuf.buffer ); +* mod.write( xptr, x ); +* +* // Perform computation: +* var out = mod.main( N, xptr, 1 ); +* // returns ~19.62 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js new file mode 100644 index 000000000000..3023477de8dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js @@ -0,0 +1,60 @@ +/** +* @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 Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to calculate the L2-norm of a complex single-precision floating-point vector. +* +* @name scnrm2 +* @type {Routine} +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.main( x.length, x, 1 ); +* // returns ~9.54 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~9.54 +*/ +var scnrm2 = new Routine(); +scnrm2.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = scnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js new file mode 100644 index 000000000000..dab2872b4773 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js @@ -0,0 +1,198 @@ +/** +* @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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var scnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* scnrm2.initializeSync(); +* +* // Specify a vector length: +* var N = 5; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* var xbuf = oneTo( N*2, 'float32' ); +* var x = new Complex64Array( xbuf.buffer ); +* scnrm2.write( xptr, x ); +* +* // Perform computation: +* var out = scnrm2.main( N, xptr, 1 ); +* // returns ~19.62 +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Calculates the L2-norm of a complex single-precision floating-point vector. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @returns {number} the L2-norm +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var scnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* scnrm2.initializeSync(); +* +* // Specify a vector length: +* var N = 5; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* var xbuf = oneTo( N*2, 'float32' ); +* var x = new Complex64Array( xbuf.buffer ); +* scnrm2.write( xptr, x ); +* +* // Perform computation: +* var out = scnrm2.main( N, xptr, 1 ); +* // returns ~19.62 +*/ +setReadOnly( Module.prototype, 'main', function scnrm2( N, xptr, strideX ) { + return this._instance.exports.c_scnrm2( N, xptr, strideX ); +}); + +/** +* Calculates the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {number} the L2-norm +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var scnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* scnrm2.initializeSync(); +* +* // Specify a vector length: +* var N = 5; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* var xbuf = oneTo( N*2, 'float32' ); +* var x = new Complex64Array( xbuf.buffer ); +* scnrm2.write( xptr, x ); +* +* // Perform computation: +* var out = scnrm2.ndarray( N, xptr, 1, 0 ); +* // returns ~19.62 +*/ +setReadOnly( Module.prototype, 'ndarray', function scnrm2( N, xptr, strideX, offsetX ) { + return this._instance.exports.c_scnrm2_ndarray( N, xptr, strideX, offsetX ); +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js new file mode 100644 index 000000000000..c04810431c44 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js @@ -0,0 +1,166 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new routine: +* var scnrm2 = new Routine(); +* +* // Initialize the module: +* scnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.main( x.length, x, 1 ); +* // returns ~9.54 +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new routine: +* var scnrm2 = new Routine(); +* +* // Initialize the module: +* scnrm2.initializeSync(); +* +* // Define strided arrays: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~9.54 +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Calculates the L2-norm of a complex single-precision floating-point vector. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {number} the L2-norm +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new routine: +* var scnrm2 = new Routine(); +* +* // Initialize the module: +* scnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.main( x.length, x, 1 ); +* // returns ~9.54 +*/ +setReadOnly( Routine.prototype, 'main', function scnrm2( N, x, strideX ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Calculates the L2-norm of a complex single-precision floating-point vector using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {number} the L2-norm +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* // Create a new routine: +* var scnrm2 = new Routine(); +* +* // Initialize the module: +* scnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Perform operation: +* var out = scnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~9.54 +*/ +setReadOnly( Routine.prototype, 'ndarray', function scnrm2( N, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input array to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ) + ]); + p0 = ptrs[ 0 ]; + + // Perform computation by calling the corresponding parent method: + return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/manifest.json b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/manifest.json new file mode 100644 index 000000000000..59c16aebd517 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "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": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/scnrm2" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/package.json b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/package.json new file mode 100644 index 000000000000..f9f2ea997f27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/package.json @@ -0,0 +1,79 @@ +{ + "name": "@stdlib/blas/base/wasm/scnrm2", + "version": "0.0.0", + "description": "Multiply a vector `x` by a scalar `alpha`.", + "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/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "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", + "scnrm2", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "float32", + "float", + "float32array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/build.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/build.js new file mode 100644 index 000000000000..66bf9650b6d6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/build.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); +var currentYear = require( '@stdlib/time/current-year' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; +var YEAR = '{{YEAR}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, YEAR, currentYear().toString() ); + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/template.txt new file mode 100644 index 000000000000..f66cdb9735b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) {{YEAR}} 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 base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile new file mode 100644 index 000000000000..eb51121eec4c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile @@ -0,0 +1,243 @@ +#/ +# @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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# 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 to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the integer size: +ifdef CBLAS_INT + INT_TYPE := $(CBLAS_INT) +else + INT_TYPE := int32_t +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -flto \ + -Wall \ + -pedantic \ + -D CBLAS_INT=$(INT_TYPE) + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -Oz \ + -fwasm-exceptions \ + -s SUPPORT_LONGJMP=1 \ + -s SIDE_MODULE=2 \ + -s EXPORTED_FUNCTIONS="$(shell cat exports.json | tr -d ' \t\n' | sed s/\"/\'/g)" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 \ + -s WASM_BIGINT=0 + +# 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 WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @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: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @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 wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @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`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js $(browser_js_targets) + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/exports.json b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/exports.json new file mode 100644 index 000000000000..1030091177bf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/exports.json @@ -0,0 +1,4 @@ +[ + "_c_scnrm2", + "_c_scnrm2_ndarray" +] diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/main.wasm b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..f383b02477fa3399573c13f2f9447b6cfc4f56e3 GIT binary patch literal 636 zcmcgoJx&5a6n-=Fb{7~37%QN8v!#VGdH{B#Sa|^pSO`$aZ(N9mf~>t2WbKWIu;DD; z!5iS4AzZ;JX5P>DGw(rvITOIAS{SaUPxHy;l|Y+|bJYXrsVvLHric9SE2~0{<}dzi zG+U%=37}Ackim^QOOjWXN(TMuG#RWG=@OtYNS1?nI=co@JB7)7*iX~`8f5996q9uW z2uP5O1;K>mGzO00p;?pqM@esk83E@Q-2$JgCKZd7DO$qH=ok#=MyiNa)O{Nx8Iho3 zELY>Od?6w9-@^h^-yXXdQ9v%P=b=x2zB2*yWm#xf2I??`b)QYi)~VF42=b1-Q675a zF~zfXmV$KDK+TqHh5un?rymz^%s4hj!9>e!MBz@t*@O9u8U7ZSp9# z50EsC1CET(3KrZlK6$R!ZCBs~YoDko@0C19f`%gzZbKw*YdH Date: Wed, 23 Apr 2025 13:05:10 +0530 Subject: [PATCH 02/11] remove: unused variables Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- .../blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js index 2cccd2a84a32..191d05d5a06a 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js @@ -36,9 +36,6 @@ var scnrm2 = require( './../lib' ); var opts = { 'skip': !hasWebAssemblySupport() }; -var options = { - 'dtype': 'float32' -}; // FUNCTIONS // From 5857b3264dabe2fa586e89b2ed21c8f49ae39e56 Mon Sep 17 00:00:00 2001 From: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:06:40 +0530 Subject: [PATCH 03/11] fix: benchmark options Signed-off-by: Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com> --- .../blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js index 191d05d5a06a..2cccd2a84a32 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js @@ -36,6 +36,9 @@ var scnrm2 = require( './../lib' ); var opts = { 'skip': !hasWebAssemblySupport() }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // From bbdfab952ff921c42113f6c9a8ad01d1909370d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 23 Apr 2025 07:47:32 +0000 Subject: [PATCH 04/11] chore: update copyright years --- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md | 2 +- .../@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js | 2 +- .../blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js | 2 +- .../blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js | 2 +- .../blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts | 2 +- .../@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts | 2 +- .../@stdlib/blas/base/wasm/scnrm2/examples/index.js | 2 +- .../blas/base/wasm/scnrm2/examples/little_endian_arrays.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/examples/module.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile | 2 +- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.main.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.module.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js | 2 +- .../@stdlib/blas/base/wasm/scnrm2/test/test.routine.js | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md index fb48a1d1b9eb..b41f5017fe79 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +Copyright (c) 2025 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js index 43c659d38c66..fb43167155c4 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js index da0a9bbfe514..3489681a3e8f 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js index 2cccd2a84a32..4771aac432cd 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js index e3e105316db6..76befe5bc4d6 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js index d3edad77323b..bf14cffee928 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts index 185d66c15f52..8c52fdbdbcc8 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts index 6868e0576c74..728570cb3348 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js index 4da1653dfe87..c99ab0a28773 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js index 8e4ae50aa9ba..fd046cd6f8ac 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/little_endian_arrays.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js index 1ff0e5ef1101..5cce735d2e97 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/examples/module.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js index 6f02393f96e5..2b83fe651780 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/binary.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js index 0f68f0682a07..44f882c83cb8 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js index 3023477de8dd..6b7592f23f38 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js index dab2872b4773..f0e23d4995db 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/module.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js index c04810431c44..b54f240e92c3 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/lib/routine.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile index eb51121eec4c..1b1f35347760 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js index 4685c133a4b5..214dc0162dcd 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js index 4866a3283880..edf98df2c90c 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.js index 9adcb07e22fa..0cdcd97ef151 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js index 733e90cec69b..78689ef3f6eb 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js index 3d44acb3419d..4a234957ebf7 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js index fe4a8ec76779..d968d9eb9381 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.routine.js index 56a4b67daaf0..d90a5804a8e1 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.routine.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.routine.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 879da5f04d1f767d39bfed5bb4a033af8cbf9ae8 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 20 Jun 2025 05:01:58 -0700 Subject: [PATCH 05/11] docs: avoid redeclaring variable Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt index 6b1f543fe6e9..913c26aec281 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/docs/repl.txt @@ -80,7 +80,7 @@ ~3.16 // Using offset parameter: - > var x = new {{alias:@stdlib/array/complex64}}( [ 3.0, 2.0, 3.0, 0.0 ] ); + > x = new {{alias:@stdlib/array/complex64}}( [ 3.0, 2.0, 3.0, 0.0 ] ); > out = {{alias}}.ndarray( 1, x, 1, 1 ) 3.0 From 06b6096dde13899f1178c1ad5f4279bebeaf6d29 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 20 Jun 2025 05:11:02 -0700 Subject: [PATCH 06/11] Apply suggestions from code review Signed-off-by: Athan --- .../blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js | 4 ++-- .../base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js index 4771aac432cd..9c2317f0e8ca 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.main.js @@ -80,9 +80,9 @@ function createBenchmark( len ) { // Initialize the module: mod.initializeSync(); // eslint-disable-line node/no-sync - // Reallocate the underlying memory to allow storing one vector and a complex number: + // Reallocate the underlying memory to allow storing one vector: nb = bytesPerElement( 'complex64' ); - mod.realloc( (N*nb)+nb ); + mod.realloc( N*nb ); // Define a pointer (i.e., byte offset) to the first vector element: xptr = 0; diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js index 76befe5bc4d6..0e761b12e210 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/benchmark/benchmark.module.ndarray.js @@ -80,9 +80,9 @@ function createBenchmark( len ) { // Initialize the module: mod.initializeSync(); // eslint-disable-line node/no-sync - // Reallocate the underlying memory to allow storing one vector and a complex number: + // Reallocate the underlying memory to allow storing one vector: nb = bytesPerElement( 'complex64' ); - mod.realloc( (N*nb)+nb ); + mod.realloc( N*nb ); // Define a pointer (i.e., byte offset) to the first vector element: xptr = 0; From 115b923bb61298103ef35e9cd334a63a65600930 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 20 Jun 2025 05:15:30 -0700 Subject: [PATCH 07/11] style: fix alignment Signed-off-by: Athan --- .../@stdlib/blas/base/wasm/scnrm2/test/test.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js index edf98df2c90c..ac6a13c591a7 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js @@ -158,7 +158,7 @@ tape( 'the `main` method supports view offsets', function test( t ) { -2.0, -2.0, 2.0, // 2 - 3.0 // 2 + 3.0 // 2 ]); x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*2 ); // start at 3rd element From d583a967da11178c29b30f550ab235414c60bcaf Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 20 Jun 2025 05:15:59 -0700 Subject: [PATCH 08/11] style: fix alignment Signed-off-by: Athan --- .../@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js index 4a234957ebf7..d694d26078c5 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js @@ -197,7 +197,7 @@ tape( 'a module instance has an `ndarray` method which supports an `x` offset', -2.0, -2.0, 2.0, // 2 - 3.0 // 2 + 3.0 // 2 ])); nrm2 = mod.ndarray( 2, xp, 2, 2 ); From 399cacaba50cbf6b7853d45eec942a40c471931e Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Sun, 22 Jun 2025 15:13:03 +0530 Subject: [PATCH 09/11] chore: fix test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/base/wasm/scnrm2/test/test.main.js | 38 +++++++++---------- .../base/wasm/scnrm2/test/test.module.main.js | 34 ++++++++--------- .../wasm/scnrm2/test/test.module.ndarray.js | 36 ++++++++---------- .../base/wasm/scnrm2/test/test.ndarray.js | 36 ++++++++---------- 4 files changed, 64 insertions(+), 80 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js index ac6a13c591a7..5d8e627d1ea0 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.main.js @@ -30,28 +30,24 @@ var scnrm2 = require( './../lib' ); // FUNCTIONS // /** -* Tests for element-wise approximate equality. +* Tests for element approximate equality. * * @private * @param {Object} t - test object -* @param {Collection} actual - actual values -* @param {Collection} expected - expected values +* @param {number} actual - actual value +* @param {number} expected - expected value * @param {number} rtol - relative tolerance */ function isApprox( t, actual, expected, rtol ) { var delta; var tol; - var i; - - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -73,15 +69,15 @@ tape( 'the `main` method calculates the L2-norm of a vector', function test( t ) var nrm2; var x; - x = new Complex64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + x = new Complex64Array( [ 3.0, -4.0, -6.0, 8.0, 0.0, 3.0 ] ); nrm2 = scnrm2.main( x.length, x, 1 ); - isApprox( t, nrm2, 7.4, 1.0 ); + isApprox( t, nrm2, 11.575836902790, 1.0 ); x = new Complex64Array( [ -4.0, 0.0 ] ); nrm2 = scnrm2.main( x.length, x, 1 ); - isApprox( t, nrm2, 4.0, 1.0 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); t.end(); }); @@ -104,7 +100,7 @@ tape( 'the `main` method supports a `stride` parameter', function test( t ) { ]); nrm2 = scnrm2.main( 3, x, 2 ); - isApprox( t, nrm2, 8.83, 1.0 ); + isApprox( t, nrm2, 8.831760866327, 1.0 ); t.end(); }); @@ -123,7 +119,7 @@ tape( 'the `main` method supports a negative `stride` parameter', function test( ]); nrm2 = scnrm2.main( 2, x, -2 ); - isApprox( t, nrm2, 8.54, 1.0 ); + isApprox( t, nrm2, 8.544003745317, 1.0 ); t.end(); }); @@ -163,8 +159,8 @@ tape( 'the `main` method supports view offsets', function test( t ) { x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*2 ); // start at 3rd element - nrm2 = scnrm2.main( 4, x1, 2 ); - isApprox( t, nrm2, 4.24, 1.0 ); + nrm2 = scnrm2.main( 2, x1, 2 ); + isApprox( t, nrm2, 4.24264068711, 1.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js index 78689ef3f6eb..f5f95704f0ac 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.main.js @@ -33,28 +33,24 @@ var Module = require( './../lib' ).Module; // FUNCTIONS // /** -* Tests for element-wise approximate equality. +* Tests for element approximate equality. * * @private * @param {Object} t - test object -* @param {Collection} actual - actual values -* @param {Collection} expected - expected values +* @param {number} actual - actual value +* @param {number} expected - expected value * @param {number} rtol - relative tolerance */ function isApprox( t, actual, expected, rtol ) { var delta; var tol; - var i; - - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -93,10 +89,10 @@ tape( 'a module instance has a `main` method which calculates the L2-norm of a v xp = 0; - mod.write( xp, new Complex64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) ); + mod.write( xp, new Complex64Array( [ 3.0, -4.0, -6.0, 8.0, 0.0, 3.0 ] ) ); nrm2 = mod.main( 3, xp, 1 ); - isApprox( t, nrm2, 7.4, 1.0 ); + isApprox( t, nrm2, 11.575836902790, 1.0 ); // Short datasets: xp = 0; @@ -104,7 +100,7 @@ tape( 'a module instance has a `main` method which calculates the L2-norm of a v mod.write( xp, new Complex64Array( [ -4.0, 0.0 ] ) ); nrm2 = mod.main( 1, xp, 1 ); - isApprox( t, nrm2, 4.0, 1.0 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); t.end(); }); @@ -137,7 +133,7 @@ tape( 'a module instance has a `main` method which supports a `stride` parameter ])); nrm2 = mod.main( 3, xp, 2 ); - isApprox( t, nrm2, 8.83, 1.0 ); + isApprox( t, nrm2, 8.831760866327, 1.0 ); t.end(); }); @@ -166,7 +162,7 @@ tape( 'a module instance has a `main` method which supports a negative `stride` ])); nrm2 = mod.main( 2, xp, -2 ); - isApprox( t, nrm2, 8.54, 1.0 ); + isApprox( t, nrm2, 8.544003745317, 1.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js index d694d26078c5..038d6134bea7 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js @@ -33,28 +33,24 @@ var Module = require( './../lib' ).Module; // FUNCTIONS // /** -* Tests for element-wise approximate equality. +* Tests for element approximate equality. * * @private * @param {Object} t - test object -* @param {Collection} actual - actual values -* @param {Collection} expected - expected values +* @param {number} actual - actual value +* @param {number} expected - expected value * @param {number} rtol - relative tolerance */ function isApprox( t, actual, expected, rtol ) { var delta; var tol; - var i; - - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -93,10 +89,10 @@ tape( 'a module instance has an `ndarray` method which calculates the L2-norm of xp = 0; - mod.write( xp, new Complex64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) ); + mod.write( xp, new Complex64Array( [ 3.0, -4.0, -6.0, 8.0, 0.0, 3.0 ] ) ); nrm2 = mod.ndarray( 3, xp, 1, 0 ); - isApprox( t, nrm2, 7.4, 1.0 ); + isApprox( t, nrm2, 11.575836902790, 1.0 ); // Short datasets: xp = 0; @@ -104,7 +100,7 @@ tape( 'a module instance has an `ndarray` method which calculates the L2-norm of mod.write( xp, new Complex64Array( [ -4.0, 0.0 ] ) ); nrm2 = mod.ndarray( 1, xp, 1, 0 ); - isApprox( t, nrm2, 4.0, 1.0 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); t.end(); }); @@ -137,7 +133,7 @@ tape( 'a module instance has an `ndarray` method which supports a `stride` param ])); nrm2 = mod.ndarray( 3, xp, 2, 0 ); - isApprox( t, nrm2, 8.83, 1.0 ); + isApprox( t, nrm2, 8.831760866327, 1.0 ); t.end(); }); @@ -168,7 +164,7 @@ tape( 'a module instance has an `ndarray` method which supports a negative `stri ])); nrm2 = mod.ndarray( 2, xp, -2, 3 ); - isApprox( t, nrm2, 4.24, 1.0 ); + isApprox( t, nrm2, 4.24264068711, 1.0 ); t.end(); }); @@ -201,7 +197,7 @@ tape( 'a module instance has an `ndarray` method which supports an `x` offset', ])); nrm2 = mod.ndarray( 2, xp, 2, 2 ); - isApprox( t, nrm2, 4.24, 1.0 ); + isApprox( t, nrm2, 4.24264068711, 1.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js index d968d9eb9381..364571ad7637 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js @@ -30,28 +30,24 @@ var scnrm2 = require( './../lib' ); // FUNCTIONS // /** -* Tests for element-wise approximate equality. +* Tests for element approximate equality. * * @private * @param {Object} t - test object -* @param {Collection} actual - actual values -* @param {Collection} expected - expected values +* @param {number} actual - actual value +* @param {number} expected - expected value * @param {number} rtol - relative tolerance */ function isApprox( t, actual, expected, rtol ) { var delta; var tol; - var i; - - t.strictEqual( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - if ( actual[ i ] === expected[ i ] ) { - t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); - } else { - delta = abs( actual[ i ] - expected[ i ] ); - tol = rtol * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } + + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( actual - expected ); + tol = rtol * EPS * abs( expected ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual+'. expected: '+expected+'. delta: '+delta+'. tol: '+tol+'.' ); } } @@ -73,16 +69,16 @@ tape( 'the `ndarray` method calculates the L2-norm of a vector', function test( var nrm2; var x; - x = new Complex64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + x = new Complex64Array( [ 3.0, -4.0, -6.0, 8.0, 0.0, 3.0 ] ); nrm2 = scnrm2.ndarray( x.length, x, 1, 0 ); - isApprox( t, nrm2, 7.4, 2.0 ); + isApprox( t, nrm2, 11.575836902790, 1.0 ); // Short datasets: x = new Complex64Array( [ -4.0, 0.0 ] ); nrm2 = scnrm2.ndarray( x.length, x, 1, 0 ); - isApprox( t, nrm2, 4.0, 1.0 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); t.end(); }); @@ -105,7 +101,7 @@ tape( 'the `ndarray` method supports a `stride` parameter', function test( t ) { ]); nrm2 = scnrm2.ndarray( 3, x, 2, 0 ); - isApprox( t, nrm2, 8.83, 1.0 ); + isApprox( t, nrm2, 8.831760866327, 1.0 ); t.end(); }); @@ -124,7 +120,7 @@ tape( 'the `ndarray` method supports a negative stride parameter', function test ]); nrm2 = scnrm2.ndarray( 2, x, -2, x.length-2 ); - isApprox( t, nrm2, 8.54, 1.0 ); + isApprox( t, nrm2, 8.544003745317, 1.0 ); t.end(); }); @@ -147,7 +143,7 @@ tape( 'the `ndarray` method supports an `offset` parameter', function test( t ) ]); nrm2 = scnrm2.ndarray( 2, x, 2, 2 ); - isApprox( t, nrm2, 4.24, 1.0 ); + isApprox( t, nrm2, 4.24264068711, 1.0 ); t.end(); }); From 4e32e97f036f6de3972d67d684a8f649e8c2430f Mon Sep 17 00:00:00 2001 From: ShabiShett07 Date: Sun, 22 Jun 2025 15:19:03 +0530 Subject: [PATCH 10/11] chore: fix test cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/wasm/scnrm2/test/test.module.ndarray.js | 16 ++++++++-------- .../blas/base/wasm/scnrm2/test/test.ndarray.js | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js index 038d6134bea7..23329f34cb0f 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.module.ndarray.js @@ -153,18 +153,18 @@ tape( 'a module instance has an `ndarray` method which supports a negative `stri xp = 0; mod.write( xp, new Complex64Array([ - 1.0, // 2 - 2.0, // 2 + 1.0, 2.0, - -7.0, - -2.0, // 1 - 3.0, // 1 - 4.0, - 2.0 + 2.0, // 2 + -7.0, // 2 + -2.0, + 3.0, + 4.0, // 1 + 2.0 // 1 ])); nrm2 = mod.ndarray( 2, xp, -2, 3 ); - isApprox( t, nrm2, 4.24264068711, 1.0 ); + isApprox( t, nrm2, 8.544003745317, 1.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js index 364571ad7637..91904ad3fbd0 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js @@ -111,6 +111,8 @@ tape( 'the `ndarray` method supports a negative stride parameter', function test var x; x = new Complex64Array([ + 1.0, + 2.0, 2.0, // 2 -7.0, // 2 -2.0, @@ -119,7 +121,7 @@ tape( 'the `ndarray` method supports a negative stride parameter', function test 2.0 // 1 ]); - nrm2 = scnrm2.ndarray( 2, x, -2, x.length-2 ); + nrm2 = scnrm2.ndarray( 2, x, -2, x.length-1); isApprox( t, nrm2, 8.544003745317, 1.0 ); t.end(); From badc99c16a6201686b627c81d5e9e1a35ef1d574 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 22 Jun 2025 03:20:17 -0700 Subject: [PATCH 11/11] style: align comment Signed-off-by: Athan --- .../@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js index 91904ad3fbd0..28787b4cd317 100644 --- a/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/wasm/scnrm2/test/test.ndarray.js @@ -141,7 +141,7 @@ tape( 'the `ndarray` method supports an `offset` parameter', function test( t ) -2.0, -2.0, 2.0, // 2 - 3.0 // 2 + 3.0 // 2 ]); nrm2 = scnrm2.ndarray( 2, x, 2, 2 );