From 2c1077017241399a28875fe35668425d4fdb8988 Mon Sep 17 00:00:00 2001 From: 0PrashantYadav0 Date: Wed, 5 Aug 2026 18:07:14 +0530 Subject: [PATCH] feat: add stats/strided/wasm/dnanmean --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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 --- --- .../stats/strided/dnanmean/manifest.json | 2 +- .../stats/strided/dnanmeanpn/manifest.json | 2 +- .../stats/strided/wasm/dnanmean/README.md | 291 ++++++++++ .../wasm/dnanmean/benchmark/benchmark.js | 107 ++++ .../dnanmean/benchmark/benchmark.module.js | 67 +++ .../benchmark/benchmark.module.main.js | 131 +++++ .../benchmark/benchmark.module.ndarray.js | 131 +++++ .../dnanmean/benchmark/benchmark.ndarray.js | 107 ++++ .../stats/strided/wasm/dnanmean/docs/repl.txt | 502 ++++++++++++++++++ .../wasm/dnanmean/docs/types/index.d.ts | 316 +++++++++++ .../strided/wasm/dnanmean/docs/types/test.ts | 347 ++++++++++++ .../strided/wasm/dnanmean/examples/index.js | 40 ++ .../dnanmean/examples/little_endian_arrays.js | 65 +++ .../strided/wasm/dnanmean/examples/module.js | 63 +++ .../wasm/dnanmean/lib/binary.browser.js | 33 ++ .../stats/strided/wasm/dnanmean/lib/binary.js | 34 ++ .../stats/strided/wasm/dnanmean/lib/index.js | 92 ++++ .../stats/strided/wasm/dnanmean/lib/main.js | 63 +++ .../stats/strided/wasm/dnanmean/lib/module.js | 198 +++++++ .../strided/wasm/dnanmean/lib/routine.js | 166 ++++++ .../stats/strided/wasm/dnanmean/manifest.json | 36 ++ .../stats/strided/wasm/dnanmean/package.json | 82 +++ .../strided/wasm/dnanmean/scripts/build.js | 66 +++ .../wasm/dnanmean/scripts/postbuild.wat.js | 64 +++ .../wasm/dnanmean/scripts/template.txt | 33 ++ .../stats/strided/wasm/dnanmean/src/Makefile | 244 +++++++++ .../strided/wasm/dnanmean/src/exports.json | 4 + .../stats/strided/wasm/dnanmean/src/main.wasm | Bin 0 -> 422 bytes .../stats/strided/wasm/dnanmean/src/main.wat | 166 ++++++ .../stats/strided/wasm/dnanmean/test/test.js | 53 ++ .../strided/wasm/dnanmean/test/test.main.js | 169 ++++++ .../strided/wasm/dnanmean/test/test.module.js | 154 ++++++ .../wasm/dnanmean/test/test.module.main.js | 242 +++++++++ .../wasm/dnanmean/test/test.module.ndarray.js | 247 +++++++++ .../wasm/dnanmean/test/test.ndarray.js | 165 ++++++ .../wasm/dnanmean/test/test.routine.js | 71 +++ 36 files changed, 4551 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/routine.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/build.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/postbuild.wat.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/exports.json create mode 100755 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/main.wasm create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/main.wat create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/test/test.routine.js diff --git a/lib/node_modules/@stdlib/stats/strided/dnanmean/manifest.json b/lib/node_modules/@stdlib/stats/strided/dnanmean/manifest.json index a8e303e431e3..9010b05f1ce2 100644 --- a/lib/node_modules/@stdlib/stats/strided/dnanmean/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/dnanmean/manifest.json @@ -83,7 +83,7 @@ ] }, { - "task": "", + "task": "build", "wasm": true, "src": [ "./src/main.c" diff --git a/lib/node_modules/@stdlib/stats/strided/dnanmeanpn/manifest.json b/lib/node_modules/@stdlib/stats/strided/dnanmeanpn/manifest.json index 99aaf0c4da72..b57c81aaa987 100644 --- a/lib/node_modules/@stdlib/stats/strided/dnanmeanpn/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/dnanmeanpn/manifest.json @@ -80,7 +80,7 @@ ] }, { - "task": "", + "task": "build", "wasm": true, "src": [ "./src/main.c" diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/README.md b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/README.md new file mode 100644 index 000000000000..6ad320dfa867 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/README.md @@ -0,0 +1,291 @@ + + +# dnanmean + +> Compute the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. + +
+ +## Usage + +```javascript +var dnanmean = require( '@stdlib/stats/strided/wasm/dnanmean' ); +``` + +#### dnanmean.main( N, x, strideX ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); + +var y = dnanmean.main( x.length, x, 1 ); +// returns ~0.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); // eslint-disable-line max-len + +var y = dnanmean.main( 5, x, 2 ); +// returns 1.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); // eslint-disable-line max-len +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var y = dnanmean.main( 5, x1, 2 ); +// returns 1.25 +``` + +#### dnanmean.ndarray( N, x, strideX, offsetX ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); + +var y = dnanmean.ndarray( x.length, x, 1, 0 ); +// returns ~0.3333 +``` + +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 access every other element starting from the second element: + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); // eslint-disable-line max-len + +var y = dnanmean.ndarray( 5, x, 2, 1 ); +// returns 1.25 +``` + +* * * + +### Module + +#### dnanmean.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 new routine: +var mod = new dnanmean.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### dnanmean.Module.prototype.main( N, xp, sx ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// 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 new routine: +var mod = new dnanmean.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 3; + +// Define a pointer (i.e., byte offset) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var y = mod.main( N, xptr, 1 ); +// returns 2.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: stride length for `x`. + +#### dnanmean.Module.prototype.ndarray( N, xp, sx, ox ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// 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 new routine: +var mod = new dnanmean.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 3; + +// Define a pointer (i.e., byte offset) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var y = mod.ndarray( N, xptr, 1, 0 ); +// returns 2.0 +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both `main` and `ndarray` methods return `NaN`. +- If every indexed element is `NaN`, both `main` and `ndarray` methods return `NaN`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dnanmean` 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/stats/strided/dnanmean`][@stdlib/stats/strided/dnanmean]. 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/stats/strided/dnanmean`][@stdlib/stats/strided/dnanmean]. 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. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var dnanmean = require( '@stdlib/stats/strided/wasm/dnanmean' ); + +// Create an input array containing NaN values: +var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0, NaN, 3.0 ] ); +console.log( x ); + +// Perform computation, ignoring NaN values: +var y = dnanmean.ndarray( x.length, x, 1, 0 ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.js new file mode 100644 index 000000000000..1365dd1e7364 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dnanmean = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = dnanmean.main( x.length, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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( format( '%s:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.js new file mode 100644 index 000000000000..9d1008c4d3e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dnanmean = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( format( '%s:Module:constructor', pkg ), 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 dnanmean.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/stats/strided/wasm/dnanmean/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.main.js new file mode 100644 index 000000000000..eececd82a463 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.main.js @@ -0,0 +1,131 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dnanmean = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// 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 xptr; + var mod; + var mem; + var nb; + var v; + var i; + + // Create a new routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dnanmean.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line n/no-sync + + // Reallocate the underlying memory to allow storing a vector: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*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( len, -10.0, 10.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mod.main( len, xptr, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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( format( '%s::module,pointers:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.ndarray.js new file mode 100644 index 000000000000..09331ea879f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,131 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dnanmean = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// 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 xptr; + var mod; + var mem; + var nb; + var v; + var i; + + // Create a new routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dnanmean.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line n/no-sync + + // Reallocate the underlying memory to allow storing a vector: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*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( len, -10.0, 10.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mod.ndarray( len, xptr, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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( format( '%s::module,pointers:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..0a67bd20c19e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/benchmark/benchmark.ndarray.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dnanmean = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = dnanmean.ndarray( x.length, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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( format( '%s:ndarray:len=%d', pkg, len ), opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/repl.txt new file mode 100644 index 000000000000..db934c3d3c9e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/repl.txt @@ -0,0 +1,502 @@ + +{{alias}}.main( N, x, strideX ) + Computes the arithmetic mean of a double-precision floating-point strided + array, ignoring `NaN` values. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + If every indexed element is `NaN`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: float + The arithmetic mean. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); + > {{alias}}.main( x.length, x, 1 ) + ~0.3333 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); + > {{alias}}.main( 4, x, 2 ) + ~0.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}.main( 4, x1, 2 ) + ~-0.3333 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Computes the arithmetic mean of a double-precision floating-point strided + array, ignoring `NaN` values and alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: float + The arithmetic mean. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); + > {{alias}}.ndarray( x.length, x, 1, 0 ) + ~0.3333 + + // Using offset parameter: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > {{alias}}.ndarray( 4, x, 2, 1 ) + ~-0.3333 + + +{{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 Float64Array, + the function writes each element as a double-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 + double-precision floating-point numbers contained in a Float64Array as + signed 32-bit integers, you must first convert the Float64Array 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 single-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 Float64Array, + the function reads each element as a double-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 + double-precision floating-point numbers contained in a Float64Array as + signed 32-bit integers, you must convert the Float64Array 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 single-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 arithmetic mean of a double-precision floating-point strided + array, ignoring `NaN` values. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Stride length. + + Returns + ------- + out: float + The arithmetic mean. + + 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: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 3, 'float64' ) ); + + // Perform computation: + > var s = mod.main( 3, xptr, 1 ) + 2.0 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) + Computes the arithmetic mean of a double-precision floating-point strided + array, ignoring `NaN` values and alternative + indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Stride length. + + ox: integer + Starting index. + + Returns + ------- + out: float + The arithmetic mean. + + 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: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 3, 'float64' ) ); + + // Perform computation: + > var s = mod.ndarray( 3, xptr, 1, 0 ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/index.d.ts new file mode 100644 index 000000000000..d6bbf4536982 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/index.d.ts @@ -0,0 +1,316 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* 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' ); + * + * // 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 new routine: + * var mod = new dnanmean.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 3; + * + * // Define a pointer (i.e., byte offset) to the first vector element: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var y = mod.main( N, xptr, 1 ); + * // returns 2.0 + */ + 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' ); + * + * // 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 new routine: + * var mod = dnanmean.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 3; + * + * // Define a pointer (i.e., byte offset) to the first vector element: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var y = mod.main( N, xptr, 1 ); + * // returns 2.0 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `dnanmean` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - stride length + * @returns arithmetic mean + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // 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 new routine: + * var mod = new dnanmean.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 3; + * + * // Define a pointer (i.e., byte offset) to the first vector element: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var y = mod.main( N, xptr, 1 ); + * // returns 2.0 + */ + main( N: number, xptr: number, strideX: number ): number; + + /** + * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - stride length + * @param offsetX - starting index + * @returns arithmetic mean + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // 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 new routine: + * var mod = new dnanmean.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 3; + * + * // Define a pointer (i.e., byte offset) to the first vector element: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var y = mod.ndarray( N, xptr, 1, 0 ); + * // returns 2.0 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `dnanmean`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @returns arithmetic mean + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); + * + * var y = dnanmean.main( 4, x, 1 ); + * // returns ~0.3333 + */ + main( N: number, x: Float64Array, strideX: number ): number; + + /** + * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns arithmetic mean + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); + * + * var out = dnanmean.ndarray( 5, x, 2, 1 ); + * // returns 1.25 + */ + ndarray( N: number, x: Float64Array, 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' ); + * + * // 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 new routine: + * var mod = new dnanmean.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 3; + * + * // Define a pointer (i.e., byte offset) to the first vector element: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var y = mod.main( N, xptr, 1 ); + * // returns 2.0 + */ + Module: ModuleConstructor; +} + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length +* @returns arithmetic mean +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* var y = dnanmean.main( 4, x, 1 ); +* // returns ~0.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); +* +* var y = dnanmean.ndarray( 5, x, 2, 1 ); +* // returns 1.25 +*/ +declare var dnanmean: Routine; + + +// EXPORTS // + +export = dnanmean; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/test.ts new file mode 100644 index 000000000000..e7956a743dff --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/docs/types/test.ts @@ -0,0 +1,347 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Memory = require( '@stdlib/wasm/memory' ); +import dnanmean = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnanmean.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 Float64Array( 10 ); + + dnanmean.main( '10', x, 1 ); // $ExpectError + dnanmean.main( true, x, 1 ); // $ExpectError + dnanmean.main( false, x, 1 ); // $ExpectError + dnanmean.main( null, x, 1 ); // $ExpectError + dnanmean.main( undefined, x, 1 ); // $ExpectError + dnanmean.main( [], x, 1 ); // $ExpectError + dnanmean.main( {}, x, 1 ); // $ExpectError + dnanmean.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 Float64Array... +{ + const x = new Float64Array( 10 ); + + dnanmean.main( x.length, 10, 1 ); // $ExpectError + dnanmean.main( x.length, '10', 1 ); // $ExpectError + dnanmean.main( x.length, true, 1 ); // $ExpectError + dnanmean.main( x.length, false, 1 ); // $ExpectError + dnanmean.main( x.length, null, 1 ); // $ExpectError + dnanmean.main( x.length, undefined, 1 ); // $ExpectError + dnanmean.main( x.length, [], 1 ); // $ExpectError + dnanmean.main( x.length, {}, 1 ); // $ExpectError + dnanmean.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 Float64Array( 10 ); + + dnanmean.main( x.length, x, '10' ); // $ExpectError + dnanmean.main( x.length, x, true ); // $ExpectError + dnanmean.main( x.length, x, false ); // $ExpectError + dnanmean.main( x.length, x, null ); // $ExpectError + dnanmean.main( x.length, x, undefined ); // $ExpectError + dnanmean.main( x.length, x, [] ); // $ExpectError + dnanmean.main( x.length, x, {} ); // $ExpectError + dnanmean.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 Float64Array( 10 ); + + dnanmean.main(); // $ExpectError + dnanmean.main( x.length ); // $ExpectError + dnanmean.main( x.length, x ); // $ExpectError + dnanmean.main( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnanmean.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 Float64Array( 10 ); + + dnanmean.ndarray( '10', x, 1, 0 ); // $ExpectError + dnanmean.ndarray( true, x, 1, 0 ); // $ExpectError + dnanmean.ndarray( false, x, 1, 0 ); // $ExpectError + dnanmean.ndarray( null, x, 1, 0 ); // $ExpectError + dnanmean.ndarray( undefined, x, 1, 0 ); // $ExpectError + dnanmean.ndarray( [], x, 1, 0 ); // $ExpectError + dnanmean.ndarray( {}, x, 1, 0 ); // $ExpectError + dnanmean.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 Float64Array... +{ + const x = new Float64Array( 10 ); + + dnanmean.ndarray( x.length, 10, 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, '10', 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, true, 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, false, 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, null, 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, [], 1, 0 ); // $ExpectError + dnanmean.ndarray( x.length, {}, 1, 0 ); // $ExpectError + dnanmean.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 Float64Array( 10 ); + + dnanmean.ndarray( x.length, x, '10', 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, true, 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, false, 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, null, 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, undefined, 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, [], 0 ); // $ExpectError + dnanmean.ndarray( x.length, x, {}, 0 ); // $ExpectError + dnanmean.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 Float64Array( 10 ); + + dnanmean.ndarray( x.length, x, 1, '10' ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, true ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, false ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, null ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, undefined ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, [] ); // $ExpectError + dnanmean.ndarray( x.length, x, 1, {} ); // $ExpectError + dnanmean.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 Float64Array( 10 ); + + dnanmean.ndarray(); // $ExpectError + dnanmean.ndarray( x.length ); // $ExpectError + dnanmean.ndarray( x.length, x ); // $ExpectError + dnanmean.ndarray( x.length, x, 1 ); // $ExpectError + dnanmean.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 + }); + + dnanmean.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + dnanmean.Module( '10' ); // $ExpectError + dnanmean.Module( true ); // $ExpectError + dnanmean.Module( false ); // $ExpectError + dnanmean.Module( null ); // $ExpectError + dnanmean.Module( undefined ); // $ExpectError + dnanmean.Module( [] ); // $ExpectError + dnanmean.Module( {} ); // $ExpectError + dnanmean.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 = dnanmean.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 = dnanmean.Module( mem ); + + mod.main( '10', 0, 1 ); // $ExpectError + mod.main( true, 0, 1 ); // $ExpectError + mod.main( false, 0, 1 ); // $ExpectError + mod.main( null, 0, 1 ); // $ExpectError + mod.main( undefined, 0, 1 ); // $ExpectError + mod.main( [], 0, 1 ); // $ExpectError + mod.main( {}, 0, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 0, 1 ); // $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 = dnanmean.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 = dnanmean.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 = dnanmean.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1, 5 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnanmean.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 = dnanmean.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 = dnanmean.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 = dnanmean.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 = dnanmean.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 = dnanmean.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/stats/strided/wasm/dnanmean/examples/index.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/index.js new file mode 100644 index 000000000000..fdd1a2e05e4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Float64Array = require( '@stdlib/array/float64' ); +var dnanmean = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create an input array containing NaN values: + var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0, NaN, 3.0 ] ); + + // Perform computation, ignoring NaN values: + var v = dnanmean.ndarray( x.length, x, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/little_endian_arrays.js new file mode 100644 index 000000000000..486e1f9e8368 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var dnanmean = 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 new routine: + var mod = new dnanmean.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line n/no-sync + + // Specify a vector length: + var N = 3; + + // 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 Float64ArrayLE( mod.memory.buffer, xptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + var v = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/module.js new file mode 100644 index 000000000000..a674b716661f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/examples/module.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 dnanmean = 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 new routine: + var mod = new dnanmean.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line n/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 3; + + // Define a pointer (i.e., byte offset) for storing the input vector: + var xptr = 0; + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + + // Perform computation: + var v = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.browser.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.browser.js new file mode 100644 index 000000000000..6a44e0c724b5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AEf39/fwF8YAAAYAN/f38BfAIPAQNlbnYGbWVtb3J5AgAAAwUEAQIAAAdRAxFfX3dhc21fY2FsbF9jdG9ycwAAF3N0ZGxpYl9zdHJpZGVkX2RuYW5tZWFuAAEfc3RkbGliX3N0cmlkZWRfZG5hbm1lYW5fbmRhcnJheQADCooCBAMAAQsaACAAIAEgAkEBIABrIAJsQQAgAkEATBsQAgvbAQIEfAR/RAAAAAAAAPh/IQUCQAJAIABBAEwNACACRSAAQQFGcg0BIAMhCgNAIAAgCEZFBEAgBCABIApBA3RqKwMAIgagIAQgBiAGYSILGyEEIAhBAWohCCACIApqIQogCSALaiEJDAELCyAJRQ0AIAQgCbgiB6MhBUQAAAAAAAAAACEEQQAhCANAIAAgCEZFBEAgBCABIANBA3RqKwMAIgYgBaGgIAQgBiAGYRshBCAIQQFqIQggAiADaiEDDAELCyAFIAQgB6OgIQULIAUPCyABIANBA3RqKwMACwwAIAAgASACIAMQAgs=' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.js new file mode 100644 index 000000000000..b2cc0a347ff9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/stats/strided/wasm/dnanmean/lib/index.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/index.js new file mode 100644 index 000000000000..cc907c6ba997 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/index.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 compute the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. +* +* @module @stdlib/stats/strided/wasm/dnanmean +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnanmean = require( '@stdlib/stats/strided/wasm/dnanmean' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +* +* // Perform operation: +* var v = dnanmean.main( x.length, x, 1 ); +* // returns ~0.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnanmean = require( '@stdlib/stats/strided/wasm/dnanmean' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* // Perform operation: +* var v = dnanmean.ndarray( 4, x, 2, 1 ); +* // returns 1.25 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var dnanmean = require( '@stdlib/stats/strided/wasm/dnanmean' ); +* +* // 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 new routine: +* var mod = new dnanmean.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 3; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var v = mod.main( 3, xptr, 1 ); +* // returns 2.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/main.js new file mode 100644 index 000000000000..ced47a54c268 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/main.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var Routine = require( './routine.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* WebAssembly routine to compute the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. +* +* @name dnanmean +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +* +* // Perform operation: +* var v = dnanmean.main( 3, x, 1 ); +* // returns ~0.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* // Perform operation: +* var v = dnanmean.ndarray( 4, x, 2, 1 ); +* // returns 1.25 +*/ +var dnanmean = new Routine(); +setReadOnly( dnanmean, 'Module', Module.bind( null ) ); +dnanmean.initializeSync(); // eslint-disable-line n/no-sync + + +// EXPORTS // + +module.exports = dnanmean; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/module.js new file mode 100644 index 000000000000..17d610b71d17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/module.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 // + +/** +* 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' ); +* +* // 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 new routine: +* var dnanmean = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanmean.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 3; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnanmean.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var v = dnanmean.main( N, xptr, 1 ); +* // returns 2.0 +*/ +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 ); + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @returns {number} arithmetic mean +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // 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 new routine: +* var dnanmean = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanmean.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 3; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnanmean.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var v = dnanmean.main( N, xptr, 1 ); +* // returns 2.0 +*/ +setReadOnly( Module.prototype, 'main', function dnanmean( N, xptr, strideX ) { + return this._instance.exports.stdlib_strided_dnanmean( N, xptr, strideX ); +}); + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} arithmetic mean +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // 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 new routine: +* var dnanmean = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanmean.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 3; +* +* // Define a pointer (i.e., byte offset) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnanmean.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = dnanmean.ndarray( N, xptr, 1, 0 ); +* // returns 2.0 +*/ +setReadOnly( Module.prototype, 'ndarray', function dnanmean( N, xptr, strideX, offsetX ) { + return this._instance.exports.stdlib_strided_dnanmean_ndarray( N, xptr, strideX, offsetX ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/routine.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/routine.js new file mode 100644 index 000000000000..fcc4b7886827 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/lib/routine.js @@ -0,0 +1,166 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 max-len, 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 Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanmean = new Routine(); +* +* // Initialize the module: +* dnanmean.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +* +* // Perform operation: +* var v = dnanmean.main( 3, x, 1 ); +* // returns ~0.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanmean = new Routine(); +* +* // Initialize the module: +* dnanmean.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* // Perform operation: +* var sum = dnanmean.ndarray( 4, x, 2, 1 ); +* // returns 1.25 +*/ +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 ); + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @returns {number} arithmetic mean +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanmean = new Routine(); +* +* // Initialize the module: +* dnanmean.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); +* +* // Perform operation: +* var v = dnanmean.main( 3, x, 1 ); +* // returns ~0.3333 +*/ +setReadOnly( Routine.prototype, 'main', function dnanmean( N, x, strideX ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values, using Welford's algorithm and alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} arithmetic mean +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanmean = new Routine(); +* +* // Initialize the module: +* dnanmean.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* // Perform operation: +* var v = dnanmean.ndarray( 4, x, 2, 1 ); +* // returns 1.25 +*/ +setReadOnly( Routine.prototype, 'ndarray', function dnanmean( N, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input arrays 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 ); +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/manifest.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/manifest.json new file mode 100644 index 000000000000..e5b53c8d2f5d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/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/stats/strided/dnanmean" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/package.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/package.json new file mode 100644 index 000000000000..7c0d7f158c7c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/package.json @@ -0,0 +1,82 @@ +{ + "name": "@stdlib/stats/strided/wasm/dnanmean", + "version": "0.0.0", + "description": "Calculate the arithmetic mean of a double-precision floating-point strided array, ignoring NaN values.", + "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", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "mean", + "nan", + "arithmetic mean", + "central tendency", + "strided", + "strided array", + "typed", + "array", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/build.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/build.js new file mode 100644 index 000000000000..0e05b3ad6a39 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/build.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/stats/strided/wasm/dnanmean/scripts/postbuild.wat.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/postbuild.wat.js new file mode 100644 index 000000000000..0d8edabe98d0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/postbuild.wat.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 licenseHeader = require( '@stdlib/_tools/licenses/header' ); +var insertHeader = require( '@stdlib/_tools/licenses/insert-header-file-list' ).sync; +var currentYear = require( '@stdlib/time/current-year' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wat' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +* @throws {Error} unexpected error +*/ +function main() { + var headers; + var files; + var err; + + files = [ + wpath + ]; + headers = { + 'wat': licenseHeader( 'Apache-2.0', 'wat', { + 'year': currentYear(), + 'copyright': 'The Stdlib Authors' + }) + }; + err = insertHeader( files, headers ); + if ( err ) { + throw err; + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/template.txt b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/scripts/template.txt new file mode 100644 index 000000000000..f66cdb9735b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/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/stats/strided/wasm/dnanmean/src/Makefile b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/Makefile new file mode 100644 index 000000000000..fcc028115b77 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/Makefile @@ -0,0 +1,244 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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) + $(QUIET) $(NODEJS) ./../scripts/postbuild.wat.js + +#/ +# 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/stats/strided/wasm/dnanmean/src/exports.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/exports.json new file mode 100644 index 000000000000..70aa0704622d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/exports.json @@ -0,0 +1,4 @@ +[ + "_stdlib_strided_dnanmean", + "_stdlib_strided_dnanmean_ndarray" +] diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/main.wasm b/lib/node_modules/@stdlib/stats/strided/wasm/dnanmean/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..c98e811244d9292040d309bef44f6554d8c9bbf8 GIT binary patch literal 422 zcmZ{f!AiqG5Qb-VHffS=sp3Jf2WNW~#7Ahr^yI}S*v2M@rb!A(Pzr_KeTqt7!gujS zJUW(EQ1HLZKRYwu&Oq8$2%=$-t;D0tQA_F)}P!l`)8ihtZibAE@+3Z|`MW(dX8BYN93#QXWWGA`Yj`0GVt=^3K6D z(G%8;9L3ZXHw0sUC%MmlIyNJ#If${a0V|FQ8*#{{uwfsK;V==T=J0*o+gtDWC4kj2 o*x(PGe&FoAo%p}#R9HG-Jz@6tJL?(thDH`U&6@u4ZYH_(3(;Op!T