From 3eb896b9773634e18cbb9d286107da20787d2a6b Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 17 Sep 2025 00:11:40 -0500 Subject: [PATCH 01/17] docs: update list of contributors PR-URL: https://github.com/stdlib-js/stdlib/pull/8089 Reviewed-by: Athan Reines --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index dc8efae1b8ef..514acabbd22c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -29,6 +29,7 @@ Anmol Sah <113588714+anmolsah@users.noreply.github.com> Annamalai Prabu Anshu Kumar <132515490+anxhukumar@users.noreply.github.com> Anshu Kumar +Anshumancanrock <109489361+Anshumancanrock@users.noreply.github.com> Anudeep Sanapala Arihant Pal Aryan Bhirud <112156883+AryanBhirud@users.noreply.github.com> From 510bbde67c11f367968bf73a63c8dfea99db6dde Mon Sep 17 00:00:00 2001 From: Payal Goswami Date: Wed, 17 Sep 2025 10:48:43 +0530 Subject: [PATCH 02/17] chore: fix JavaScript lint errors PR-URL: https://github.com/stdlib-js/stdlib/pull/8086 Closes: https://github.com/stdlib-js/stdlib/issues/8082 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/assert/is-odd/benchmark/benchmark.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-odd/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-odd/benchmark/benchmark.js index 7e002c8e1928..4a54a094ecc7 100644 --- a/lib/node_modules/@stdlib/assert/is-odd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/is-odd/benchmark/benchmark.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-new-wrappers, no-undefined, no-empty-function */ +/* eslint-disable no-empty-function */ 'use strict'; @@ -47,7 +47,7 @@ bench( pkg+'::primitives', function benchmark( b ) { true, false, null, - undefined + void 0 ]; b.tic(); @@ -110,7 +110,7 @@ bench( pkg+'::primitives:isPrimitive', function benchmark( b ) { true, false, null, - undefined + void 0 ]; b.tic(); @@ -173,7 +173,7 @@ bench( pkg+'::primitives:isObject', function benchmark( b ) { true, false, null, - undefined + void 0 ]; b.tic(); From b5ace26f95531ed7322c25bcf190e77d595dc055 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 17 Sep 2025 11:30:55 +0530 Subject: [PATCH 03/17] feat: add `stats/strided/wasm/dnanvariancewd` PR-URL: https://github.com/stdlib-js/stdlib/pull/8085 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Co-authored-by: stdlib-bot --- .../strided/dnanvariancewd/manifest.json | 2 +- .../strided/wasm/dnanvariancewd/README.md | 306 ++++++++++ .../dnanvariancewd/benchmark/benchmark.js | 121 ++++ .../benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 145 +++++ .../benchmark/benchmark.module.ndarray.js | 145 +++++ .../benchmark/benchmark.ndarray.js | 121 ++++ .../strided/wasm/dnanvariancewd/docs/repl.txt | 552 ++++++++++++++++++ .../wasm/dnanvariancewd/docs/types/index.d.ts | 321 ++++++++++ .../wasm/dnanvariancewd/docs/types/test.ts | 415 +++++++++++++ .../wasm/dnanvariancewd/examples/index.js | 43 ++ .../examples/little_endian_arrays.js | 65 +++ .../wasm/dnanvariancewd/examples/module.js | 63 ++ .../wasm/dnanvariancewd/lib/binary.browser.js | 33 ++ .../strided/wasm/dnanvariancewd/lib/binary.js | 34 ++ .../strided/wasm/dnanvariancewd/lib/index.js | 100 ++++ .../strided/wasm/dnanvariancewd/lib/main.js | 60 ++ .../strided/wasm/dnanvariancewd/lib/module.js | 200 +++++++ .../wasm/dnanvariancewd/lib/routine.js | 168 ++++++ .../strided/wasm/dnanvariancewd/manifest.json | 36 ++ .../strided/wasm/dnanvariancewd/package.json | 86 +++ .../wasm/dnanvariancewd/scripts/build.js | 66 +++ .../wasm/dnanvariancewd/scripts/template.txt | 33 ++ .../strided/wasm/dnanvariancewd/src/Makefile | 243 ++++++++ .../wasm/dnanvariancewd/src/exports.json | 4 + .../strided/wasm/dnanvariancewd/src/main.wasm | Bin 0 -> 406 bytes .../strided/wasm/dnanvariancewd/src/main.wat | 141 +++++ .../strided/wasm/dnanvariancewd/test/test.js | 53 ++ .../wasm/dnanvariancewd/test/test.main.js | 315 ++++++++++ .../wasm/dnanvariancewd/test/test.module.js | 154 +++++ .../dnanvariancewd/test/test.module.main.js | 353 +++++++++++ .../test/test.module.ndarray.js | 307 ++++++++++ .../wasm/dnanvariancewd/test/test.ndarray.js | 311 ++++++++++ .../wasm/dnanvariancewd/test/test.routine.js | 71 +++ 34 files changed, 5132 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/routine.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/build.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/exports.json create mode 100755 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wasm create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wat create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.routine.js diff --git a/lib/node_modules/@stdlib/stats/strided/dnanvariancewd/manifest.json b/lib/node_modules/@stdlib/stats/strided/dnanvariancewd/manifest.json index 86308d31795d..4e48e5cccb38 100644 --- a/lib/node_modules/@stdlib/stats/strided/dnanvariancewd/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/dnanvariancewd/manifest.json @@ -81,7 +81,7 @@ ] }, { - "task": "", + "task": "build", "wasm": true, "src": [ "./src/main.c" diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/README.md b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/README.md new file mode 100644 index 000000000000..24878b11f57e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/README.md @@ -0,0 +1,306 @@ + + +# dnanvariancewd + +> Compute the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. + +
+ +## Usage + +```javascript +var dnanvariancewd = require( '@stdlib/stats/strided/wasm/dnanvariancewd' ); +``` + +#### dnanvariancewd.main( N, correction, x, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); + +var v = dnanvariancewd.main( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **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( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ] ); + +var v = dnanvariancewd.main( 5, 1, x, 2 ); +// returns 6.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 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = dnanvariancewd.main( 5, 1, x1, 2 ); +// returns 6.25 +``` + +#### dnanvariancewd.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and 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 v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.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 ] ); + +var v = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +// returns 6.25 +``` + +* * * + +### Module + +#### dnanvariancewd.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 dnanvariancewd.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### dnanvariancewd.Module.prototype.main( N, correction, xp, sx ) + +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); + +// 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 dnanvariancewd.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( N, 1, xptr, 1 ); +// returns 1.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: stride length for `x`. + +#### dnanvariancewd.Module.prototype.ndarray( N, correction, xp, sx, ox ) + +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); + +// 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 dnanvariancewd.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.ndarray( N, 1, xptr, 1, 0 ); +// returns 1.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 `n - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements), both `main` and `ndarray` methods return `NaN`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dnanvariancewd` 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/dnanvariancewd`][@stdlib/stats/strided/dnanvariancewd]. 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/dnanvariancewd`][@stdlib/stats/strided/dnanvariancewd]. 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var dnanvariancewd = require( '@stdlib/stats/strided/wasm/dnanvariancewd' ); + +function rand() { + if ( bernoulli( 0.2 ) > 0 ) { + return NaN; + } + return discreteUniform( 0, 10 ); +} + +var x = filledarrayBy( 10, 'float64', rand ); +console.log( x ); + +var v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.js new file mode 100644 index 000000000000..ecaef3c88a37 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnanvariancewd = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, options.dtype, rand ); + 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 = dnanvariancewd.main( x.length, 1, 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( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.js new file mode 100644 index 000000000000..1482aff0c351 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var dnanvariancewd = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new dnanvariancewd.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/dnanvariancewd/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.main.js new file mode 100644 index 000000000000..e01493449dde --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.main.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnanvariancewd = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* 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 dnanvariancewd.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/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, filledarrayBy( len, options.dtype, rand ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mod.main( len, 1, 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( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.ndarray.js new file mode 100644 index 000000000000..a69d84645f30 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var 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/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnanvariancewd = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* 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 dnanvariancewd.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/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, filledarrayBy( len, options.dtype, rand ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = mod.ndarray( len, 1, 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( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6f38aa779185 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/benchmark/benchmark.ndarray.js @@ -0,0 +1,121 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnanvariancewd = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filledarrayBy( len, options.dtype, rand ); + 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 = dnanvariancewd.ndarray( x.length, 1, 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( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/repl.txt new file mode 100644 index 000000000000..e4f039a49b64 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/repl.txt @@ -0,0 +1,552 @@ + +{{alias}}.main( N, correction, x, strideX ) + Computes the variance of a double-precision floating-point strided array + ignoring `NaN` values and using Welford's algorithm. + + 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 `0.0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `n - c` where `c` corresponds to the + provided degrees of freedom adjustment and `n` corresponds to the number + of non-`NaN` indexed elements. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); + > {{alias}}.main( x.length, 1, x, 1 ) + ~4.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, 1, x, 2 ) + ~4.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, 1, x1, 2) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a double-precision floating-point strided array + ignoring `NaN` values and using Welford's algorithm 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. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `n - c` where `c` corresponds to the + provided degrees of freedom adjustment and `n` corresponds to the number + of non-`NaN` indexed elements. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float64Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.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, 1, x, 2, 1 ) + ~4.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 Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, correction, xp, sx ) + Computes the variance of a double-precision floating-point strided array + ignoring `NaN` values and using Welford's algorithm. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `n - c` where `c` corresponds to the + provided degrees of freedom adjustment and `n` corresponds to the number + of non-`NaN` indexed elements. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Stride length. + + Returns + ------- + out: number + The variance. + + 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, 1, xptr, 1 ) + 1.0 + + +{{alias}}.Module.prototype.ndarray( N, correction, xp, sx, ox ) + Computes the variance of a double-precision floating-point strided array + ignoring `NaN` values and using Welford's algorithm and alternative + indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `n - c` where `c` corresponds to the + provided degrees of freedom adjustment and `n` corresponds to the number + of non-`NaN` indexed elements. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Stride length. + + ox: integer + Starting index. + + Returns + ------- + out: number + The variance. + + 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, 1, xptr, 1, 0 ) + 1.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/index.d.ts new file mode 100644 index 000000000000..3a78475cece5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/index.d.ts @@ -0,0 +1,321 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// 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 dnanvariancewd.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, 1, xptr, 1 ); + * // returns 1.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 = dnanvariancewd.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, 1, xptr, 1 ); + * // returns 1.0 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `dnanvariancewd` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - stride length + * @returns variance + * + * @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 dnanvariancewd.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, 1, xptr, 1 ); + * // returns 1.0 + */ + main( N: number, correction: number, xptr: number, strideX: number ): number; + + /** + * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @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 dnanvariancewd.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, 1, xptr, 1, 0 ); + * // returns 1.0 + */ + ndarray( N: number, correction: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `dnanvariancewd`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); + * + * var y = dnanvariancewd.main( 4, 1, x, 1 ); + * // returns ~4.3333 + */ + main( N: number, x: Float64Array, strideX: number ): number; + + /** + * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @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 = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); + * // returns ~4.7857 + */ + ndarray( N: number, correction: 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 dnanvariancewd.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, 1, xptr, 1 ); + * // returns 1.0 + */ + Module: ModuleConstructor; +} + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* var y = dnanvariancewd.main( 4, 1, x, 1 ); +* // returns ~4.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 = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +* // returns 6.25 +*/ +declare var dnanvariancewd: Routine; + + +// EXPORTS // + +export = dnanvariancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/test.ts new file mode 100644 index 000000000000..eeecce7a82fd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/docs/types/test.ts @@ -0,0 +1,415 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import dnanvariancewd = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.main( x.length, 1, 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 ); + + dnanvariancewd.main( '10', 1, x, 1 ); // $ExpectError + dnanvariancewd.main( true, 1, x, 1 ); // $ExpectError + dnanvariancewd.main( false, 1, x, 1 ); // $ExpectError + dnanvariancewd.main( null, 1, x, 1 ); // $ExpectError + dnanvariancewd.main( undefined, 1, x, 1 ); // $ExpectError + dnanvariancewd.main( [], 1, x, 1 ); // $ExpectError + dnanvariancewd.main( {}, 1, x, 1 ); // $ExpectError + dnanvariancewd.main( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.main( x.length, 10, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, '10', x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, true, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, false, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, null, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, undefined, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, [], x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, {}, x, 1 ); // $ExpectError + dnanvariancewd.main( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.main( x.length, 1, 10, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, '10', 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, true, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, false, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, null, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, undefined, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, [], 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, {}, 1 ); // $ExpectError + dnanvariancewd.main( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.main( x.length, 1, x, '10' ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, true ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, false ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, null ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, undefined ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, [] ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, {} ); // $ExpectError + dnanvariancewd.main( x.length, 1, 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 ); + + dnanvariancewd.main(); // $ExpectError + dnanvariancewd.main( x.length ); // $ExpectError + dnanvariancewd.main( x.length, x ); // $ExpectError + dnanvariancewd.main( x.length, 1, x ); // $ExpectError + dnanvariancewd.main( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.ndarray( x.length, 1, 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 ); + + dnanvariancewd.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( true, 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( false, 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( null, 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( [], 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.ndarray( x.length, 10, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnanvariancewd.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, true ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, false ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, null ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, 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 ); + + dnanvariancewd.ndarray(); // $ExpectError + dnanvariancewd.ndarray( x.length ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1 ); // $ExpectError + dnanvariancewd.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + dnanvariancewd.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + dnanvariancewd.Module( '10' ); // $ExpectError + dnanvariancewd.Module( true ); // $ExpectError + dnanvariancewd.Module( false ); // $ExpectError + dnanvariancewd.Module( null ); // $ExpectError + dnanvariancewd.Module( undefined ); // $ExpectError + dnanvariancewd.Module( [] ); // $ExpectError + dnanvariancewd.Module( {} ); // $ExpectError + dnanvariancewd.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 = dnanvariancewd.Module( mem ); + + mod.main( 10, 1, 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 = dnanvariancewd.Module( mem ); + + mod.main( '10', 1, 0, 1 ); // $ExpectError + mod.main( true, 1, 0, 1 ); // $ExpectError + mod.main( false, 1, 0, 1 ); // $ExpectError + mod.main( null, 1, 0, 1 ); // $ExpectError + mod.main( undefined, 1, 0, 1 ); // $ExpectError + mod.main( [], 1, 0, 1 ); // $ExpectError + mod.main( {}, 1, 0, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 1, 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 = dnanvariancewd.Module( mem ); + + mod.main( 10, '10', 0, 1 ); // $ExpectError + mod.main( 10, true, 0, 1 ); // $ExpectError + mod.main( 10, false, 0, 1 ); // $ExpectError + mod.main( 10, null, 0, 1 ); // $ExpectError + mod.main( 10, undefined, 0, 1 ); // $ExpectError + mod.main( 10, [], 0, 1 ); // $ExpectError + mod.main( 10, {}, 0, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 0, 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 = dnanvariancewd.Module( mem ); + + mod.main( 10, 1, '10', 1 ); // $ExpectError + mod.main( 10, 1, true, 1 ); // $ExpectError + mod.main( 10, 1, false, 1 ); // $ExpectError + mod.main( 10, 1, null, 1 ); // $ExpectError + mod.main( 10, 1, undefined, 1 ); // $ExpectError + mod.main( 10, 1, [], 1 ); // $ExpectError + mod.main( 10, 1, {}, 1 ); // $ExpectError + mod.main( 10, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnanvariancewd.Module( mem ); + + mod.main( 10, 1, 0, '10' ); // $ExpectError + mod.main( 10, 1, 0, true ); // $ExpectError + mod.main( 10, 1, 0, false ); // $ExpectError + mod.main( 10, 1, 0, null ); // $ExpectError + mod.main( 10, 1, 0, undefined ); // $ExpectError + mod.main( 10, 1, 0, [] ); // $ExpectError + mod.main( 10, 1, 0, {} ); // $ExpectError + mod.main( 10, 1, 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 = dnanvariancewd.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 1 ); // $ExpectError + mod.main( 10, 1, 0 ); // $ExpectError + mod.main( 10, 1, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray( 10, 1, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray( '10', 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 1, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 1, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray( 1, '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, true, 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, false, 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, null, 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, [], 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( 1, ( x: number ): number => x, 0, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray( 10, 1, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, ( x: number ): number => x, 1, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray( 10, 1, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnanvariancewd.Module( mem ); + + mod.ndarray( 10, 1, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 1, 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 = dnanvariancewd.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 1 ); // $ExpectError + mod.ndarray( 10, 1, 0 ); // $ExpectError + mod.ndarray( 10, 1, 0, 1 ); // $ExpectError + mod.ndarray( 10, 1, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/index.js new file mode 100644 index 000000000000..5823b3feb7fe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dnanvariancewd = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 3; + + // Create an input array: + var x = oneTo( N, 'float64' ); + + // Perform computation: + var v = dnanvariancewd.ndarray( N, 1, x, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/little_endian_arrays.js new file mode 100644 index 000000000000..d6f1d14189b2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +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 dnanvariancewd = 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 dnanvariancewd.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/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, 1, xptr, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/module.js new file mode 100644 index 000000000000..a3e0dace9b67 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/examples/module.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dnanvariancewd = 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 dnanvariancewd.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/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, 1, xptr, 1, 0 ); + + // Print the result: + console.log( v ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.browser.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.browser.js new file mode 100644 index 000000000000..5249fd38aa72 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAEVA2AAAGAEf3x/fwF8YAV/fH9/fwF8Ag8BA2VudgZtZW1vcnkCAAADBAMAAQIHXQMRX193YXNtX2NhbGxfY3RvcnMAAB1zdGRsaWJfc3RyaWRlZF9kbmFudmFyaWFuY2V3ZAABJXN0ZGxpYl9zdHJpZGVkX2RuYW52YXJpYW5jZXdkX25kYXJyYXkAAgrtAQMDAAELHAAgACABIAIgA0EBIABrIANsQQAgA0EATBsQAgvJAQIFfAJ/RAAAAAAAAPh/IQgCQAJAIABBAEwNACADRSAAQQFGcg0BA0AgACALRkUEQCACIARBA3RqKwMAIgcgB2EEQCAHIAahIgkgByAGIAkgCkEBaiIKt6OgIgahoiAFoCEFCyALQQFqIQsgAyAEaiEEDAELCyAKtyABoSIBRAAAAAAAAAAAZQ0AIAUgAaMhCAsgCA8LRAAAAAAAAAAARAAAAAAAAPh/IAEgALhjG0QAAAAAAAD4fyACIARBA3RqKwMAIgEgAWEbCw==' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.js new file mode 100644 index 000000000000..2b83fe651780 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var 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/dnanvariancewd/lib/index.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/index.js new file mode 100644 index 000000000000..f6104ffa2cd4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/index.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* WebAssembly routine to compute the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @module @stdlib/stats/strided/wasm/dnanvariancewd +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnanvariancewd = require( '@stdlib/stats/strided/wasm/dnanvariancewd' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* // Perform operation: +* var v = dnanvariancewd.main( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnanvariancewd = require( '@stdlib/stats/strided/wasm/dnanvariancewd' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); +* +* // Perform operation: +* var v = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +* // returns 6.25 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var dnanvariancewd = require( '@stdlib/stats/strided/wasm/dnanvariancewd' ); +* +* // 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 dnanvariancewd.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, 1, xptr, 1 ); +* // returns 1.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/main.js new file mode 100644 index 000000000000..73c17d40f10b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly routine to compute the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @name dnanvariancewd +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* // Perform operation: +* var v = dnanvariancewd.main( 4, 1, x, 1 ); +* // returns ~4.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, NaN, NaN ] ); +* +* // Perform operation: +* var v = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +* // returns 6.25 +*/ +var dnanvariancewd = new Routine(); +dnanvariancewd.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = dnanvariancewd; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/module.js new file mode 100644 index 000000000000..fdcca37f40cb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/module.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* 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 dnanvariancewd = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanvariancewd.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: +* dnanvariancewd.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var v = dnanvariancewd.main( N, 1, xptr, 1 ); +* // returns 1.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 variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @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 dnanvariancewd = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanvariancewd.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: +* dnanvariancewd.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var v = dnanvariancewd.main( N, 1, xptr, 1 ); +* // returns 1.0 +*/ +setReadOnly( Module.prototype, 'main', function dnanvariancewd( N, correction, xptr, strideX ) { + return this._instance.exports.stdlib_strided_dnanvariancewd( N, correction, xptr, strideX ); // eslint-disable-line max-len +}); + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @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 dnanvariancewd = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnanvariancewd.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: +* dnanvariancewd.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = dnanvariancewd.ndarray( N, 1, xptr, 1, 0 ); +* // returns 1.0 +*/ +setReadOnly( Module.prototype, 'ndarray', function dnanvariancewd( N, correction, xptr, strideX, offsetX ) { + return this._instance.exports.stdlib_strided_dnanvariancewd_ndarray( N, correction, xptr, strideX, offsetX ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/routine.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/routine.js new file mode 100644 index 000000000000..e44bbb44a3e6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/lib/routine.js @@ -0,0 +1,168 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* 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 dnanvariancewd = new Routine(); +* +* // Initialize the module: +* dnanvariancewd.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* // Perform operation: +* var v = dnanvariancewd.main( 4, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanvariancewd = new Routine(); +* +* // Initialize the module: +* dnanvariancewd.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, NaN, NaN ] ); +* +* // Perform operation: +* var sum = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +* // returns 6.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 variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanvariancewd = new Routine(); +* +* // Initialize the module: +* dnanvariancewd.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* // Perform operation: +* var v = dnanvariancewd.main( 4, 1, x, 1 ); +* // returns ~4.3333 +*/ +setReadOnly( Routine.prototype, 'main', function dnanvariancewd( N, correction, x, strideX ) { + return this.ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Float64Array} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} variance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnanvariancewd = new Routine(); +* +* // Initialize the module: +* dnanvariancewd.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, NaN, NaN ] ); +* +* // Perform operation: +* var v = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); +* // returns 6.25 +*/ +setReadOnly( Routine.prototype, 'ndarray', function dnanvariancewd( N, correction, 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, correction, p0.ptr, p0.stride, p0.offset ); +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/manifest.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/manifest.json new file mode 100644 index 000000000000..7011de46b7ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/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/dnanvariancewd" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/package.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/package.json new file mode 100644 index 000000000000..42b1c6ea0356 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/package.json @@ -0,0 +1,86 @@ +{ + "name": "@stdlib/stats/strided/wasm/dnanvariancewd", + "version": "0.0.0", + "description": "Calculate the variance of a double-precision floating-point strided array ignoring NaN values and using Welford's algorithm.", + "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", + "variance", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "welford", + "strided", + "strided array", + "typed", + "array", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/build.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/build.js new file mode 100644 index 000000000000..66bf9650b6d6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/build.js @@ -0,0 +1,66 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); +var currentYear = require( '@stdlib/time/current-year' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; +var YEAR = '{{YEAR}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, YEAR, currentYear().toString() ); + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/template.txt b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/scripts/template.txt new file mode 100644 index 000000000000..f66cdb9735b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/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/dnanvariancewd/src/Makefile b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/Makefile new file mode 100644 index 000000000000..1b1f35347760 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/Makefile @@ -0,0 +1,243 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the integer size: +ifdef CBLAS_INT + INT_TYPE := $(CBLAS_INT) +else + INT_TYPE := int32_t +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -flto \ + -Wall \ + -pedantic \ + -D CBLAS_INT=$(INT_TYPE) + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -Oz \ + -fwasm-exceptions \ + -s SUPPORT_LONGJMP=1 \ + -s SIDE_MODULE=2 \ + -s EXPORTED_FUNCTIONS="$(shell cat exports.json | tr -d ' \t\n' | sed s/\"/\'/g)" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 \ + -s WASM_BIGINT=0 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js $(browser_js_targets) + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/exports.json b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/exports.json new file mode 100644 index 000000000000..0f3f76c21cd7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/exports.json @@ -0,0 +1,4 @@ +[ + "_stdlib_strided_dnanvariancewd", + "_stdlib_strided_dnanvariancewd_ndarray" +] diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wasm b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..4721f860dc5cd3cd90623e1958cc2f47e05556a3 GIT binary patch literal 406 zcmaJ*!AiqG5S`iGG-=jSJ$S0ZB;ZL9KcNBJlfNL_HJd})B!x|ADHQT6js1xF3;h`H z9^HymPtN7Nd2e`cK-VRLn_*x!MP4l)9#Ncjyyi22nP|6di`$uZLPyvTc~-4@WmYcj zh5>NF0h#~8uasK5FqP_}P-(NYHNb7%m?D2wbz^gr8D%P6t+dT`m1b)Lc=xZbDx& kVHe|1FF@wnJi>hxND7AXte+nvBzR9pzx$szkWi207cbaU-v9sr literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wat b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wat new file mode 100644 index 000000000000..8bed58a90b89 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/src/main.wat @@ -0,0 +1,141 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2025 The Stdlib Authors. +;; +;; Licensed under the Apache License, Version 2.0 (the "License"); +;; you may not use this file except in compliance with the License. +;; You may obtain a copy of the License at +;; +;; http://www.apache.org/licenses/LICENSE-2.0 +;; +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 f64 i32 i32) (result f64))) + (type (;2;) (func (param i32 f64 i32 i32 i32) (result f64))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 f64 i32 i32) (result f64) + local.get 0 + local.get 1 + local.get 2 + local.get 3 + i32.const 1 + local.get 0 + i32.sub + local.get 3 + i32.mul + i32.const 0 + local.get 3 + i32.const 0 + i32.le_s + select + call 2) + (func (;2;) (type 2) (param i32 f64 i32 i32 i32) (result f64) + (local f64 f64 f64 f64 f64 i32 i32) + f64.const nan (;=nan;) + local.set 8 + block ;; label = @1 + block ;; label = @2 + local.get 0 + i32.const 0 + i32.le_s + br_if 0 (;@2;) + local.get 3 + i32.eqz + local.get 0 + i32.const 1 + i32.eq + i32.or + br_if 1 (;@1;) + loop ;; label = @3 + local.get 0 + local.get 11 + i32.eq + i32.eqz + if ;; label = @4 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + f64.load + local.tee 7 + local.get 7 + f64.eq + if ;; label = @5 + local.get 7 + local.get 6 + f64.sub + local.tee 9 + local.get 7 + local.get 6 + local.get 9 + local.get 10 + i32.const 1 + i32.add + local.tee 10 + f64.convert_i32_s + f64.div + f64.add + local.tee 6 + f64.sub + f64.mul + local.get 5 + f64.add + local.set 5 + end + local.get 11 + i32.const 1 + i32.add + local.set 11 + local.get 3 + local.get 4 + i32.add + local.set 4 + br 1 (;@3;) + end + end + local.get 10 + f64.convert_i32_s + local.get 1 + f64.sub + local.tee 1 + f64.const 0x0p+0 (;=0;) + f64.le + br_if 0 (;@2;) + local.get 5 + local.get 1 + f64.div + local.set 8 + end + local.get 8 + return + end + f64.const 0x0p+0 (;=0;) + f64.const nan (;=nan;) + local.get 1 + local.get 0 + f64.convert_i32_u + f64.lt + select + f64.const nan (;=nan;) + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + f64.load + local.tee 1 + local.get 1 + f64.eq + select) + (export "__wasm_call_ctors" (func 0)) + (export "stdlib_strided_dnanvariancewd" (func 1)) + (export "stdlib_strided_dnanvariancewd_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.js new file mode 100644 index 000000000000..24dcec089707 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dnanvariancewd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnanvariancewd, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof dnanvariancewd.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof dnanvariancewd.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof dnanvariancewd.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( dnanvariancewd instanceof dnanvariancewd.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.main.js new file mode 100644 index 000000000000..1a6dc3e23148 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.main.js @@ -0,0 +1,315 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dnanvariancewd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnanvariancewd, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 4', function test( t ) { + t.strictEqual( dnanvariancewd.main.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the `main` method calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ); // eslint-disable-line max-len + + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( v, 53.5/(x.length-6), 'returns expected value' ); + + x = new Float64Array( [ -4.0, NaN ] ); + + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 4.0 ] ); + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ); // eslint-disable-line max-len + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = NaN; + } + v = dnanvariancewd.main( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-2), 'returns expected value' ); + + x = new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ); // eslint-disable-line max-len + + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( v, 53.5/(x.length-7), 'returns expected value' ); + + x = new Float64Array( [ -4.0, NaN ] ); + + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 4.0 ] ); + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ); // eslint-disable-line max-len + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = NaN; + } + v = dnanvariancewd.main( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = dnanvariancewd.main( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `main` method returns a population variance of `0` provided the first element is not `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( 1, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `main` method returns a sample variance equal to `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( 1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( 1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the `main` method returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = dnanvariancewd.main( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]); + + v = dnanvariancewd.main( 5, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports a negative `stride` parameter', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array([ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = dnanvariancewd.main( 5, 1, x, -2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.main( x.length, 1, x, -1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the `main` method returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, 1, x, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.main( x.length, x.length, x, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0, + NaN, // 4 + NaN + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = dnanvariancewd.main( 5, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.js new file mode 100644 index 000000000000..0cdcd97ef151 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.main.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.main.js new file mode 100644 index 000000000000..cea42763df4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.main.js @@ -0,0 +1,353 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 4', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance `main` method calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ) ); // eslint-disable-line max-len + y = mod.main( 7, 0, xp, 1 ); + t.strictEqual( y, 53.5/6, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ) ); // eslint-disable-line max-len + y = mod.main( 12, 0, xp, 1 ); + t.strictEqual( y, 53.5/(12-6), 'returns expected value' ); // 6 NaNs ignored => N=6 + + mod.write( xp, new Float64Array( [ -4.0, NaN ] ) ); + y = mod.main( 2, 0, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN ] ) ); + y = mod.main( 2, 0, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN ] ) ); + y = mod.main( 1, 0, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 4.0 ] ) ); + y = mod.main( 1, 0, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.main( 1000, 0, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ) ); // eslint-disable-line max-len + y = mod.main( 10, 0, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ NaN ] ) ); + } + y = mod.main( 1000, 0, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `main` method calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ) ); // eslint-disable-line max-len + y = mod.main( 7, 1, xp, 1 ); + t.strictEqual( y, 53.5/5, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ) ); // eslint-disable-line max-len + y = mod.main( 12, 1, xp, 1 ); + t.strictEqual( y, 53.5/5, 'returns expected value' ); // 6 NaNs ignored => N=6, correction=1 => N-c=5 + + mod.write( xp, new Float64Array( [ -4.0, NaN ] ) ); + y = mod.main( 2, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN ] ) ); + y = mod.main( 2, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN ] ) ); + y = mod.main( 1, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 4.0 ] ) ); + y = mod.main( 1, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.main( 1000, 1, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ) ); // eslint-disable-line max-len + y = mod.main( 10, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ NaN ] ) ); + } + y = mod.main( 1000, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance `main` method returns `NaN`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + + y = mod.main( 0, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mod.main( -1, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, a module instance `main` method returns expected results for population vs sample variance', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + + y = mod.main( 1, 0, xp, 1 ); + t.strictEqual( y, 0.0, 'population variance is 0' ); + + y = mod.main( 1, 1, xp, 1 ); + t.strictEqual( isnan( y ), true, 'sample variance is NaN' ); + + mod.write( xp, new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ) ); + y = mod.main( 1, 0, xp, 1 ); + t.strictEqual( isnan( y ), true, 'population variance is NaN when first element is NaN' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, a module instance `main` method returns `NaN`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + + y = mod.main( 6, 6, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mod.main( 6, 7, xp, 1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `main` method supports a `stride` parameter', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ])); + + y = mod.main( 5, 1, xp, 2 ); + t.strictEqual( y, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `main` method supports a negative `stride` parameter', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ])); + + y = mod.main( 5, 1, xp, -2 ); + t.strictEqual( y, 6.25, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.main( 1000, 1, xp, -1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, a module instance `main` method returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + + y = mod.main( 6, 1, xp, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ) ); + y = mod.main( 6, 1, xp, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + y = mod.main( 6, 6, xp, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.ndarray.js new file mode 100644 index 000000000000..08d94f5c1318 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.module.ndarray.js @@ -0,0 +1,307 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 5', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance `ndarray` method calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 7, 0, xp, 1, 0 ); + t.strictEqual( y, 53.5/(7-1), 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 12, 0, xp, 1, 0 ); + t.strictEqual( y, 53.5/(12-6), 'returns expected value' ); + + mod.write( xp, new Float64Array( [ -4.0, NaN ] ) ); + y = mod.ndarray( 2, 0, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN ] ) ); + y = mod.ndarray( 2, 0, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN ] ) ); + y = mod.ndarray( 1, 0, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 4.0 ] ) ); + y = mod.ndarray( 1, 0, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.ndarray( 1000, 0, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 10, 0, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ NaN ] ) ); + } + y = mod.ndarray( 1000, 0, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `ndarray` method calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 7, 1, xp, 1, 0 ); + t.strictEqual( y, 53.5/(7-2), 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 12, 1, xp, 1, 0 ); + t.strictEqual( y, 53.5/(12-7), 'returns expected value' ); + + mod.write( xp, new Float64Array( [ -4.0, NaN ] ) ); + y = mod.ndarray( 2, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN ] ) ); + y = mod.ndarray( 2, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN ] ) ); + y = mod.ndarray( 1, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 4.0 ] ) ); + y = mod.ndarray( 1, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.ndarray( 1000, 1, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ) ); // eslint-disable-line max-len + y = mod.ndarray( 10, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ NaN ] ) ); + } + y = mod.ndarray( 1000, 1, xp, 1, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `ndarray` method supports a `stride` parameter', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ])); + + y = mod.ndarray( 5, 1, xp, 2, 0 ); + t.strictEqual( y, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `ndarray` method supports a negative `stride` parameter', function test( t ) { + var mem; + var mod; + var xp; + var y; + var i; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ])); + + y = mod.ndarray( 5, 1, xp, -2, 8 ); + t.strictEqual( y, 6.25, 'returns expected value' ); + + mod.write( xp, new Float64Array( 1e3 ) ); + for ( i = 0; i < 1e3; i++ ) { + mod.write( xp + (i*8), new Float64Array( [ 100.0 ] ) ); + } + y = mod.ndarray( 1000, 1, xp, -1, 999 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, a module instance `ndarray` method returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + + y = mod.ndarray( 6, 1, xp, 0, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ) ); + y = mod.ndarray( 6, 1, xp, 0, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0, NaN ] ) ); + y = mod.ndarray( 6, 6, xp, 0, 0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance `ndarray` method supports an `offset` parameter', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ])); + + y = mod.ndarray( 5, 1, xp, 2, 1 ); + t.strictEqual( y, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.ndarray.js new file mode 100644 index 000000000000..d2675ca99ebe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.ndarray.js @@ -0,0 +1,311 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dnanvariancewd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnanvariancewd, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 5', function test( t ) { + t.strictEqual( dnanvariancewd.ndarray.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the `ndarray` method calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ); // eslint-disable-line max-len + + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-6), 'returns expected value' ); + + x = new Float64Array( [ -4.0, NaN ] ); + + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 4.0 ] ); + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ); // eslint-disable-line max-len + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = NaN; + } + v = dnanvariancewd.ndarray( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-2), 'returns expected value' ); + + x = new Float64Array( [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ] ); // eslint-disable-line max-len + + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 53.5/(x.length-7), 'returns expected value' ); + + x = new Float64Array( [ -4.0, NaN ] ); + + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 4.0 ] ); + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ] ); // eslint-disable-line max-len + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = NaN; + } + v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `ndarray` method returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = dnanvariancewd.ndarray( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `ndarray` method returns a population variance of `0` provided the first element is not `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( 1, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `ndarray` method returns a sample variance equal to `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( 1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( 1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the `ndarray` method returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = dnanvariancewd.ndarray( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]); + + v = dnanvariancewd.ndarray( 5, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a negative `stride` parameter', function test( t ) { + var x; + var v; + var i; + + x = new Float64Array([ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = dnanvariancewd.ndarray( 5, 1, x, -2, 8 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + x = new Float64Array( 1e3 ); + for ( i = 0; i < 1e3; i++ ) { + x[ i ] = 100.0; + } + v = dnanvariancewd.ndarray( x.length, 1, x, -1, x.length-1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the `ndarray` method returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float64Array( [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, 1, x, 0, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnanvariancewd.ndarray( x.length, x.length, x, 0, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ]); + + v = dnanvariancewd.ndarray( 5, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.routine.js b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.routine.js new file mode 100644 index 000000000000..806b3de987e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/wasm/dnanvariancewd/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From 57a9400329d0570d2b25ad6b87d4d9a74d7fc28b Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 16 Sep 2025 23:07:08 -0700 Subject: [PATCH 04/17] fix: avoid strict equality check --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/flatten/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js b/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js index 22ecfba4112d..9b728c85dc72 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js @@ -301,7 +301,7 @@ function flatten( x, options ) { }; // Resolve function options... - if ( nargs === 2 ) { + if ( nargs > 1 ) { if ( !isPlainObject( options ) ) { throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } From c8652f3a3ca317179b46596787eb4db4966c154a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 17 Sep 2025 12:31:38 +0500 Subject: [PATCH 05/17] feat: add `ndarray/flatten-by` PR-URL: https://github.com/stdlib-js/stdlib/pull/8078 Ref: https://github.com/stdlib-js/stdlib/issues/2656 Closes: https://github.com/stdlib-js/metr-issue-tracker/issues/76 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/ndarray/flatten-by/README.md | 231 ++ .../ndarray/flatten-by/benchmark/benchmark.js | 315 +++ .../@stdlib/ndarray/flatten-by/docs/repl.txt | 49 + .../ndarray/flatten-by/docs/types/index.d.ts | 387 ++++ .../ndarray/flatten-by/docs/types/test.ts | 209 ++ .../ndarray/flatten-by/examples/index.js | 41 + .../@stdlib/ndarray/flatten-by/lib/index.js | 52 + .../@stdlib/ndarray/flatten-by/lib/main.js | 187 ++ .../@stdlib/ndarray/flatten-by/package.json | 65 + .../@stdlib/ndarray/flatten-by/test/test.js | 1991 +++++++++++++++++ 10 files changed, 3527 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/README.md b/lib/node_modules/@stdlib/ndarray/flatten-by/README.md new file mode 100644 index 000000000000..f4121b083525 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/README.md @@ -0,0 +1,231 @@ + + +# flattenBy + +> Flatten an [ndarray][@stdlib/ndarray/ctor] according to a callback function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var flattenBy = require( '@stdlib/ndarray/flatten-by' ); +``` + +#### flattenBy( x\[, options], fcn\[, thisArg] ) + +Flattens an [ndarray][@stdlib/ndarray/ctor] according to a callback function. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function scale( value ) { + return value * 2.0; +} + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var y = flattenBy( x, scale ); +// returns + +var arr = ndarray2array( y ); +// returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). +- **fcn**: callback function. +- **thisArg**: callback execution context (_optional_). + +The function accepts the following options: + +- **order**: order in which input [ndarray][@stdlib/ndarray/ctor] elements should be flattened. Must be one of the following: + + - `'row-major'`: flatten elements in lexicographic order. For example, given a two-dimensional input [ndarray][@stdlib/ndarray/ctor] (i.e., a matrix), flattening in lexicographic order means flattening the input [ndarray][@stdlib/ndarray/ctor] row-by-row. + - `'column-major'`: flatten elements in colexicographic order. For example, given a two-dimensional input [ndarray][@stdlib/ndarray/ctor] (i.e., a matrix), flattening in colexicographic order means flattening the input [ndarray][@stdlib/ndarray/ctor] column-by-column. + - `'any'`: flatten according to the physical layout of the input [ndarray][@stdlib/ndarray/ctor] data in memory, regardless of the stated [order][@stdlib/ndarray/orders] of the input [ndarray][@stdlib/ndarray/ctor]. + - `'same'`: flatten according to the stated [order][@stdlib/ndarray/orders] of the input [ndarray][@stdlib/ndarray/ctor]. + + Default: `'row-major'`. + +- **depth**: maximum number of input [ndarray][@stdlib/ndarray/ctor] dimensions to flatten. + +By default, the function flattens all dimensions of the input [ndarray][@stdlib/ndarray/ctor]. To flatten to a desired depth, specify the `depth` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function scale( value ) { + return value * 2.0; +} + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var opts = { + 'depth': 1 +}; + +var y = flattenBy( x, opts, scale ); +// returns + +var arr = ndarray2array( y ); +// returns [ [ 2.0, 4.0 ], [ 6.0, 8.0 ], [ 10.0, 12.0 ] ] +``` + +By default, the input [ndarray][@stdlib/ndarray/ctor] is flattened in lexicographic order. To flatten elements in a different order, specify the `order` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function scale( value ) { + return value * 2.0; +} + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var opts = { + 'order': 'column-major' +}; + +var y = flattenBy( x, opts, scale ); +// returns + +var arr = ndarray2array( y ); +// returns [ 2.0, 6.0, 10.0, 4.0, 8.0, 12.0 ] +``` + +To set the callback function execution context, provide a `thisArg`. + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function scale( value ) { + this.count += 1; + return value * 2.0; +} + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var ctx = { + 'count': 0 +}; + +var y = flattenBy( x, scale, ctx ); +// returns + +var arr = ndarray2array( y ); +// returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] + +var count = ctx.count; +// returns 6 +``` + +
+ + + +
+ +## Notes + +- The function **always** returns a copy of input [ndarray][@stdlib/ndarray/ctor] data, even when an input [ndarray][@stdlib/ndarray/ctor] already has the desired number of dimensions. + +- The callback function is provided the following arguments: + + - **value**: current array element. + - **indices**: current array element indices. + - **arr**: the input [ndarray][@stdlib/ndarray/ctor]. + +- The order in which array elements are traversed and passed to a provided callback function is **not** guaranteed to match the order of array elements in an [ndarray][@stdlib/ndarray/ctor] view. Accordingly, a provided callback should avoid making assumptions regarding the order of provided elements. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var flattenBy = require( '@stdlib/ndarray/flatten-by' ); + +function scale( value ) { + return value * 2.0; +} + +var xbuf = discreteUniform( 12, -100, 100, { + 'dtype': 'generic' +}); + +var x = array( xbuf, { + 'shape': [ 2, 2, 3 ], + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = flattenBy( x, scale ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/flatten-by/benchmark/benchmark.js new file mode 100644 index 000000000000..85beef563891 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/benchmark/benchmark.js @@ -0,0 +1,315 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var pkg = require( './../package.json' ).name; +var flattenBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @param {number} value - current value +* @returns {number} output value +*/ +function clbk( value ) { + return value + 1; +} + + +// MAIN // + +bench( pkg+'::2d:row-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 10, 10 ], 'row-major' ), + zeros( 'float32', [ 10, 10 ], 'row-major' ), + zeros( 'int32', [ 10, 10 ], 'row-major' ), + zeros( 'generic', [ 10, 10 ], 'row-major' ) + ]; + opts = { + 'depth': 1, + 'order': 'row-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::2d:column-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 10, 10 ], 'row-major' ), + zeros( 'float32', [ 10, 10 ], 'row-major' ), + zeros( 'int32', [ 10, 10 ], 'row-major' ), + zeros( 'generic', [ 10, 10 ], 'row-major' ) + ]; + opts = { + 'depth': 1, + 'order': 'column-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d:row-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 10 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 10 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 10 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 10 ], 'row-major' ) + ]; + opts = { + 'depth': 2, + 'order': 'row-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d:column-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 10 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 10 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 10 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 10 ], 'row-major' ) + ]; + opts = { + 'depth': 2, + 'order': 'column-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d:row-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 2, 5 ], 'row-major' ) + ]; + opts = { + 'depth': 3, + 'order': 'row-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d:column-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 2, 5 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 2, 5 ], 'row-major' ) + ]; + opts = { + 'depth': 3, + 'order': 'column-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d:row-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 2, 5, 1 ], 'row-major' ) + ]; + opts = { + 'depth': 4, + 'order': 'row-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d:column-major', function benchmark( b ) { + var values; + var opts; + var y; + var i; + var j; + + values = [ + zeros( 'float64', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'float32', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'int32', [ 2, 5, 2, 5, 1 ], 'row-major' ), + zeros( 'generic', [ 2, 5, 2, 5, 1 ], 'row-major' ) + ]; + opts = { + 'depth': 4, + 'order': 'column-major' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % values.length; + y = flattenBy( values[ j ], opts, clbk ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt new file mode 100644 index 000000000000..f6cae4264419 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( x[, options], fcn[, thisArg] ) + Flattens an ndarray according to a callback function. + + Parameters + ---------- + x: ndarray + Input ndarray. + + options: Object (optional) + Function options. + + options.depth: integer (optional) + Maximum number of dimensions to flatten. By default, the function + flattens all input ndarray dimensions. + + options.order: string (optional) + Order in which input ndarray elements should be flattened. The following + orders are supported: + + - row-major: flatten in lexicographic order. + - column-major: flatten in colexicographic order. + - same: flatten according to the stated order of the input ndarray. + - any: flatten according to physical layout of the input ndarray data in + memory, regardless of the stated order of the input ndarray. + + Default: 'row-major'. + + fcn: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + out: ndarray + Output ndarray. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + > function f ( v ) { return v * 2.0 }; + > var y = {{alias}}( x, f ); + > var arr = {{alias:@stdlib/ndarray/to-array}}( y ) + [ 2.0, 4.0, 6.0, 8.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts new file mode 100644 index 000000000000..a97d0924d204 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts @@ -0,0 +1,387 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray, genericndarray, Order } from '@stdlib/types/ndarray'; +import { ComplexLike } from '@stdlib/types/complex'; + +/** +* Callback invoked for each ndarray element. +* +* @returns output value +*/ +type Nullary = ( this: ThisArg ) => V; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @returns output value +*/ +type Unary = ( this: ThisArg, value: T ) => V; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @returns output value +*/ +type Binary = ( this: ThisArg, value: T, indices: Array ) => V; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns output value +*/ +type Ternary = ( this: ThisArg, value: T, indices: Array, arr: U ) => V; + +/** +* Callback invoked for each ndarray element. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns output value +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Maximum number of dimensions to flatten. + * + * ## Notes + * + * - By default, the function flattens all input ndarray dimensions. + */ + depth?: number; + + /** + * Order in which input ndarray elements should be flattened. + * + * ## Notes + * + * - The following orders are supported: + * + * - **row-major**: flatten in lexicographic order. + * - **column-major**: flatten in colexicographic order. + * - **same**: flatten according to the stated order of the input ndarray. + * - **any**: flatten according to the physical layout of the input ndarray data in memory, regardless of the stated order of the input ndarray. + * + * - Default: 'row-major'. + */ + order?: Order | 'same' | 'any'; +} + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var y = flattenBy( x, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, fcn: Callback, thisArg?: ThisParameterType> ): T; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function identity( value ) { +* return value; +* } +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 1, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var y = flattenBy( x, identity ); +* // returns +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: U, fcn: Callback, thisArg?: ThisParameterType> ): U; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function invert( value ) { +* return !value; +* } +* +* var buffer = new BooleanArray( [ true, false, true, false, true, false ] ); +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var y = flattenBy( x, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ false, true, false, true, false, true ] +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, fcn: Callback, thisArg?: ThisParameterType> ): T; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var y = flattenBy( x, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +declare function flattenBy = genericndarray, V = unknown, W extends genericndarray = genericndarray, ThisArg = unknown>( x: U, fcn: Callback, thisArg?: ThisParameterType> ): W; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var opts = { +* 'depth': 2 +* }; +* +* var y = flattenBy( x, opts, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): T; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function identity( value ) { +* return value; +* } +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 1, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var opts = { +* 'depth': 1 +* }; +* +* var y = flattenBy( x, opts, identity ); +* // returns +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: U, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): U; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function invert( value ) { +* return !value; +* } +* +* var buffer = new BooleanArray( [ true, false, true, false, true, false ] ); +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var opts = { +* 'depth': 2 +* }; +* +* var y = flattenBy( x, opts, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ false, true, false, true, false, true ] +*/ +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): T; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var opts = { +* 'depth': 2 +* }; +* +* var y = flattenBy( x, opts, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +declare function flattenBy = genericndarray, V = unknown, W extends genericndarray = genericndarray, ThisArg = unknown>( x: U, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): W; + + +// EXPORTS // + +export = flattenBy; diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts new file mode 100644 index 000000000000..d0eec5992d8c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts @@ -0,0 +1,209 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import empty = require( '@stdlib/ndarray/base/empty' ); +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import flattenBy = require( './index' ); + +/** +* Evaluates the identity function. +* +* @param x - input value +* @returns input value +*/ +function identity( x: any ): any { + return x; +} + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + flattenBy( zeros( 'float64', sh, ord ), identity ); // $ExpectType float64ndarray + flattenBy( zeros( 'float64', sh, ord ), {}, identity ); // $ExpectType float64ndarray + flattenBy( zeros( 'float64', sh, ord ), identity, {} ); // $ExpectType float64ndarray + flattenBy( zeros( 'float64', sh, ord ), {}, identity, {} ); // $ExpectType float64ndarray + flattenBy( zeros( 'float32', sh, ord ), identity ); // $ExpectType float32ndarray + flattenBy( zeros( 'float32', sh, ord ), {}, identity ); // $ExpectType float32ndarray + flattenBy( zeros( 'float32', sh, ord ), identity, {} ); // $ExpectType float32ndarray + flattenBy( zeros( 'float32', sh, ord ), {}, identity, {} ); // $ExpectType float32ndarray + flattenBy( zeros( 'complex64', sh, ord ), identity ); // $ExpectType complex64ndarray + flattenBy( zeros( 'complex64', sh, ord ), {}, identity ); // $ExpectType complex64ndarray + flattenBy( zeros( 'complex64', sh, ord ), identity, {} ); // $ExpectType complex64ndarray + flattenBy( zeros( 'complex64', sh, ord ), {}, identity, {} ); // $ExpectType complex64ndarray + flattenBy( zeros( 'complex128', sh, ord ), identity ); // $ExpectType complex128ndarray + flattenBy( zeros( 'complex128', sh, ord ), {}, identity ); // $ExpectType complex128ndarray + flattenBy( zeros( 'complex128', sh, ord ), identity, {} ); // $ExpectType complex128ndarray + flattenBy( zeros( 'complex128', sh, ord ), {}, identity, {} ); // $ExpectType complex128ndarray + flattenBy( zeros( 'int32', sh, ord ), identity ); // $ExpectType int32ndarray + flattenBy( zeros( 'int32', sh, ord ), {}, identity ); // $ExpectType int32ndarray + flattenBy( zeros( 'int32', sh, ord ), identity, {} ); // $ExpectType int32ndarray + flattenBy( zeros( 'int32', sh, ord ), {}, identity, {} ); // $ExpectType int32ndarray + flattenBy( zeros( 'int16', sh, ord ), identity ); // $ExpectType int16ndarray + flattenBy( zeros( 'int16', sh, ord ), {}, identity ); // $ExpectType int16ndarray + flattenBy( zeros( 'int16', sh, ord ), identity, {} ); // $ExpectType int16ndarray + flattenBy( zeros( 'int16', sh, ord ), {}, identity, {} ); // $ExpectType int16ndarray + flattenBy( zeros( 'int8', sh, ord ), identity ); // $ExpectType int8ndarray + flattenBy( zeros( 'int8', sh, ord ), {}, identity ); // $ExpectType int8ndarray + flattenBy( zeros( 'int8', sh, ord ), identity, {} ); // $ExpectType int8ndarray + flattenBy( zeros( 'int8', sh, ord ), {}, identity, {} ); // $ExpectType int8ndarray + flattenBy( zeros( 'uint32', sh, ord ), identity ); // $ExpectType uint32ndarray + flattenBy( zeros( 'uint32', sh, ord ), {}, identity ); // $ExpectType uint32ndarray + flattenBy( zeros( 'uint32', sh, ord ), identity, {} ); // $ExpectType uint32ndarray + flattenBy( zeros( 'uint16', sh, ord ), identity ); // $ExpectType uint16ndarray + flattenBy( zeros( 'uint16', sh, ord ), {}, identity ); // $ExpectType uint16ndarray + flattenBy( zeros( 'uint16', sh, ord ), identity, {} ); // $ExpectType uint16ndarray + flattenBy( zeros( 'uint16', sh, ord ), {}, identity, {} ); // $ExpectType uint16ndarray + flattenBy( zeros( 'uint8', sh, ord ), identity ); // $ExpectType uint8ndarray + flattenBy( zeros( 'uint8', sh, ord ), {}, identity ); // $ExpectType uint8ndarray + flattenBy( zeros( 'uint8', sh, ord ), identity, {} ); // $ExpectType uint8ndarray + flattenBy( zeros( 'uint8', sh, ord ), {}, identity, {} ); // $ExpectType uint8ndarray + flattenBy( zeros( 'uint8c', sh, ord ), identity ); // $ExpectType uint8cndarray + flattenBy( zeros( 'uint8c', sh, ord ), {}, identity ); // $ExpectType uint8cndarray + flattenBy( zeros( 'uint8c', sh, ord ), identity, {} ); // $ExpectType uint8cndarray + flattenBy( zeros( 'uint8c', sh, ord ), {}, identity, {} ); // $ExpectType uint8cndarray + flattenBy( empty( 'bool', sh, ord ), identity ); // $ExpectType boolndarray + flattenBy( empty( 'bool', sh, ord ), {}, identity ); // $ExpectType boolndarray + flattenBy( empty( 'bool', sh, ord ), identity, {} ); // $ExpectType boolndarray + flattenBy( empty( 'bool', sh, ord ), {}, identity, {} ); // $ExpectType boolndarray + flattenBy( zeros( 'generic', sh, ord ), identity ); // $ExpectType genericndarray + flattenBy( zeros( 'generic', sh, ord ), {}, identity ); // $ExpectType genericndarray + flattenBy( zeros( 'generic', sh, ord ), identity, {} ); // $ExpectType genericndarray + flattenBy( zeros( 'generic', sh, ord ), {}, identity, {} ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + flattenBy( 5, identity ); // $ExpectError + flattenBy( true, identity ); // $ExpectError + flattenBy( false, identity ); // $ExpectError + flattenBy( null, identity ); // $ExpectError + flattenBy( undefined, identity ); // $ExpectError + flattenBy( {}, identity ); // $ExpectError + flattenBy( [ 1 ], identity ); // $ExpectError + flattenBy( ( x: number ): number => x, identity ); // $ExpectError + + flattenBy( 5, {}, identity ); // $ExpectError + flattenBy( true, {}, identity ); // $ExpectError + flattenBy( false, {}, identity ); // $ExpectError + flattenBy( null, {}, identity ); // $ExpectError + flattenBy( undefined, {}, identity ); // $ExpectError + flattenBy( {}, {}, identity ); // $ExpectError + flattenBy( [ 1 ], {}, identity ); // $ExpectError + flattenBy( ( x: number ): number => x, {}, identity ); // $ExpectError + + flattenBy( 5, identity, {} ); // $ExpectError + flattenBy( true, identity, {} ); // $ExpectError + flattenBy( false, identity, {} ); // $ExpectError + flattenBy( null, identity, {} ); // $ExpectError + flattenBy( undefined, identity, {} ); // $ExpectError + flattenBy( {}, identity, {} ); // $ExpectError + flattenBy( [ 1 ], identity, {} ); // $ExpectError + flattenBy( ( x: number ): number => x, identity, {} ); // $ExpectError + + flattenBy( 5, {}, identity, {} ); // $ExpectError + flattenBy( true, {}, identity, {} ); // $ExpectError + flattenBy( false, {}, identity, {} ); // $ExpectError + flattenBy( null, {}, identity, {} ); // $ExpectError + flattenBy( undefined, {}, identity, {} ); // $ExpectError + flattenBy( {}, {}, identity, {} ); // $ExpectError + flattenBy( [ 1 ], {}, identity, {} ); // $ExpectError + flattenBy( ( x: number ): number => x, {}, identity, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( 'generic', [ 2, 2, 2 ], 'row-major' ); + + flattenBy( x, '5', identity ); // $ExpectError + flattenBy( x, true, identity ); // $ExpectError + flattenBy( x, false, identity ); // $ExpectError + flattenBy( x, null, identity ); // $ExpectError + flattenBy( x, [ 1 ], identity ); // $ExpectError + + flattenBy( x, '5', identity, {} ); // $ExpectError + flattenBy( x, true, identity, {} ); // $ExpectError + flattenBy( x, false, identity, {} ); // $ExpectError + flattenBy( x, null, identity, {} ); // $ExpectError + flattenBy( x, [ 1 ], identity, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument with invalid `depth` option... +{ + const x = zeros( 'generic', [ 2, 2, 2 ], 'row-major' ); + + flattenBy( x, { 'depth': '5' }, identity ); // $ExpectError + flattenBy( x, { 'depth': true }, identity ); // $ExpectError + flattenBy( x, { 'depth': false }, identity ); // $ExpectError + flattenBy( x, { 'depth': null }, identity ); // $ExpectError + flattenBy( x, { 'depth': [ 1 ] }, identity ); // $ExpectError + + flattenBy( x, { 'depth': '5' }, identity, {} ); // $ExpectError + flattenBy( x, { 'depth': true }, identity, {} ); // $ExpectError + flattenBy( x, { 'depth': false }, identity, {} ); // $ExpectError + flattenBy( x, { 'depth': null }, identity, {} ); // $ExpectError + flattenBy( x, { 'depth': [ 1 ] }, identity, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument with invalid `order` option... +{ + const x = zeros( 'generic', [ 2, 2, 2 ], 'row-major' ); + + flattenBy( x, { 'order': '5' }, identity ); // $ExpectError + flattenBy( x, { 'order': true }, identity ); // $ExpectError + flattenBy( x, { 'order': false }, identity ); // $ExpectError + flattenBy( x, { 'order': null }, identity ); // $ExpectError + flattenBy( x, { 'order': [ 1 ] }, identity ); // $ExpectError + + flattenBy( x, { 'order': '5' }, identity, {} ); // $ExpectError + flattenBy( x, { 'order': true }, identity, {} ); // $ExpectError + flattenBy( x, { 'order': false }, identity, {} ); // $ExpectError + flattenBy( x, { 'order': null }, identity, {} ); // $ExpectError + flattenBy( x, { 'order': [ 1 ] }, identity, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback which is not a function... +{ + const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + flattenBy( x, {}, '5' ); // $ExpectError + flattenBy( x, {}, true ); // $ExpectError + flattenBy( x, {}, false ); // $ExpectError + flattenBy( x, {}, null ); // $ExpectError + flattenBy( x, {}, undefined ); // $ExpectError + flattenBy( x, {}, {} ); // $ExpectError + flattenBy( x, {}, [ 1 ] ); // $ExpectError + + flattenBy( x, {}, '5', {} ); // $ExpectError + flattenBy( x, {}, true, {} ); // $ExpectError + flattenBy( x, {}, false, {} ); // $ExpectError + flattenBy( x, {}, null, {} ); // $ExpectError + flattenBy( x, {}, undefined, {} ); // $ExpectError + flattenBy( x, {}, {}, {} ); // $ExpectError + flattenBy( x, {}, [ 1 ], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( 'generic', [ 2, 2, 2 ], 'row-major' ); + + flattenBy(); // $ExpectError + flattenBy( x ); // $ExpectError + flattenBy( x, {}, ( x: number ): number => x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/examples/index.js b/lib/node_modules/@stdlib/ndarray/flatten-by/examples/index.js new file mode 100644 index 000000000000..d99b9ccc65e3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var flattenBy = require( './../lib' ); + +function scale( value ) { + return value * 2.0; +} + +var xbuf = discreteUniform( 12, -100, 100, { + 'dtype': 'generic' +}); + +var x = array( xbuf, { + 'shape': [ 2, 2, 3 ], + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = flattenBy( x, scale ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/lib/index.js b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/index.js new file mode 100644 index 000000000000..204d867de17b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/index.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Flatten an ndarray according to a callback function. +* +* @module @stdlib/ndarray/flatten-by +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var flattenBy = require( '@stdlib/ndarray/flatten-by' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +* // return +* +* var y = flattenBy( x, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js new file mode 100644 index 000000000000..b06674f4df5a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js @@ -0,0 +1,187 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ); +var isOrder = require( '@stdlib/ndarray/base/assert/is-order' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2order = require( '@stdlib/ndarray/base/strides2order' ); +var flattenShape = require( '@stdlib/ndarray/base/flatten-shape' ); +var map = require( '@stdlib/ndarray/base/map' ); +var emptyLike = require( '@stdlib/ndarray/empty-like' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var ROW_MAJOR = 'row-major'; +var COL_MAJOR = 'column-major'; + + +// MAIN // + +/** +* Flattens an ndarray according to a callback function. +* +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {NonNegativeInteger} [options.depth] - maximum number of dimensions to flatten +* @param {string} [options.order='row-major'] - order in which input ndarray elements should be flattened +* @param {Function} fcn - callback function +* @param {*} [thisArg] - callback execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {TypeError} callback argument must be a function +* @throws {TypeError} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +* // return +* +* var y = flattenBy( x, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +function flattenBy( x, options, fcn, thisArg ) { + var hasOpts; + var nargs; + var view; + var opts; + var ctx; + var xsh; + var cb; + var st; + var y; + var o; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + nargs = arguments.length; + xsh = getShape( x ); + hasOpts = false; + + // Define default options: + opts = { + 'depth': xsh.length, // by default, flatten to a one-dimensional ndarray + 'order': ROW_MAJOR // by default, flatten in lexicographic order (i.e., trailing dimensions first; e.g., if `x` is a matrix, flatten row-by-row) + }; + + // Case: flattenBy( x, fcn ) + if ( nargs <= 2 ) { + cb = options; + } + // Case: flattenBy( x, ???, ??? ) + else if ( nargs === 3 ) { + // Case: flattenBy( x, fcn, thisArg ) + if ( isFunction( options ) ) { + cb = options; + ctx = fcn; + } + // Case: flattenBy( x, options, fcn ) + else { + hasOpts = true; + cb = fcn; + } + } + // Case: flattenBy( x, options, fcn, thisArg ) + else { + hasOpts = true; + cb = fcn; + ctx = thisArg; + } + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) ); + } + if ( hasOpts ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'depth' ) ) { + if ( !isNonNegativeInteger( options.depth ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', options.depth ) ); + } + opts.depth = options.depth; + } + if ( hasOwnProp( options, 'order' ) ) { + if ( options.order === 'any' ) { + // When 'any', we want to flatten according to the physical layout of the data in memory... + o = strides2order( getStrides( x ) ); + if ( o === 1 ) { + // Data is currently arranged in row-major order: + opts.order = ROW_MAJOR; + } else if ( o === 2 ) { + // Data is currently arranged in column-major order: + opts.order = COL_MAJOR; + } else { // o === 0 || o === 3 (i.e., neither row- nor column-major || both row- and column-major + // When the data is either both row- and column-major (e.g., a one-dimensional ndarray) or neither row- nor column-major (e.g., unordered strides), fallback to flattening according to the stated order of the input ndarray: + opts.order = getOrder( x ); + } + } else if ( options.order === 'same' ) { + // When 'same', we want to flatten according to the stated order of the input ndarray: + opts.order = getOrder( x ); + } else if ( isOrder( options.order ) ) { + // When provided a specific order, flatten according to that order regardless of the order of the input ndarray: + opts.order = options.order; + } else { + throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + } + } + } + // Create an output ndarray having contiguous memory: + y = emptyLike( x, { + 'shape': flattenShape( xsh, opts.depth ), + 'order': opts.order + }); + + // Create a view on top of output ndarray having the same shape as the input ndarray: + st = ( xsh.length > 0 ) ? shape2strides( xsh, opts.order ) : [ 0 ]; + view = ndarray( getDType( y ), getData( y ), xsh, st, 0, opts.order ); + + // Transform and assign elements to the output ndarray: + map( [ x, view ], cb, ctx ); + return y; +} + + +// EXPORTS // + +module.exports = flattenBy; diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/package.json b/lib/node_modules/@stdlib/ndarray/flatten-by/package.json new file mode 100644 index 000000000000..1317829b37c8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/flatten-by", + "version": "0.0.0", + "description": "Flatten an ndarray according to a callback function.", + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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", + "multidimensional", + "array", + "ndarray", + "tensor", + "matrix", + "flat", + "flatten", + "map", + "copy", + "transform" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js b/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js new file mode 100644 index 000000000000..9b306deb95f9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js @@ -0,0 +1,1991 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var Float64Array = require( '@stdlib/array/float64' ); +var identity = require( '@stdlib/number/float64/base/identity' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var flattenBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof flattenBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( value, identity ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( value, {}, identity ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( value, identity, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray (options, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( value, {}, identity, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( zeros( [ 2, 2, 2 ] ), value, identity ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( zeros( [ 2, 2, 2 ] ), value, identity, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `depth` option', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'depth': value + }; + flattenBy( zeros( [ 2 ] ), opts, identity ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `order` option', function test( t ) { + var values; + var opts; + var i; + + values = [ + '5', + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + opts = { + 'order': value + }; + flattenBy( zeros( [ 2 ] ), opts, identity ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( zeros( [ 2, 2, 2 ] ), {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided a callback argument which is not a function (thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + flattenBy( zeros( [ 2, 2, 2 ] ), {}, value, {} ); + }; + } +}); + +tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (row-major, contiguous)', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (row-major, non-contiguous)', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = [ 8, 4, 2 ]; + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, NaN, 2.0, NaN, 3.0, NaN, 4.0, NaN, 5.0, NaN, 6.0, NaN, 7.0, NaN, 8.0, NaN ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (column-major, contiguous)', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (column-major, non-contiguous)', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = [ 2, 4, 8 ]; + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, NaN, 5.0, NaN, 3.0, NaN, 7.0, NaN, 2.0, NaN, 6.0, NaN, 4.0, NaN, 8.0, NaN ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the maximum number of dimensions to flatten (row-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'depth': 0 + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1 + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 2 + }; + y = flattenBy( x, opts, identity ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the maximum number of dimensions to flatten (column-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'depth': 0 + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] + ], + [ + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1 + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 2 + }; + y = flattenBy( x, opts, identity ); + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in lexicographic order (row-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'row-major' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'row-major' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in lexicographic order (column-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'row-major' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'row-major' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in colexicographic order (row-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'column-major' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'column-major' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 5.0, 6.0 ], + [ 3.0, 4.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in colexicographic order (column-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'column-major' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'column-major' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 5.0, 6.0 ], + [ 3.0, 4.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in same order as the input ndarray (row-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 3.0, 4.0 ], + [ 5.0, 6.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray in same order as the input ndarray (column-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 1.0, 2.0 ], + [ 5.0, 6.0 ], + [ 3.0, 4.0 ], + [ 7.0, 8.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray according to the physical layout of the input ndarray (row-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = [ -1, -2, -4 ]; // reversing and negating the strides simulates a flipped and reversed view + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 8.0, 4.0 ], + * [ 6.0, 2.0 ] + * ], + * [ + * [ 7.0, 3.0 ], + * [ 5.0, 1.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 8.0, 4.0 ], + [ 7.0, 3.0 ], + [ 6.0, 2.0 ], + [ 5.0, 1.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a provided input ndarray according to the physical layout of the input ndarray (column-major)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = [ -4, -2, -1 ]; // reversing and negating the strides simulates a flipped and reversed view + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 8.0, 7.0 ], + * [ 6.0, 5.0 ] + * ], + * [ + * [ 4.0, 3.0 ], + * [ 2.0, 1.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + opts = { + 'depth': 1, + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = [ + [ 8.0, 7.0 ], + [ 6.0, 5.0 ], + [ 4.0, 3.0 ], + [ 2.0, 1.0 ] + ]; + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.deepEqual( ndarray2array( y ), expected, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 4, 2 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a zero-dimensional input ndarray', function test( t ) { + var expected; + var xbuf; + var dt; + var x; + var y; + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'row-major' + }); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'column-major' + }); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a zero-dimensional input ndarray (order=same)', function test( t ) { + var expected; + var xbuf; + var opts; + var dt; + var x; + var y; + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'row-major' + }); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'column-major' + }); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a zero-dimensional input ndarray (order=any)', function test( t ) { + var expected; + var xbuf; + var opts; + var dt; + var x; + var y; + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'row-major' + }); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + x = scalar2ndarray( 3.0, { + 'dtype': dt, + 'order': 'column-major' + }); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 3.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a one-dimensional input ndarray', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + ord = 'column-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flattenBy( x, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a one-dimensional input ndarray (order=same)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + ord = 'column-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'same' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports flattening a one-dimensional input ndarray (order=any)', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + + dt = 'float64'; + ord = 'column-major'; + sh = [ 8 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'order': 'any' + }; + y = flattenBy( x, opts, identity ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the callback execution context (row-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var xbuf; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + ctx = { + 'count': 1 + }; + + values = []; + indices = []; + arrays = []; + y = flattenBy( x, clbk, ctx ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.strictEqual( ctx.count, 9, 'returns expected value' ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 0, 1, 0 ], + [ 0, 1, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 1, 1, 0 ], + [ 1, 1, 1 ] + ]; + indices.sort( ascending ); // index order is not guaranteed + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x, + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v; + } + + function ascending( a, b ) { + if ( a[ 0 ] > b[ 0 ] ) { + return 1; + } + if ( a[ 0 ] < b[ 0 ] ) { + return -1; + } + if ( a[ 1 ] > b[ 1 ] ) { + return 1; + } + if ( a[ 1 ] < b[ 1 ] ) { + return -1; + } + if ( a[ 2 ] > b[ 2 ] ) { + return 1; + } + if ( a[ 2 ] < b[ 2 ] ) { + return -1; + } + return 0; + } +}); + +tape( 'the function supports specifying the callback execution context (row-major, options)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var xbuf; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + ctx = { + 'count': 1 + }; + + values = []; + indices = []; + arrays = []; + y = flattenBy( x, {}, clbk, ctx ); + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.strictEqual( ctx.count, 9, 'returns expected value' ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 0, 1, 0 ], + [ 0, 1, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 1, 1, 0 ], + [ 1, 1, 1 ] + ]; + indices.sort( ascending ); // index order is not guaranteed + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x, + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v; + } + + function ascending( a, b ) { + if ( a[ 0 ] > b[ 0 ] ) { + return 1; + } + if ( a[ 0 ] < b[ 0 ] ) { + return -1; + } + if ( a[ 1 ] > b[ 1 ] ) { + return 1; + } + if ( a[ 1 ] < b[ 1 ] ) { + return -1; + } + if ( a[ 2 ] > b[ 2 ] ) { + return 1; + } + if ( a[ 2 ] < b[ 2 ] ) { + return -1; + } + return 0; + } +}); + +tape( 'the function supports specifying the callback execution context (column-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var xbuf; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + ctx = { + 'count': 1 + }; + + values = []; + indices = []; + arrays = []; + y = flattenBy( x, clbk, ctx ); + expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.strictEqual( ctx.count, 9, 'returns expected value' ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 0, 1, 0 ], + [ 0, 1, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 1, 1, 0 ], + [ 1, 1, 1 ] + ]; + indices.sort( ascending ); // index order is not guaranteed + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x, + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v; + } + + function ascending( a, b ) { + if ( a[ 0 ] > b[ 0 ] ) { + return 1; + } + if ( a[ 0 ] < b[ 0 ] ) { + return -1; + } + if ( a[ 1 ] > b[ 1 ] ) { + return 1; + } + if ( a[ 1 ] < b[ 1 ] ) { + return -1; + } + if ( a[ 2 ] > b[ 2 ] ) { + return 1; + } + if ( a[ 2 ] < b[ 2 ] ) { + return -1; + } + return 0; + } +}); + +tape( 'the function supports specifying the callback execution context (column-major, options)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var xbuf; + var ord; + var ctx; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + ctx = { + 'count': 1 + }; + + values = []; + indices = []; + arrays = []; + y = flattenBy( x, {}, clbk, ctx ); + expected = new Float64Array( [ 1.0, 5.0, 3.0, 7.0, 2.0, 6.0, 4.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), dt, 'returns expected value' ); + t.strictEqual( getOrder( y ), 'row-major', 'returns expected value' ); + t.strictEqual( ctx.count, 9, 'returns expected value' ); + + expected = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 0, 1, 0 ], + [ 0, 1, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ], + [ 1, 1, 0 ], + [ 1, 1, 1 ] + ]; + indices.sort( ascending ); // index order is not guaranteed + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x, + x, + x, + x, + x + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v; + } + + function ascending( a, b ) { + if ( a[ 0 ] > b[ 0 ] ) { + return 1; + } + if ( a[ 0 ] < b[ 0 ] ) { + return -1; + } + if ( a[ 1 ] > b[ 1 ] ) { + return 1; + } + if ( a[ 1 ] < b[ 1 ] ) { + return -1; + } + if ( a[ 2 ] > b[ 2 ] ) { + return 1; + } + if ( a[ 2 ] < b[ 2 ] ) { + return -1; + } + return 0; + } +}); From 27437323cb1d22c53c91f152d6d05153630bc123 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 01:43:25 -0700 Subject: [PATCH 06/17] docs: fix description --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/nullary-strided1d-dispatch/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch/docs/types/index.d.ts index f963101617fd..bbd07923e964 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch/docs/types/index.d.ts @@ -186,7 +186,7 @@ declare class NullaryStrided1dDispatch { * * @param out - output ndarray * @param x - additional ndarray argument - * @param args - output ndarray, additional ndarray arguments, and function options + * @param args - additional ndarray arguments and function options * @returns output ndarray * * @example From 724283b0bc5d2eb8bf48491c954c6a119330c1f5 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 17 Sep 2025 14:06:27 +0500 Subject: [PATCH 07/17] feat: add `ndarray/base/nullary-strided1d-dispatch-factory` PR-URL: https://github.com/stdlib-js/stdlib/pull/7828 Ref: https://github.com/stdlib-js/stdlib/issues/2656 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Co-authored-by: stdlib-bot --- .../README.md | 221 ++++++++++++++++ .../benchmark/benchmark.assign.js | 117 +++++++++ .../benchmark/benchmark.js | 63 +++++ .../docs/repl.txt | 103 ++++++++ .../docs/types/index.d.ts | 231 +++++++++++++++++ .../docs/types/test.ts | 238 ++++++++++++++++++ .../examples/index.js | 68 +++++ .../lib/index.js | 66 +++++ .../lib/main.js | 118 +++++++++ .../package.json | 64 +++++ .../test/test.js | 35 +++ 11 files changed, 1324 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md new file mode 100644 index 000000000000..431f1e58bf28 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md @@ -0,0 +1,221 @@ + + +# nullaryStrided1dDispatchFactory + +> Create a function for applying a strided function to an ndarray. + +
+ +## Usage + + + +```javascript +var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); +``` + +#### nullaryStrided1dDispatchFactory( table, idtypes, odtypes\[, options] ) + +Returns a function for applying a strided function to an ndarray. + + + +```javascript +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + +var table = { + 'default': base +}; + +var dtypes = [ 'float64', 'float32', 'generic' ]; + +var nullary = nullaryStrided1dDispatchFactory( table, [ dtypes ], dtypes ); +``` + +The function has the following parameters: + +- **table**: strided function dispatch table. Must have the following properties: + + - **default**: default strided function which should be invoked when provided ndarrays have data types which do not have a corresponding specialized implementation. + + A dispatch table may have the following additional properties: + + - **types**: one-dimensional list of ndarray data types describing specialized output ndarray argument signatures. Only the output ndarray argument data types should be specified. Additional ndarray argument data types should be omitted and are not considered during dispatch. The length of `types` must equal the number of strided functions specified by `fcns`. + - **fcns**: list of strided functions which are specific to specialized output ndarray argument signatures. + +- **idtypes**: list containing lists of supported input data types for each input ndarray argument. + +- **odtypes**: list of supported output data types. + +- **options**: function options (_optional_). + +The function supports the following options: + +- **strictTraversalOrder**: boolean specifying whether the order of element traversal must match the memory layout order of an output ndarray. Default: `false`. + +#### nullary( out\[, ...args]\[, options] ) + +Applies a strided function and assigns results to a provided output ndarray. + + + +```javascript +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var idt = dtypes( 'real_and_generic' ); +var odt = dtypes( 'all' ); + +var table = { + 'default': base +}; +var nullary = nullaryStrided1dDispatchFactory( table, [ idt ], odt ); + +var xbuf = [ -1.0, 2.0, -3.0 ]; +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +var order = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +var out = nullary( x, order ); +// returns + +var arr = ndarray2array( out ); +// returns [ -3.0, -1.0, 2.0 ] + +var bool = ( out === x ); +// returns true +``` + +The method has the following parameters: + +- **out**: output ndarray. +- **args**: additional input ndarray arguments (_optional_). +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform operation. + +
+ + + +
+ +## Notes + +- A strided function should have the following signature: + + ```text + f( arrays ) + ``` + + where + + - **arrays**: array containing an output ndarray, followed by any additional ndarray arguments. + +
+ + + +
+ +## Examples + + + + + +```javascript +var dsorthp = require( '@stdlib/blas/ext/base/ndarray/dsorthp' ); +var ssorthp = require( '@stdlib/blas/ext/base/ndarray/ssorthp' ); +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + +// Define the supported input and output data types: +var idt = dtypes( 'real_and_generic' ); +var odt = dtypes( 'all' ); + +// Define a dispatch table: +var table = { + 'types': [ + 'float64', // input/output + 'float32' // input/output + ], + 'fcns': [ + dsorthp, + ssorthp + ], + 'default': base +}; + +// Create an interface for performing an operation: +var sorthp = nullaryStrided1dDispatchFactory( table, [ idt ], odt ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var order = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +// Perform operation: +sorthp( x, order ); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..9c8ba48c25dd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var dtypes = require( '@stdlib/array/dtypes' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gsorthp = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var nullary; + var table; + var idt; + var odt; + var x; + var o; + + table = { + 'default': gsorthp + }; + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'all' ); + nullary = factory( table, [ idt ], odt ); + + x = uniform( len, -50.0, 50.0, { + 'dtype': 'float64' + }); + x = new ndarray( 'float64', x, [ len ], [ 1 ], 0, 'row-major' ); + o = new ndarray( 'generic', [ 1 ], [], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = nullary( x, o ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( out.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js new file mode 100644 index 000000000000..d71dd3c3095d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var gsorthp = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::factory', function benchmark( b ) { + var idtypes; + var odtypes; + var table; + var v; + var i; + + table = { + 'default': gsorthp + }; + idtypes = [ + 'float64', + 'float32' + ]; + odtypes = [ + 'float64', + 'float32' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( table, [ idtypes ], odtypes ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt new file mode 100644 index 000000000000..71e2b4c4863a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt @@ -0,0 +1,103 @@ + +{{alias}}( table, idtypes, odtypes[, options] ) + Returns function for applying a strided function to an ndarray. + + Parameters + ---------- + table: Object + Dispatch table containing strided functions. The table object must have + the following property: + + - default: default strided function to invoke when provided ndarrays + have data types which do not have a corresponding specialized + implementation. + + The table may having the following additional properties: + + - types: one-dimensional list of ndarray data types describing + specialized output ndarray argument signatures. + - fcns: list of strided functions which are specific to specialized + output ndarray argument signatures. + + A strided function should have the following signature: + + f( arrays ) + + where + + - arrays: array containing an output ndarray, followed by any additional + ndarray arguments. + + idtypes: Array> + List containing lists of supported input data types for each input + ndarray argument. + + odtypes: Array + List of supported output data types. + + options: Object (optional) + Function options. + + options.strictTraversalOrder: boolean (optional) + Boolean specifying whether the order of element traversal must match the + memory layout order of an output ndarray. + + Returns + ------- + fcn: Function + Function for applying a strided function to ndarrays. + + Examples + -------- + > var idt = [ 'float64', 'float32', 'generic' ]; + > var odt = [ 'float64', 'float32', 'generic' ]; + > var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} }; + > var f = {{alias}}( t, [ idt ], odt ); + +fcn( out[, ...args][, options] ) + Applies a strided function and assign results to a provided output ndarray. + + Parameters + ---------- + out: ndarray + Output array. + + args: ...ndarray (optional) + Additional ndarray arguments. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided output + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var idt = [ 'float64', 'float32', 'generic' ]; + > var odt = [ 'float64', 'float32', 'generic' ]; + > var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} }; + > var f = {{alias}}( t, [ idt ], odt ); + > var buf = [ -1.0, 2.0, -3.0, -4.0 ]; + > var dt = 'generic'; + > var sh = [ buf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, buf, sh, sx, ox, ord ); + > var o = {{alias:@stdlib/ndarray/from-scalar}}( 1.0 ); + > var out = f( x, o ) + + > var bool = ( out === x ) + true + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ -4.0, -3.0, -1.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts new file mode 100644 index 000000000000..0b36d8d7f3a6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts @@ -0,0 +1,231 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform an operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining factory options. +*/ +interface FactoryOptions { + /** + * Boolean specifying whether the order of element traversal must match the memory layout of an output ndarray. + */ + strictTraversalOrder?: boolean; +} + +/** +* Strided function. +* +* @param arrays - input ndarrays +* @param options - function options +* @returns result +*/ +type Nullary = ( arrays: [ typedndarray ], options?: unknown ) => typedndarray; + +/** +* Strided function. +* +* @param arrays - input ndarrays +* @param options - function options +* @returns result +*/ +type NullaryWithAdditionalArrays = ( arrays: [ typedndarray, ...Array> ], options?: unknown ) => typedndarray; + +/** +* Base dispatch table. +*/ +interface BaseDispatchTable { + /** + * Default strided function. + */ + default: Nullary | NullaryWithAdditionalArrays; +} + +/** +* Dispatch table. +*/ +interface DispatchTable extends BaseDispatchTable { + /** + * One-dimensional list of ndarray data types describing specialized output ndarray argument signatures. + */ + types: ArrayLike; + + /** + * List of strided functions which are specific to specialized output ndarray argument signatures. + */ + fcns: ArrayLike | NullaryWithAdditionalArrays>; +} + + +/** +* Interface for applying an operation to an ndarray. +*/ +interface NullaryFunction { + /** + * Applies a strided function and assign results to a provided output ndarray. + * + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + * var dtypes = require( '@stdlib/ndarray/dtypes' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray = require( '@stdlib/ndarray/base/ctor' ); + * + * var idt = dtypes( 'real_and_generic' ); + * var odt = dtypes( 'all' ); + * + * var table = { + * 'default': base + * }; + * var sorthp = factory( table, [ idt ], odt ); + * + * var xbuf = [ -1.0, 2.0, -3.0 ]; + * var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + * + * var order = scalar2ndarray( 1.0, { + * 'dtype': 'generic' + * }); + * + * var out = sorthp( x, order ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -3.0, -1.0, 2.0 ] + * + * var bool = ( out === x ); + * // returns true + */ + = OutputArray>( out: V, options?: BaseOptions ): V; + + /** + * Applies a strided function and assigns results to a provided output ndarray. + * + * @param out - output ndarray + * @param x - additional ndarray argument + * @param args - output ndarray, additional array arguments, and function options + * @returns output ndarray + * + * @example + * var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + * var dtypes = require( '@stdlib/ndarray/dtypes' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray = require( '@stdlib/ndarray/base/ctor' ); + * + * var idt = dtypes( 'real_and_generic' ); + * var odt = dtypes( 'all' ); + * + * var table = { + * 'default': base + * }; + * var sorthp = factory( table, [ idt ], odt ); + * + * var xbuf = [ -1.0, 2.0, -3.0 ]; + * var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + * + * var order = scalar2ndarray( 1.0, { + * 'dtype': 'generic' + * }); + * + * var out = sorthp( x, order ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -3.0, -1.0, 2.0 ] + * + * var bool = ( out === x ); + * // returns true + */ + = OutputArray>( out: V, x: InputArray, ...args: Array ): V; +} + +/** +* Creates a function for applying a strided function to an output ndarray. +* +* @param table - dispatch table +* @param idtypes - list containing lists of supported input data types for each ndarray argument +* @param odtypes - list of supported output data types +* @param options - function options +* @returns function for applying a nullary function +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var idt = dtypes( 'real_and_generic' ); +* var odt = dtypes( 'all' ); +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ idt ], odt ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var order = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp( x, order ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +declare function factory( table: DispatchTable | BaseDispatchTable, idtypes: ArrayLike>, odtypes: ArrayLike, options?: FactoryOptions ): NullaryFunction; + + +// EXPORTS // + +export = factory; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts new file mode 100644 index 000000000000..a3ed9f36b95f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts @@ -0,0 +1,238 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import { DataType } from '@stdlib/types/ndarray'; +import gsorthp = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import factory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + factory( table, [ dtypes ], dtypes ); // $ExpectType NullaryFunction + factory( table, [ dtypes ], dtypes, {} ); // $ExpectType NullaryFunction +} + +// The compiler throws an error if the function is provided a first argument which is not a dispatch table... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + + factory( '5', [ dtypes ], dtypes ); // $ExpectError + factory( 5, [ dtypes ], dtypes ); // $ExpectError + factory( true, [ dtypes ], dtypes ); // $ExpectError + factory( false, [ dtypes ], dtypes ); // $ExpectError + factory( null, [ dtypes ], dtypes ); // $ExpectError + factory( void 0, [ dtypes ], dtypes ); // $ExpectError + factory( 'abc', [ dtypes ], dtypes ); // $ExpectError + factory( {}, [ dtypes ], dtypes ); // $ExpectError + factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes ); // $ExpectError + + factory( '5', [ dtypes ], dtypes, {} ); // $ExpectError + factory( 5, [ dtypes ], dtypes, {} ); // $ExpectError + factory( true, [ dtypes ], dtypes, {} ); // $ExpectError + factory( false, [ dtypes ], dtypes, {} ); // $ExpectError + factory( null, [ dtypes ], dtypes, {} ); // $ExpectError + factory( void 0, [ dtypes ], dtypes, {} ); // $ExpectError + factory( 'abc', [ dtypes ], dtypes, {} ); // $ExpectError + factory( {}, [ dtypes ], dtypes, {} ); // $ExpectError + factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a list of data type lists... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + factory( table, '5', dtypes ); // $ExpectError + factory( table, 5, dtypes ); // $ExpectError + factory( table, true, dtypes ); // $ExpectError + factory( table, false, dtypes ); // $ExpectError + factory( table, null, dtypes ); // $ExpectError + factory( table, void 0, dtypes ); // $ExpectError + factory( table, 'abc', dtypes ); // $ExpectError + factory( table, {}, dtypes ); // $ExpectError + factory( table, ( x: number ): number => x, dtypes ); // $ExpectError + + factory( table, '5', dtypes, {} ); // $ExpectError + factory( table, 5, dtypes, {} ); // $ExpectError + factory( table, true, dtypes, {} ); // $ExpectError + factory( table, false, dtypes, {} ); // $ExpectError + factory( table, null, dtypes, {} ); // $ExpectError + factory( table, void 0, dtypes, {} ); // $ExpectError + factory( table, 'abc', dtypes, {} ); // $ExpectError + factory( table, {}, dtypes, {} ); // $ExpectError + factory( table, ( x: number ): number => x, dtypes, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a list of data types... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + factory( table, [ dtypes ], '5' ); // $ExpectError + factory( table, [ dtypes ], 5 ); // $ExpectError + factory( table, [ dtypes ], true ); // $ExpectError + factory( table, [ dtypes ], false ); // $ExpectError + factory( table, [ dtypes ], null ); // $ExpectError + factory( table, [ dtypes ], void 0 ); // $ExpectError + factory( table, [ dtypes ], 'abc' ); // $ExpectError + factory( table, [ dtypes ], {} ); // $ExpectError + factory( table, [ dtypes ], ( x: number ): number => x ); // $ExpectError + + factory( table, [ dtypes ], '5', {} ); // $ExpectError + factory( table, [ dtypes ], 5, {} ); // $ExpectError + factory( table, [ dtypes ], true, {} ); // $ExpectError + factory( table, [ dtypes ], false, {} ); // $ExpectError + factory( table, [ dtypes ], null, {} ); // $ExpectError + factory( table, [ dtypes ], void 0, {} ); // $ExpectError + factory( table, [ dtypes ], 'abc', {} ); // $ExpectError + factory( table, [ dtypes ], {}, {} ); // $ExpectError + factory( table, [ dtypes ], ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not an object... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + factory( table, [ dtypes ], dtypes, '5' ); // $ExpectError + factory( table, [ dtypes ], dtypes, 5 ); // $ExpectError + factory( table, [ dtypes ], dtypes, true ); // $ExpectError + factory( table, [ dtypes ], dtypes, false ); // $ExpectError + factory( table, [ dtypes ], dtypes, null ); // $ExpectError + factory( table, [ dtypes ], dtypes, 'abc' ); // $ExpectError + factory( table, [ dtypes ], dtypes, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + factory(); // $ExpectError + factory( table ); // $ExpectError + factory( table, [ dtypes ] ); // $ExpectError + factory( table, [ dtypes ], dtypes, {}, {} ); // $ExpectError +} + +// The function returns a function which returns an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const o = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + const f = factory( table, [ dtypes ], dtypes ); + f( x ); // $ExpectType float64ndarray + f( x, o ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the returned function is provided a first argument which is not an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + const f = factory( table, [ dtypes ], dtypes ); + f( '5' ); // $ExpectError + f( 5 ); // $ExpectError + f( true ); // $ExpectError + f( false ); // $ExpectError + f( null ); // $ExpectError + f( void 0 ); // $ExpectError + f( {} ); // $ExpectError + f( ( x: number ): number => x ); // $ExpectError + + f( '5', {} ); // $ExpectError + f( 5, {} ); // $ExpectError + f( true, {} ); // $ExpectError + f( false, {} ); // $ExpectError + f( null, {} ); // $ExpectError + f( void 0, {} ); // $ExpectError + f( {}, {} ); // $ExpectError + f( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an invalid `dims` option... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const o = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + const f = factory( table, [ dtypes ], dtypes ); + f( x, { 'dims': '5' } ); // $ExpectError + f( x, { 'dims': 5 } ); // $ExpectError + f( x, { 'dims': true } ); // $ExpectError + f( x, { 'dims': false } ); // $ExpectError + f( x, { 'dims': null } ); // $ExpectError + f( x, { 'dims': {} } ); // $ExpectError + f( x, { 'dims': ( x: number ): number => x } ); // $ExpectError + + f( x, o, { 'dims': '5' } ); // $ExpectError + f( x, o, { 'dims': 5 } ); // $ExpectError + f( x, o, { 'dims': true } ); // $ExpectError + f( x, o, { 'dims': false } ); // $ExpectError + f( x, o, { 'dims': null } ); // $ExpectError + f( x, o, { 'dims': {} } ); // $ExpectError + f( x, o, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an unsupported number of arguments... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': gsorthp + }; + + const f = factory( table, [ dtypes ], dtypes ); + f(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js new file mode 100644 index 000000000000..740a18102396 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var dsorthp = require( '@stdlib/blas/ext/base/ndarray/dsorthp' ); +var ssorthp = require( '@stdlib/blas/ext/base/ndarray/ssorthp' ); +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var factory = require( './../lib' ); + +// Define the supported input and output data types: +var idt = dtypes( 'real_and_generic' ); +var odt = dtypes( 'all' ); + +// Define a dispatch table: +var table = { + 'types': [ + 'float64', // input/output + 'float32' // input/output + ], + 'fcns': [ + dsorthp, + ssorthp + ], + 'default': base +}; + +// Create an interface for performing an operation: +var sorthp = factory( table, [ idt ], odt ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var order = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +// Perform operation: +sorthp( x, order ); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js new file mode 100644 index 000000000000..5d3d3f363b7a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Create a function for applying a strided function to a provided ndarray. +* +* @module @stdlib/ndarray/base/nullary-strided1d-dispatch-factory +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); +* +* var idt = dtypes( 'real_and_generic' ); +* var odt = dtypes( 'all' ); +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ idt ], odt ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var order = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp( x, order ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js new file mode 100644 index 000000000000..ecf3c77fa7de --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var NullaryStrided1dDispatch = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch' ); + + +// MAIN // + +/** +* Returns a function for applying a strided function to a provided ndarray. +* +* @param {Object} table - dispatch table +* @param {Function} table.default - default strided function +* @param {StringArray} [table.types] - one-dimensional list of ndarray data types describing specialized output ndarray argument signatures +* @param {ArrayLikeObject} [table.fcns] - list of strided functions which are specific to specialized output ndarray argument signatures +* @param {ArrayLikeObject} idtypes - list containing lists of supported input data types for each ndarray argument +* @param {StringArray} odtypes - list of supported output data types +* @param {Options} [options] - function options +* @param {boolean} [options.strictTraversalOrder=false] - boolean specifying whether to require that element traversal match the memory layout of an output ndarray +* @throws {TypeError} first argument must be an object having valid properties +* @throws {Error} first argument must be an object having valid properties +* @throws {TypeError} second argument must be an array containing arrays of supported data types +* @throws {TypeError} third argument must be an array of supported data types +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {Function} function for applying a strided function an ndarray +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var idt = dtypes( 'real_and_generic' ); +* var odt = dtypes( 'all' ); +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ idt ], odt ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var o = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp( x, o ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +function factory( table, idtypes, odtypes, options ) { + var f; + if ( arguments.length > 3 ) { + f = new NullaryStrided1dDispatch( table, idtypes, odtypes, options ); + } else { + f = new NullaryStrided1dDispatch( table, idtypes, odtypes ); + } + return assign; + + /** + * Applies a strided function and assigns results to a provided output ndarray. + * + * @private + * @param {ndarrayLike} out - output ndarray + * @param {...ndarrayLike} [args] - additional ndarray arguments + * @param {Options} [options] - function options + * @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation + * @throws {TypeError} first argument must be an ndarray + * @throws {TypeError} first argument must have a supported data type + * @throws {TypeError} options argument must be an object + * @throws {RangeError} dimension indices must not exceed input ndarray bounds + * @throws {RangeError} number of dimension indices must not exceed the number of output ndarray dimensions + * @throws {Error} must provide valid options + * @returns {ndarrayLike} output ndarray + */ + function assign() { + var args; + var i; + + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return f.assign.apply( f, args ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json new file mode 100644 index 000000000000..565036eddc99 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/nullary-strided1d-dispatch-factory", + "version": "0.0.0", + "description": "Create a function for applying a strided function to a provided ndarray.", + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "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", + "factory", + "function", + "func", + "fcn", + "ndarray", + "strided", + "vector", + "array", + "apply", + "call" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js new file mode 100644 index 000000000000..6a51e9ffda63 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var factory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +// FIXME: add tests From 66605d64a64a00d8343cb41d5d570d52be66294d Mon Sep 17 00:00:00 2001 From: Seth-Banker <125103042+Seth-Banker@users.noreply.github.com> Date: Wed, 17 Sep 2025 02:55:52 -0700 Subject: [PATCH 08/17] chore: fix JavaScript lint errors PR-URL: https://github.com/stdlib-js/stdlib/pull/8090 Closes: https://github.com/stdlib-js/stdlib/issues/8088 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../_tools/scripts/publish_packages.js | 20 +++++++++---------- .../assert/is-integer-array/examples/index.js | 2 -- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/_tools/scripts/publish_packages.js b/lib/node_modules/@stdlib/_tools/scripts/publish_packages.js index 12b988e07558..201e6116f1a7 100644 --- a/lib/node_modules/@stdlib/_tools/scripts/publish_packages.js +++ b/lib/node_modules/@stdlib/_tools/scripts/publish_packages.js @@ -606,6 +606,16 @@ function onTopics( error, data, info ) { console.log( 'Rate limit: '+JSON.stringify( info ) ); } +/** +* Adds executable permission to `bin/cli` files. +* +* @private +* @param {Object} git - `git` class instance +*/ +function updatePermissions( git ) { + shell( 'find '+git.cwd+' -regex \'.*/bin/cli\' -print0 | xargs -r -0 chmod +x' ); +} + /** * Publishes a package to the respective GitHub repository. * @@ -1295,16 +1305,6 @@ function publish( pkg, clbk ) { invokeCallback(); } - /** - * Adds executable permission to `bin/cli` files. - * - * @private - * @param {Object} git - `git` class instance - */ - function updatePermissions( git ) { - shell( 'find '+git.cwd+' -regex \'.*/bin/cli\' -print0 | xargs -r -0 chmod +x' ); - } - /** * Replacer function for inserting an install section before a usage section. * diff --git a/lib/node_modules/@stdlib/assert/is-integer-array/examples/index.js b/lib/node_modules/@stdlib/assert/is-integer-array/examples/index.js index b7a20a29366f..83b08a076e3b 100644 --- a/lib/node_modules/@stdlib/assert/is-integer-array/examples/index.js +++ b/lib/node_modules/@stdlib/assert/is-integer-array/examples/index.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable no-new-wrappers */ - 'use strict'; var Number = require( '@stdlib/number/ctor' ); From 0ed631d96dae3b796882c441f79505275afbc4c0 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 17 Sep 2025 15:08:44 +0500 Subject: [PATCH 09/17] feat: add `dtype` option support in `ndarray/flatten` PR-URL: https://github.com/stdlib-js/stdlib/pull/8091 Closes: https://github.com/stdlib-js/metr-issue-tracker/issues/79 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/ndarray/flatten/README.md | 26 +++++++++++++++ .../@stdlib/ndarray/flatten/docs/repl.txt | 4 +++ .../ndarray/flatten/docs/types/index.d.ts | 11 ++++++- .../ndarray/flatten/docs/types/test.ts | 24 ++++++++++++++ .../@stdlib/ndarray/flatten/lib/main.js | 15 ++++++--- .../@stdlib/ndarray/flatten/test/test.js | 33 +++++++++++++++++++ 6 files changed, 108 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/flatten/README.md b/lib/node_modules/@stdlib/ndarray/flatten/README.md index 156801cd8799..b956b26039e0 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/README.md +++ b/lib/node_modules/@stdlib/ndarray/flatten/README.md @@ -72,6 +72,8 @@ The function accepts the following options: - **depth**: maximum number of input [ndarray][@stdlib/ndarray/ctor] dimensions to flatten. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/ctor]. + By default, the function flattens all dimensions of the input [ndarray][@stdlib/ndarray/ctor]. To flatten to a desired depth, specify the `depth` option. ```javascript @@ -108,6 +110,28 @@ var arr = ndarray2array( y ); // returns [ 1.0, 3.0, 5.0, 2.0, 4.0, 6.0 ] ``` +By default, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. To return an ndarray with a different [data type][@stdlib/ndarray/dtypes], specify the `dtype` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var y = flatten( x, { + 'dtype': 'float32' +}); +// returns + +var dt = dtype( y ); +// returns 'float32' + +var arr = ndarray2array( y ); +// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +``` + @@ -164,6 +188,8 @@ console.log( ndarray2array( y ) ); [@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes + [@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders diff --git a/lib/node_modules/@stdlib/ndarray/flatten/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/flatten/docs/repl.txt index 4e2e4208667e..c9647f66f732 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/flatten/docs/repl.txt @@ -29,6 +29,10 @@ Default: 'row-major'. + options.dtype: string (optional) + Output ndarray data type. By default, the function returns an ndarray + having the same data type as the provided input ndarray. + Returns ------- out: ndarray diff --git a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts index e993af9cd32d..788645b37e08 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { ndarray, Order } from '@stdlib/types/ndarray'; +import { ndarray, Order, DataType } from '@stdlib/types/ndarray'; /** * Interface defining function options. @@ -50,6 +50,15 @@ interface Options { * - Default: 'row-major'. */ order?: Order | 'same' | 'any'; + + /** + * Output ndarray data type. + * + * ## Notes + * + * - By default, the function returns an ndarray having the same data type as a provided input ndarray. + */ + dtype?: DataType; } /** diff --git a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts index bc9d1cf920bc..3c6b702eeb74 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts @@ -128,6 +128,30 @@ import flatten = require( './index' ); flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'order': ( x: number ): number => x } ); // $ExpectError } +// The compiler throws an error if the function is provided a second argument with invalid `dtype` option... +{ + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': '5' } ); // $ExpectError + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': true } ); // $ExpectError + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': false } ); // $ExpectError + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': null } ); // $ExpectError + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': [ 1 ] } ); // $ExpectError + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': ( x: number ): number => x } ); // $ExpectError + + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': '5' } ); // $ExpectError + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': true } ); // $ExpectError + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': false } ); // $ExpectError + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': null } ); // $ExpectError + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': [ 1 ] } ); // $ExpectError + flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), { 'dtype': ( x: number ): number => x } ); // $ExpectError + + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': '5' } ); // $ExpectError + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': true } ); // $ExpectError + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': false } ); // $ExpectError + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': null } ); // $ExpectError + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': [ 1 ] } ); // $ExpectError + flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( 'float64', [ 2, 2, 2 ], 'row-major' ); diff --git a/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js b/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js index 9b728c85dc72..53a5f2436d51 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/flatten/lib/main.js @@ -54,6 +54,7 @@ var COL_MAJOR = 'column-major'; * @param {Options} [options] - function options * @param {NonNegativeInteger} [options.depth] - maximum number of dimensions to flatten * @param {string} [options.order='row-major'] - order in which input ndarray elements should be flattened +* @param {*} [options.dtype] - output ndarray data type * @throws {TypeError} first argument must be an ndarray-like object * @throws {TypeError} options argument must be an object * @throws {TypeError} must provide valid options @@ -296,8 +297,9 @@ function flatten( x, options ) { // Define default options: opts = { - 'depth': xsh.length, // by default, flatten to a one-dimensional ndarray - 'order': ROW_MAJOR // by default, flatten in lexicographic order (i.e., trailing dimensions first; e.g., if `x` is a matrix, flatten row-by-row) + 'depth': xsh.length, // by default, flatten to a one-dimensional ndarray + 'order': ROW_MAJOR, // by default, flatten in lexicographic order (i.e., trailing dimensions first; e.g., if `x` is a matrix, flatten row-by-row) + 'dtype': getDType( x ) }; // Resolve function options... @@ -335,16 +337,21 @@ function flatten( x, options ) { throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); } } + if ( hasOwnProp( options, 'dtype' ) ) { + // Delegate `dtype` validation to `emptyLike` during output array creation: + opts.dtype = options.dtype; + } } // Create an output ndarray having contiguous memory: y = emptyLike( x, { 'shape': flattenShape( xsh, opts.depth ), - 'order': opts.order + 'order': opts.order, + 'dtype': opts.dtype }); // Create a view on top of output ndarray having the same shape as the input ndarray: st = ( xsh.length > 0 ) ? shape2strides( xsh, opts.order ) : [ 0 ]; - view = ndarray( getDType( y ), getData( y ), xsh, st, 0, opts.order ); + view = ndarray( opts.dtype, getData( y ), xsh, st, 0, opts.order ); // Copy elements to the output ndarray: assign( [ x, view ] ); diff --git a/lib/node_modules/@stdlib/ndarray/flatten/test/test.js b/lib/node_modules/@stdlib/ndarray/flatten/test/test.js index 02a079145248..2a4331d84ade 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/flatten/test/test.js @@ -191,6 +191,39 @@ tape( 'the function throws an error if provided an invalid `order` option', func } }); +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 1, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+ values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts = { + 'dtype': value + }; + flatten( zeros( [ 2 ] ), opts ); + }; + } +}); + tape( 'by default, the function flattens all dimensions of a provided input ndarray in lexicographic order (row-major, contiguous)', function test( t ) { var expected; var xbuf; From 6d742438beb8e7fe0de4ecfbc82083da16a0a83c Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 13:38:44 -0700 Subject: [PATCH 10/17] fix: ensure correct type when providing a `dtype` option --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ndarray/flatten/docs/types/index.d.ts | 52 +++++++++++++++---- .../ndarray/flatten/docs/types/test.ts | 4 ++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts index 788645b37e08..88a156accc9e 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/index.d.ts @@ -20,12 +20,12 @@ /// -import { ndarray, Order, DataType } from '@stdlib/types/ndarray'; +import { ndarray, typedndarray, Order, DataTypeMap } from '@stdlib/types/ndarray'; /** -* Interface defining function options. +* Interface defining "base" function options. */ -interface Options { +interface BaseOptions { /** * Maximum number of dimensions to flatten. * @@ -50,16 +50,47 @@ interface Options { * - Default: 'row-major'. */ order?: Order | 'same' | 'any'; +} +/** +* Function options. +*/ +type Options = BaseOptions & { /** * Output ndarray data type. - * - * ## Notes - * - * - By default, the function returns an ndarray having the same data type as a provided input ndarray. */ - dtype?: DataType; -} + dtype: U; +}; + +/** +* Returns a flattened copy of an input ndarray. +* +* ## Notes +* +* - The function **always** returns a copy of input ndarray data, even when an input ndarray already has the desired number of dimensions. +* - By default, the function returns an ndarray having the same data type as a provided input ndarray. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param options.dtype - output ndarray data type +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +* // return +* +* var y = flatten( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] +*/ +declare function flatten( x: T, options?: BaseOptions ): T; /** * Returns a flattened copy of an input ndarray. @@ -72,6 +103,7 @@ interface Options { * @param options - function options * @param options.depth - maximum number of dimensions to flatten * @param options.order - order in which input ndarray elements should be flattened +* @param options.dtype - output ndarray data type * @returns output ndarray * * @example @@ -87,7 +119,7 @@ interface Options { * var arr = ndarray2array( y ); * // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] */ -declare function flatten( x: T, options?: Options ): T; +declare function flatten = 'generic'>( x: typedndarray, options: Options ): DataTypeMap[U]; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts index 3c6b702eeb74..e580ce354514 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten/docs/types/test.ts @@ -31,6 +31,10 @@ import flatten = require( './index' ); flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType float64ndarray flatten( zeros( 'complex128', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType complex128ndarray flatten( zeros( 'generic', [ 2, 2, 2 ], 'row-major' ), {} ); // $ExpectType genericndarray + + flatten( zeros( 'float64', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'float32' } ); // $ExpectType float32ndarray + flatten( zeros( 'int32', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'float64' } ); // $ExpectType float64ndarray + flatten( zeros( 'int32', [ 2, 2, 2 ], 'row-major' ), { 'dtype': 'generic' } ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray-like object... From 5b5daeec126b0807718af14a2875cbacc4bd63bf Mon Sep 17 00:00:00 2001 From: Shaswata Panda <106397517+shaswata-26@users.noreply.github.com> Date: Thu, 18 Sep 2025 02:09:54 +0530 Subject: [PATCH 11/17] chore: address EditorConfig lint errors PR-URL: https://github.com/stdlib-js/stdlib/pull/8093 Closes: https://github.com/stdlib-js/stdlib/issues/8087 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- lib/node_modules/@stdlib/math/base/special/beta/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/beta/manifest.json b/lib/node_modules/@stdlib/math/base/special/beta/manifest.json index 8b5db7c71a43..64b2a1183de5 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/beta/manifest.json @@ -58,7 +58,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs", "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/log1p", @@ -79,7 +79,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/special/abs", + "@stdlib/math/base/special/abs", "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/log1p", From 9b660ceda07c2d62d1faccfe619da11579f631c6 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 13:46:03 -0700 Subject: [PATCH 12/17] test: add `dtype` test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/flatten/test/test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/flatten/test/test.js b/lib/node_modules/@stdlib/ndarray/flatten/test/test.js index 2a4331d84ade..d6e7e3fc86b2 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/flatten/test/test.js @@ -24,9 +24,11 @@ var tape = require( 'tape' ); var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); var getOrder = require( '@stdlib/ndarray/order' ); @@ -1391,3 +1393,50 @@ tape( 'the function supports flattening a one-dimensional input ndarray (order=a t.end(); }); + +tape( 'the function supports specifying the output ndarray data type', function test( t ) { + var expected; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + y = flatten( x, { + 'dtype': 'float32' + }); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), 'float32', 'returns expected value' ); + t.strictEqual( getOrder( y ), ord, 'returns expected value' ); + + t.end(); +}); From 6fe6a7362f3e6cc18790ee1c4f7388cbce187cb3 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 18 Sep 2025 02:07:02 +0500 Subject: [PATCH 13/17] feat: add `dtype` option support in `ndarray/flatten-by` PR-URL: https://github.com/stdlib-js/stdlib/pull/8094 Closes: https://github.com/stdlib-js/metr-issue-tracker/issues/80 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/ndarray/flatten-by/README.md | 31 +++++++ .../@stdlib/ndarray/flatten-by/docs/repl.txt | 4 + .../ndarray/flatten-by/docs/types/index.d.ts | 69 +++++++++++++-- .../ndarray/flatten-by/docs/types/test.ts | 22 +++++ .../@stdlib/ndarray/flatten-by/lib/main.js | 15 +++- .../@stdlib/ndarray/flatten-by/test/test.js | 84 +++++++++++++++++++ 6 files changed, 214 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/README.md b/lib/node_modules/@stdlib/ndarray/flatten-by/README.md index f4121b083525..09e2f751e4e3 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/README.md @@ -78,6 +78,8 @@ The function accepts the following options: - **depth**: maximum number of input [ndarray][@stdlib/ndarray/ctor] dimensions to flatten. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [data type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/ctor]. + By default, the function flattens all dimensions of the input [ndarray][@stdlib/ndarray/ctor]. To flatten to a desired depth, specify the `depth` option. ```javascript @@ -126,6 +128,33 @@ var arr = ndarray2array( y ); // returns [ 2.0, 6.0, 10.0, 4.0, 8.0, 12.0 ] ``` +By default, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. To return an ndarray with a different [data type][@stdlib/ndarray/dtypes], specify the `dtype` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function scale( value ) { + return value * 2.0; +} + +var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] ); +// returns + +var opts = { + 'dtype': 'float32' +}; +var y = flattenBy( x, opts, scale ); +// returns + +var dt = dtype( y ); +// returns 'float32' + +var arr = ndarray2array( y ); +// returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +``` + To set the callback function execution context, provide a `thisArg`. @@ -224,6 +253,8 @@ console.log( ndarray2array( y ) ); [@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes + [@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt index f6cae4264419..00c968f90a31 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/repl.txt @@ -26,6 +26,10 @@ Default: 'row-major'. + options.dtype: string (optional) + Output ndarray data type. By default, the function returns an ndarray + having the same data type as the provided input ndarray. + fcn: Function Callback function. diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts index a97d0924d204..d51cb80a8c3e 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { typedndarray, genericndarray, Order } from '@stdlib/types/ndarray'; +import { typedndarray, genericndarray, Order, DataTypeMap } from '@stdlib/types/ndarray'; import { ComplexLike } from '@stdlib/types/complex'; /** @@ -68,9 +68,9 @@ type Ternary = ( this: ThisArg, value: T, indices: Array = Nullary | Unary | Binary | Ternary; /** -* Interface defining function options. +* Interface defining "base" function options. */ -interface Options { +interface BaseOptions { /** * Maximum number of dimensions to flatten. * @@ -97,6 +97,16 @@ interface Options { order?: Order | 'same' | 'any'; } +/** +* Function options. +*/ +type Options = BaseOptions & { + /** + * Output ndarray data type. + */ + dtype: U; +}; + /** * Flattens an ndarray according to a callback function. * @@ -232,6 +242,7 @@ declare function flattenBy = genericnda * @param options - function options * @param options.depth - maximum number of dimensions to flatten * @param options.order - order in which input ndarray elements should be flattened +* @param options.dtype - output ndarray data type * @param fcn - callback function * @param thisArg - callback execution context * @returns output ndarray @@ -263,7 +274,7 @@ declare function flattenBy = genericnda * var arr = ndarray2array( y ); * // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] */ -declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): T; +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: BaseOptions, fcn: Callback, thisArg?: ThisParameterType> ): T; /** * Flattens an ndarray according to a callback function. @@ -272,6 +283,7 @@ declare function flattenBy = typedndarray * @param options - function options * @param options.depth - maximum number of dimensions to flatten * @param options.order - order in which input ndarray elements should be flattened +* @param options.dtype - output ndarray data type * @param fcn - callback function * @param thisArg - callback execution context * @returns output ndarray @@ -300,7 +312,7 @@ declare function flattenBy = typedndarray * var y = flattenBy( x, opts, identity ); * // returns */ -declare function flattenBy = typedndarray, ThisArg = unknown>( x: U, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): U; +declare function flattenBy = typedndarray, ThisArg = unknown>( x: U, options: BaseOptions, fcn: Callback, thisArg?: ThisParameterType> ): U; /** * Flattens an ndarray according to a callback function. @@ -309,6 +321,7 @@ declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): T; +declare function flattenBy = typedndarray, ThisArg = unknown>( x: T, options: BaseOptions, fcn: Callback, thisArg?: ThisParameterType> ): T; /** * Flattens an ndarray according to a callback function. @@ -349,6 +362,7 @@ declare function flattenBy = typedndarray = typedndarray = genericndarray, V = unknown, W extends genericndarray = genericndarray, ThisArg = unknown>( x: U, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): W; +declare function flattenBy = genericndarray, V = unknown, W extends genericndarray = genericndarray, ThisArg = unknown>( x: U, options: BaseOptions, fcn: Callback, thisArg?: ThisParameterType> ): W; + +/** +* Flattens an ndarray according to a callback function. +* +* @param x - input ndarray +* @param options - function options +* @param options.depth - maximum number of dimensions to flatten +* @param options.order - order in which input ndarray elements should be flattened +* @param options.dtype - output ndarray data type +* @param fcn - callback function +* @param thisArg - callback execution context +* @returns output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function scale( value ) { +* return value * 2.0; +* } +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var shape = [ 3, 1, 2 ]; +* var strides = [ 2, 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // return +* +* var opts = { +* 'depth': 2 +* }; +* +* var y = flattenBy( x, opts, scale ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] +*/ +declare function flattenBy | genericndarray = typedndarray, V = unknown, W extends keyof DataTypeMap = 'generic', ThisArg = unknown>( x: U, options: Options, fcn: Callback, thisArg?: ThisParameterType> ): DataTypeMap[W]; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts index d0eec5992d8c..0cd9cbe320e1 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/docs/types/test.ts @@ -86,6 +86,11 @@ function identity( x: any ): any { flattenBy( zeros( 'generic', sh, ord ), {}, identity ); // $ExpectType genericndarray flattenBy( zeros( 'generic', sh, ord ), identity, {} ); // $ExpectType genericndarray flattenBy( zeros( 'generic', sh, ord ), {}, identity, {} ); // $ExpectType genericndarray + + flattenBy( zeros( 'float64', sh, ord ), { 'dtype': 'float32' }, identity ); // $ExpectType float32ndarray + flattenBy( zeros( 'float64', sh, ord ), { 'dtype': 'generic' }, identity ); // $ExpectType genericndarray + flattenBy( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, identity ); // $ExpectType float64ndarray + flattenBy( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, identity ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... @@ -178,6 +183,23 @@ function identity( x: any ): any { flattenBy( x, { 'order': [ 1 ] }, identity, {} ); // $ExpectError } +// The compiler throws an error if the function is provided a second argument with invalid `dtype` option... +{ + const x = zeros( 'generic', [ 2, 2, 2 ], 'row-major' ); + + flattenBy( x, { 'dtype': '5' }, identity ); // $ExpectError + flattenBy( x, { 'dtype': true }, identity ); // $ExpectError + flattenBy( x, { 'dtype': false }, identity ); // $ExpectError + flattenBy( x, { 'dtype': null }, identity ); // $ExpectError + flattenBy( x, { 'dtype': [ 1 ] }, identity ); // $ExpectError + + flattenBy( x, { 'dtype': '5' }, identity, {} ); // $ExpectError + flattenBy( x, { 'dtype': true }, identity, {} ); // $ExpectError + flattenBy( x, { 'dtype': false }, identity, {} ); // $ExpectError + flattenBy( x, { 'dtype': null }, identity, {} ); // $ExpectError + flattenBy( x, { 'dtype': [ 1 ] }, identity, {} ); // $ExpectError +} + // The compiler throws an error if the function is provided a callback which is not a function... { const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js index b06674f4df5a..32d65e55c5db 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/lib/main.js @@ -55,6 +55,7 @@ var COL_MAJOR = 'column-major'; * @param {Options} [options] - function options * @param {NonNegativeInteger} [options.depth] - maximum number of dimensions to flatten * @param {string} [options.order='row-major'] - order in which input ndarray elements should be flattened +* @param {*} [options.dtype] - output ndarray data type * @param {Function} fcn - callback function * @param {*} [thisArg] - callback execution context * @throws {TypeError} first argument must be an ndarray-like object @@ -101,8 +102,9 @@ function flattenBy( x, options, fcn, thisArg ) { // Define default options: opts = { - 'depth': xsh.length, // by default, flatten to a one-dimensional ndarray - 'order': ROW_MAJOR // by default, flatten in lexicographic order (i.e., trailing dimensions first; e.g., if `x` is a matrix, flatten row-by-row) + 'depth': xsh.length, // by default, flatten to a one-dimensional ndarray + 'order': ROW_MAJOR, // by default, flatten in lexicographic order (i.e., trailing dimensions first; e.g., if `x` is a matrix, flatten row-by-row) + 'dtype': getDType( x ) }; // Case: flattenBy( x, fcn ) @@ -165,16 +167,21 @@ function flattenBy( x, options, fcn, thisArg ) { throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); } } + if ( hasOwnProp( options, 'dtype' ) ) { + // Delegate `dtype` validation to `emptyLike` during output array creation: + opts.dtype = options.dtype; + } } // Create an output ndarray having contiguous memory: y = emptyLike( x, { 'shape': flattenShape( xsh, opts.depth ), - 'order': opts.order + 'order': opts.order, + 'dtype': opts.dtype }); // Create a view on top of output ndarray having the same shape as the input ndarray: st = ( xsh.length > 0 ) ? shape2strides( xsh, opts.order ) : [ 0 ]; - view = ndarray( getDType( y ), getData( y ), xsh, st, 0, opts.order ); + view = ndarray( opts.dtype, getData( y ), xsh, st, 0, opts.order ); // Transform and assign elements to the output ndarray: map( [ x, view ], cb, ctx ); diff --git a/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js b/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js index 9b306deb95f9..8fd480e43237 100644 --- a/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/flatten-by/test/test.js @@ -24,9 +24,11 @@ var tape = require( 'tape' ); var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); var zeros = require( '@stdlib/ndarray/zeros' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); var identity = require( '@stdlib/number/float64/base/identity' ); var getDType = require( '@stdlib/ndarray/dtype' ); var getShape = require( '@stdlib/ndarray/shape' ); @@ -272,6 +274,39 @@ tape( 'the function throws an error if provided an invalid `order` option', func } }); +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 1, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+ values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts = { + 'dtype': value + }; + flattenBy( zeros( [ 2 ] ), opts, identity ); + }; + } +}); + tape( 'the function throws an error if provided a callback argument which is not a function', function test( t ) { var values; var i; @@ -1534,6 +1569,55 @@ tape( 'the function supports flattening a one-dimensional input ndarray (order=a t.end(); }); +tape( 'the function supports specifying the output ndarray data type', function test( t ) { + var expected; + var xbuf; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + /* + * [ + * [ + * [ 1.0, 2.0 ], + * [ 3.0, 4.0 ] + * ], + * [ + * [ 5.0, 6.0 ], + * [ 7.0, 8.0 ] + * ] + * ] + */ + xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + x = new ndarray( dt, xbuf, sh, st, o, ord ); + + opts = { + 'dtype': 'float32' + }; + y = flattenBy( x, opts, identity ); + expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + + t.notEqual( y, x, 'returns expected value' ); + t.notEqual( getData( y ), xbuf, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( getData( y ), expected ), true, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 8 ], 'returns expected value' ); + t.strictEqual( getDType( y ), 'float32', 'returns expected value' ); + t.strictEqual( getOrder( y ), ord, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports specifying the callback execution context (row-major)', function test( t ) { var expected; var indices; From 9629e2ee35e901567a51fcd79e2c13156ed46053 Mon Sep 17 00:00:00 2001 From: Gauravkaushik-1206 <144526331+Gauravkaushik-1206@users.noreply.github.com> Date: Thu, 18 Sep 2025 03:05:28 +0530 Subject: [PATCH 14/17] test: add tests for `slice` method in `dstructs/named-typed-tuple` PR-URL: https://github.com/stdlib-js/stdlib/pull/8057 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../named-typed-tuple/test/test.slice.js | 382 ++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js new file mode 100644 index 000000000000..0fefa6d4925d --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js @@ -0,0 +1,382 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypedtuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `slice` method', function test( t ) { + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y' ], { + 'name': 'Point' + }); + p = new Point( [ 10, 20 ] ); + + t.strictEqual( hasOwnProp( p, 'slice' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.slice ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice.call( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice.call( value, 0 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance (start, end)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice.call( value, 0, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice( value ); + }; + } +}); + +tape( 'the method throws an error if provided a first argument which is not an integer (end)', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice( value, 1 ); + }; + } +}); + +tape( 'the method throws an error if provided a second argument which is not an integer', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.slice( 0, value ); + }; + } +}); + +tape( 'if called without arguments, the method returns a tuple containing the same elements as the original tuple', function test( t ) { + var expected; + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 10, 20, 30 ] ); + + expected = { + 'x': 10, + 'y': 20, + 'z': 30 + }; + actual = p.slice(); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'x', 'y', 'z' ], 'returns expected value' ); + + actual = { + 'x': actual.x, + 'y': actual.y, + 'z': actual.z + }; + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided one argument, the method returns a tuple containing elements starting from a specified index (inclusive)', function test( t ) { + var expected; + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + expected = [ 2, 3, 4 ]; + actual = p.slice( 1 ); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'y', 'z', 'w' ], 'returns expected value' ); + t.end(); +}); + +tape( 'if provided two arguments, the method returns a tuple containing elements starting from a specified start index (inclusive) and ending at a specified end index (exclusive)', function test( t ) { + var expected; + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + expected = [ 2, 3 ]; + actual = p.slice( 1, 3 ); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'y', 'z' ], 'returns expected value' ); + + expected = [ 2, 3, 4 ]; + actual = p.slice( 1, 30 ); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'y', 'z', 'w' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports negative indices', function test( t ) { + var expected; + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + expected = [ 2, 3 ]; + actual = p.slice( -3, -1 ); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'y', 'z' ], 'returns expected value' ); + + expected = [ 1, 2 ]; + actual = p.slice( -30, -2 ); + + t.notEqual( actual, p, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.deepEqual( actual.fields, [ 'x', 'y' ], 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns null if a resolved beginning index exceeds a resolved ending index', function test( t ) { + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + actual = p.slice( 2, 0 ); + + t.strictEqual( actual, null, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns null if a resolved beginning index exceeds the maximum tuple index', function test( t ) { + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + actual = p.slice( 5 ); + + t.strictEqual( actual, null, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns null if a resolved ending index is less than or equal to zero', function test( t ) { + var actual; + var Point; + var p; + + Point = namedtypedtuple( [ 'x', 'y', 'z', 'w' ] ); + p = new Point( [ 1, 2, 3, 4 ] ); + + actual = p.slice( 2, -8 ); + t.strictEqual( actual, null, 'returns expected value' ); + + actual = p.slice( 1, 0 ); + t.strictEqual( actual, null, 'returns expected value' ); + t.end(); +}); From 05cf2e6e36c42b9db322e14f5bc78adf4d3901f9 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 14:53:40 -0700 Subject: [PATCH 15/17] feat: add support for returning empty tuples --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dstructs/named-typed-tuple/README.md | 21 +++++++-- .../dstructs/named-typed-tuple/docs/repl.txt | 8 ++-- .../dstructs/named-typed-tuple/lib/main.js | 44 +++++++------------ .../named-typed-tuple/test/test.slice.js | 18 +++++--- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/README.md b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/README.md index bcc8f10c9745..96551c05649c 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/README.md +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/README.md @@ -1798,6 +1798,19 @@ var y = p2.y; // returns 0.0 ``` +If the method is unable to resolve indices to a non-empty tuple subsequence, the method returns an empty tuple. + +```javascript +var factory = namedtypedtuple( [ 'x', 'y', 'z' ] ); + +var p1 = factory( [ 1.0, 0.0, -1.0 ] ); + +var p2 = p1.slice( 10, -1 ); + +var len = p2.length; +// returns 0 +``` + #### tuple.some( predicate\[, thisArg] ) @@ -2074,7 +2087,7 @@ var y = p2.y; // returns 0.0 ``` -If the method is unable to resolve indices to a non-empty tuple subsequence, the method returns `null`. +If the method is unable to resolve indices to a non-empty tuple subsequence, the method returns an empty tuple. ```javascript var factory = namedtypedtuple( [ 'x', 'y', 'z' ] ); @@ -2082,7 +2095,9 @@ var factory = namedtypedtuple( [ 'x', 'y', 'z' ] ); var p1 = factory( [ 1.0, 0.0, -1.0 ] ); var p2 = p1.subtuple( 10, -1 ); -// returns null + +var len = p2.length; +// returns 0 ``` @@ -2112,7 +2127,7 @@ var factory = namedtypedtuple( [ 'x', 'y', 'z' ] ); var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' ); var str = tuple.toLocaleString(); -// returns '1,0,-1' +// returns 'tuple(x=1, y=0, z=-1)' ``` diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/repl.txt b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/repl.txt index a90b664fec7e..c99f34eabc90 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/repl.txt +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/docs/repl.txt @@ -1144,7 +1144,7 @@ tuple.slice( [begin[, end]] ) the host tuple. If the method is unable to resolve indices to a non-empty tuple subsequence, - the method returns `null`. + the method returns an empty typed array. Parameters ---------- @@ -1303,8 +1303,8 @@ tuple.subtuple( [begin[, end]] ) Creates a new named typed tuple over the same underlying ArrayBuffer and with the same underlying data type as the host tuple. - If the function is unable to resolve indices to a non-empty tuple - subsequence, the function returns `null`. + If the method is unable to resolve indices to a non-empty tuple subsequence, + the method returns an empty typed array. Parameters ---------- @@ -1318,7 +1318,7 @@ tuple.subtuple( [begin[, end]] ) Returns ------- - tuple: TypedArray|null + tuple: TypedArray A new named typed tuple. Examples diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/lib/main.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/lib/main.js index be0afce7cd01..f454d5ecf975 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/lib/main.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/lib/main.js @@ -23,6 +23,7 @@ // MODULES // var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isArrayBuffer = require( '@stdlib/assert/is-arraybuffer' ); var isFunction = require( '@stdlib/assert/is-function' ); @@ -95,7 +96,7 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi var opts; var err; var i; - if ( !isStringArray( names ) ) { + if ( !isStringArray( names ) && !isEmptyArrayLikeObject( names ) ) { throw new TypeError( format( 'invalid argument. Must provide an array of strings. Value: `%s`.', names ) ); } if ( !hasDistinctElements( names ) ) { @@ -251,17 +252,6 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi } } - /** - * Returns the list of tuple fields. - * - * @private - * @memberof tuple - * @returns {StringArray} tuple fields - */ - function getFields() { - return fields.slice(); - } - /** * Returns the list of tuple fields in index order. * @@ -943,10 +933,6 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi /** * Copies elements to a new tuple with the same underlying data type as the host tuple. * - * ## Notes - * - * - If the function is unable to resolve indices to a non-empty tuple subsequence, the function returns `null`. - * * @private * @memberof tuple * @param {integer} [begin=0] - start element index (inclusive) @@ -954,7 +940,7 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi * @throws {TypeError} `this` must be the host tuple * @throws {TypeError} first argument must be an integer * @throws {TypeError} second argument must be an integer - * @returns {(TypedArray|null)} new tuple + * @returns {TypedArray} new tuple */ function slice( begin, end ) { var tmp; @@ -994,9 +980,6 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi j = nfields; } } - if ( i >= j ) { - return null; - } f = []; tmp = []; for ( ; i < j; i++ ) { @@ -1117,10 +1100,6 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi /** * Creates a new tuple over the same underlying `ArrayBuffer` and with the same underlying data type as the host tuple. * - * ## Notes - * - * - If the function is unable to resolve indices to a non-empty tuple subsequence, the function returns `null`. - * * @private * @memberof tuple * @param {integer} [begin=0] - start element index (inclusive) @@ -1128,7 +1107,7 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi * @throws {TypeError} `this` must be the host tuple * @throws {TypeError} first argument must be an integer * @throws {TypeError} second argument must be an integer - * @returns {(TypedArray|null)} new tuple + * @returns {TypedArray} new tuple */ function subtuple( begin, end ) { var f; @@ -1168,8 +1147,8 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi j = nfields; } } - if ( i >= j ) { - return null; + if ( j <= i ) { + return factory( [], opts )( tuple.buffer, tuple.byteOffset, dtype ); } f = []; for ( k = i; k < j; k++ ) { @@ -1275,6 +1254,17 @@ function factory( names, options ) { // eslint-disable-line max-lines-per-functi } } + /** + * Returns the list of tuple fields. + * + * @private + * @memberof tuple + * @returns {StringArray} tuple fields + */ + function getFields() { + return fields.slice(); + } + // Note: keep the following methods in alphabetical order... /** diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js index 0fefa6d4925d..21cef258d46f 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.slice.js @@ -339,7 +339,7 @@ tape( 'the method supports negative indices', function test( t ) { t.end(); }); -tape( 'the method returns null if a resolved beginning index exceeds a resolved ending index', function test( t ) { +tape( 'the method returns an empty tuple if a resolved beginning index exceeds a resolved ending index', function test( t ) { var actual; var Point; var p; @@ -348,11 +348,12 @@ tape( 'the method returns null if a resolved beginning index exceeds a resolved p = new Point( [ 1, 2, 3, 4 ] ); actual = p.slice( 2, 0 ); - t.strictEqual( actual, null, 'returns expected value' ); + t.strictEqual( actual.length, 0, 'returns expected value' ); + t.deepEqual( actual.fields, [], 'returns expected value' ); t.end(); }); -tape( 'the method returns null if a resolved beginning index exceeds the maximum tuple index', function test( t ) { +tape( 'the method returns an empty tuple if a resolved beginning index exceeds the maximum tuple index', function test( t ) { var actual; var Point; var p; @@ -361,11 +362,12 @@ tape( 'the method returns null if a resolved beginning index exceeds the maximum p = new Point( [ 1, 2, 3 ] ); actual = p.slice( 5 ); - t.strictEqual( actual, null, 'returns expected value' ); + t.strictEqual( actual.length, 0, 'returns expected value' ); + t.deepEqual( actual.fields, [], 'returns expected value' ); t.end(); }); -tape( 'the method returns null if a resolved ending index is less than or equal to zero', function test( t ) { +tape( 'the method returns an empty tuple if a resolved ending index is less than or equal to zero', function test( t ) { var actual; var Point; var p; @@ -374,9 +376,11 @@ tape( 'the method returns null if a resolved ending index is less than or equal p = new Point( [ 1, 2, 3, 4 ] ); actual = p.slice( 2, -8 ); - t.strictEqual( actual, null, 'returns expected value' ); + t.strictEqual( actual.length, 0, 'returns expected value' ); + t.deepEqual( actual.fields, [], 'returns expected value' ); actual = p.slice( 1, 0 ); - t.strictEqual( actual, null, 'returns expected value' ); + t.strictEqual( actual.length, 0, 'returns expected value' ); + t.deepEqual( actual.fields, [], 'returns expected value' ); t.end(); }); From fd9991b94b618d3adfd81f177ddda412388bf1df Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 16:51:50 -0700 Subject: [PATCH 16/17] fix: remove conditional --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js | 4 +--- lib/node_modules/@stdlib/ndarray/base/some-by/test/test.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js index 6c2cd169969f..d62e053c8aed 100644 --- a/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js @@ -196,9 +196,7 @@ function someBy( arrays, predicate, thisArg ) { // Resolve the success criterion: N = n.accessors[ 0 ]( n.data, n.offset ); - if ( N < 1 ) { - return true; - } + // Determine whether we can avoid iteration altogether... if ( ndims === 0 ) { if ( x.accessorProtocol ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/some-by/test/test.js b/lib/node_modules/@stdlib/ndarray/base/some-by/test/test.js index 0dc1673e766c..0ee3feb41629 100644 --- a/lib/node_modules/@stdlib/ndarray/base/some-by/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/some-by/test/test.js @@ -56,7 +56,7 @@ tape( 'the function returns `false` if provided an empty input ndarray', functio } }); -tape( 'the function returns `true` if a provided `n` parameter is less than zero', function test( t ) { +tape( 'the function returns `false` if a provided `n` parameter is less than zero', function test( t ) { var actual; var x; var n; @@ -67,7 +67,7 @@ tape( 'the function returns `true` if a provided `n` parameter is less than zero }); actual = someBy( [ x, n ], clbk ); - t.strictEqual( actual, true, 'returns expected value' ); + t.strictEqual( actual, false, 'returns expected value' ); t.end(); From a3e79786217bf1c9a84875203251af82cc93a222 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 17 Sep 2025 17:02:10 -0700 Subject: [PATCH 17/17] docs: update markup --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/any-by/README.md | 2 +- .../@stdlib/ndarray/base/any-by/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/any-by/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/base/any/README.md | 2 +- .../@stdlib/ndarray/base/any/docs/repl.txt | 2 +- lib/node_modules/@stdlib/ndarray/base/any/lib/main.js | 2 +- .../@stdlib/ndarray/base/assign/lib/main.js | 2 +- .../@stdlib/ndarray/base/binary/lib/main.js | 2 +- .../@stdlib/ndarray/base/count-falsy/README.md | 2 +- .../@stdlib/ndarray/base/count-falsy/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/count-falsy/lib/main.js | 2 +- .../@stdlib/ndarray/base/count-if/README.md | 2 +- .../@stdlib/ndarray/base/count-if/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/count-if/lib/main.js | 2 +- .../@stdlib/ndarray/base/count-truthy/README.md | 2 +- .../@stdlib/ndarray/base/count-truthy/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/count-truthy/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/base/ctor/README.md | 10 +++++----- .../@stdlib/ndarray/base/every-by/README.md | 2 +- .../@stdlib/ndarray/base/every-by/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/every-by/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/base/every/README.md | 2 +- .../@stdlib/ndarray/base/every/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/every/lib/main.js | 2 +- .../@stdlib/ndarray/base/find/docs/repl.txt | 2 +- lib/node_modules/@stdlib/ndarray/base/find/lib/main.js | 2 +- .../@stdlib/ndarray/base/for-each/README.md | 2 +- .../@stdlib/ndarray/base/for-each/lib/main.js | 2 +- .../@stdlib/ndarray/base/includes/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/includes/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/base/map/lib/main.js | 2 +- .../@stdlib/ndarray/base/meta-data-props/README.md | 2 +- .../@stdlib/ndarray/base/nullary/README.md | 2 +- .../@stdlib/ndarray/base/nullary/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/nullary/lib/main.js | 2 +- .../@stdlib/ndarray/base/some-by/README.md | 2 +- .../@stdlib/ndarray/base/some-by/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/some-by/lib/main.js | 2 +- .../@stdlib/ndarray/base/unary-by/README.md | 2 +- .../@stdlib/ndarray/base/unary-by/docs/repl.txt | 2 +- .../@stdlib/ndarray/base/unary-by/lib/main.js | 2 +- .../@stdlib/ndarray/base/unary/lib/main.js | 2 +- lib/node_modules/@stdlib/ndarray/ctor/README.md | 8 ++++---- 43 files changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/any-by/README.md b/lib/node_modules/@stdlib/ndarray/base/any-by/README.md index 1bb80b5b9b5a..869b2b25b240 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/any-by/README.md @@ -82,7 +82,7 @@ The function accepts the following arguments: - **predicate**: predicate function. - **thisArg**: predicate function execution context (_optional_). -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/any-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/any-by/docs/repl.txt index d6860e747c89..40de05ea5fcb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/any-by/docs/repl.txt @@ -3,7 +3,7 @@ Tests whether at least one element in an ndarray passes a test implemented by a predicate function. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/any-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/any-by/lib/main.js index c5d9f0731d7c..046c85a85848 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/any-by/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = ANY.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/any/README.md b/lib/node_modules/@stdlib/ndarray/base/any/README.md index ee3423e92bda..ec51f73980fa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/any/README.md @@ -76,7 +76,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing an input ndarray. -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/any/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/any/docs/repl.txt index c1d7ddd3460c..56f3e8da946c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/any/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( arrays ) Tests whether at least one element in an ndarray is truthy. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/any/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/any/lib/main.js index 632d4df17ea6..0d2113bd9b7f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/any/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/any/lib/main.js @@ -177,7 +177,7 @@ var MAX_DIMS = ANY.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/assign/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/assign/lib/main.js index 12a2fd857ab0..cce3b9930f52 100644 --- a/lib/node_modules/@stdlib/ndarray/base/assign/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/assign/lib/main.js @@ -195,7 +195,7 @@ function complex2real( x ) { * * ## Notes * -* - Each provided ndarray should be an `object` with the following properties: +* - Each provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/binary/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/binary/lib/main.js index a30ef3c15674..89c866e36704 100644 --- a/lib/node_modules/@stdlib/ndarray/base/binary/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/binary/lib/main.js @@ -146,7 +146,7 @@ function hasAccessors( x, y, z ) { * * ## Notes * -* - Each provided ndarray should be an `object` with the following properties: +* - Each provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-falsy/README.md b/lib/node_modules/@stdlib/ndarray/base/count-falsy/README.md index c41c90d3a62f..5d2cc147f6e2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-falsy/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/count-falsy/README.md @@ -76,7 +76,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing an input ndarray. -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-falsy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/count-falsy/docs/repl.txt index d81855a333eb..b4f92dad88bc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-falsy/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/count-falsy/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( arrays ) Counts the number of falsy elements in an ndarray. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-falsy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/count-falsy/lib/main.js index f9c170ace0d8..325afeec0c95 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-falsy/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/count-falsy/lib/main.js @@ -177,7 +177,7 @@ var MAX_DIMS = COUNT.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-if/README.md b/lib/node_modules/@stdlib/ndarray/base/count-if/README.md index be22e9e5e853..3c74b4d077ba 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-if/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/count-if/README.md @@ -82,7 +82,7 @@ The function accepts the following arguments: - **predicate**: predicate function. - **thisArg**: predicate function execution context (_optional_). -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-if/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/count-if/docs/repl.txt index 3a0b421cea23..ec945749f3a4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-if/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/count-if/docs/repl.txt @@ -3,7 +3,7 @@ Counts the number of elements in an ndarray which pass a test implemented by a predicate function. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-if/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/count-if/lib/main.js index 5d943b8c1de5..5695a2388adc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-if/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/count-if/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = COUNT.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-truthy/README.md b/lib/node_modules/@stdlib/ndarray/base/count-truthy/README.md index 33b95221ccd8..549f5fc9f091 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-truthy/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/count-truthy/README.md @@ -76,7 +76,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing an input ndarray. -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-truthy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/count-truthy/docs/repl.txt index ac575cf6072b..95d57e356a42 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-truthy/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/count-truthy/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( arrays ) Counts the number of truthy elements in an ndarray. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/count-truthy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/count-truthy/lib/main.js index ec289be6bcf0..fa3112c91862 100644 --- a/lib/node_modules/@stdlib/ndarray/base/count-truthy/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/count-truthy/lib/main.js @@ -177,7 +177,7 @@ var MAX_DIMS = COUNT.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/ctor/README.md b/lib/node_modules/@stdlib/ndarray/base/ctor/README.md index 482124a554d5..9197e8929c77 100644 --- a/lib/node_modules/@stdlib/ndarray/base/ctor/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/ctor/README.md @@ -236,11 +236,11 @@ var dtype = arr.dtype; #### ndarray.prototype.flags -Meta information, such as information concerning the memory layout of the array. The returned `object` has the following properties: +Meta information, such as information concerning the memory layout of the array. The returned object has the following properties: -- **ROW_MAJOR_CONTIGUOUS**: `boolean` indicating if an array is row-major contiguous. -- **COLUMN_MAJOR_CONTIGUOUS**: `boolean` indicating if an array is column-major contiguous. -- **READONLY**: `boolean` indicating if an array is **read-only**. +- **ROW_MAJOR_CONTIGUOUS**: boolean indicating if an array is row-major contiguous. +- **COLUMN_MAJOR_CONTIGUOUS**: boolean indicating if an array is column-major contiguous. +- **READONLY**: boolean indicating if an array is **read-only**. An array is contiguous if (1) an array is compatible with being stored in a single memory segment and (2) each array element is adjacent to the next array element. Note that an array can be both row-major contiguous and column-major contiguous at the same time (e.g., if an array is a 1-dimensional ndarray with `strides = [1]`). @@ -538,7 +538,7 @@ The method does **not** serialize data outside of the buffer region defined by t #### ndarray.prototype.toJSON() -Serializes an `ndarray` as a [JSON][json] `object`. `JSON.stringify()` implicitly calls this method when stringifying an `ndarray` instance. +Serializes an `ndarray` as a [JSON][json] object. `JSON.stringify()` implicitly calls this method when stringifying an `ndarray` instance. ```javascript // Specify the array configuration: diff --git a/lib/node_modules/@stdlib/ndarray/base/every-by/README.md b/lib/node_modules/@stdlib/ndarray/base/every-by/README.md index 4e0cc5ad5975..a6cfdaf0c430 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/every-by/README.md @@ -82,7 +82,7 @@ The function accepts the following arguments: - **predicate**: predicate function. - **thisArg**: predicate function execution context (_optional_). -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/every-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/every-by/docs/repl.txt index cf10fa57c711..179a8cf561ca 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/every-by/docs/repl.txt @@ -3,7 +3,7 @@ Tests whether all elements in an ndarray pass a test implemented by a predicate function. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/every-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/every-by/lib/main.js index 07d377a36ec8..c9e099622bd1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/every-by/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = EVERY.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/every/README.md b/lib/node_modules/@stdlib/ndarray/base/every/README.md index ee777fc206ec..e4f87e0f5b92 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/every/README.md @@ -76,7 +76,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing an input ndarray. -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/every/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/every/docs/repl.txt index 78f70703b3f2..3d381816b756 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/every/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( arrays ) Tests whether every element in an ndarray is truthy. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/every/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/every/lib/main.js index b2324dc1fe23..38f8df2bec71 100644 --- a/lib/node_modules/@stdlib/ndarray/base/every/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/every/lib/main.js @@ -177,7 +177,7 @@ var MAX_DIMS = EVERY.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt index f94c2642a8fa..9e548f4901e0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/find/docs/repl.txt @@ -3,7 +3,7 @@ Returns the first element in an ndarray which passes a test implemented by a predicate function. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js index e6b2748f4d21..ee39e1a7228d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/find/lib/main.js @@ -86,7 +86,7 @@ var MAX_DIMS = FIND.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/for-each/README.md b/lib/node_modules/@stdlib/ndarray/base/for-each/README.md index c0fbdee3c13f..1e6afceb2620 100644 --- a/lib/node_modules/@stdlib/ndarray/base/for-each/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/for-each/README.md @@ -91,7 +91,7 @@ The callback function is provided the following arguments: ## Notes -- The provided ndarray should be an `object` with the following properties: +- The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/for-each/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/for-each/lib/main.js index f872337a9414..5378170a06e7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/for-each/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/for-each/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = FOR_EACH.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/includes/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/includes/docs/repl.txt index b51b61eac4ac..918bb3ab59ae 100644 --- a/lib/node_modules/@stdlib/ndarray/base/includes/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/includes/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( arrays ) Tests whether an ndarray contains a specified value. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/includes/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/includes/lib/main.js index 1a93d4a1d94e..1d3b346f00e8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/includes/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/includes/lib/main.js @@ -181,7 +181,7 @@ var MAX_DIMS = INCLUDES.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/map/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/map/lib/main.js index 09dc78b7edfc..724279df9cfa 100644 --- a/lib/node_modules/@stdlib/ndarray/base/map/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/map/lib/main.js @@ -128,7 +128,7 @@ var MAX_DIMS = MAP.length -1; * * ## Notes * -* - Each provided ndarray should be an `object` with the following properties: +* - Each provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/meta-data-props/README.md b/lib/node_modules/@stdlib/ndarray/base/meta-data-props/README.md index 1f2c1650d9ed..6979ac054a33 100644 --- a/lib/node_modules/@stdlib/ndarray/base/meta-data-props/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/meta-data-props/README.md @@ -66,7 +66,7 @@ var obj = {}; setProps( meta, dtypes, obj ); ``` -The `meta` data argument should be an `object` with the following properties: +The `meta` data argument should be an object with the following properties: - **nargs**: total number of arguments. This value is one more than might be expected, as the output array is treated as an implicit argument, even when not explicitly provided. - **nin**: number of input ndarrays. diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/README.md b/lib/node_modules/@stdlib/ndarray/base/nullary/README.md index f0b5023ed2bc..70d2cedc6680 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/README.md @@ -83,7 +83,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing an output ndarray. - **fcn**: nullary function to apply. -The provided ndarray should be an `object` with the following properties: +The provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nullary/docs/repl.txt index d140c011af36..11309e8627a8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/docs/repl.txt @@ -3,7 +3,7 @@ Applies a nullary callback and assigns results to elements in an output ndarray. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nullary/lib/main.js index c97d5e914638..9a9851195a37 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = NULLARY.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/some-by/README.md b/lib/node_modules/@stdlib/ndarray/base/some-by/README.md index 35cba61cc7fe..f8942555eb45 100644 --- a/lib/node_modules/@stdlib/ndarray/base/some-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/some-by/README.md @@ -88,7 +88,7 @@ The function accepts the following arguments: - **predicate**: predicate function. - **thisArg**: predicate function execution context (_optional_). -Each provided ndarray should be an `object` with the following properties: +Each provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/some-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/some-by/docs/repl.txt index f3c116f308c9..3e55bfd4f157 100644 --- a/lib/node_modules/@stdlib/ndarray/base/some-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/some-by/docs/repl.txt @@ -3,7 +3,7 @@ Tests whether at least `n` elements in an ndarray pass a test implemented by a predicate function. - A provided "ndarray" should be an `object` with the following properties: + A provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js index d62e053c8aed..d09c47ee63e1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js @@ -127,7 +127,7 @@ var MAX_DIMS = SOME.length - 1; * * ## Notes * -* - A provided ndarray should be an `object` with the following properties: +* - A provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-by/README.md b/lib/node_modules/@stdlib/ndarray/base/unary-by/README.md index 51c52abc3a16..bb66377b3642 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-by/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/unary-by/README.md @@ -98,7 +98,7 @@ The function accepts the following arguments: - **arrays**: array-like object containing one input ndarray and one output ndarray. - **fcn**: unary function to apply. -Each provided ndarray should be an `object` with the following properties: +Each provided ndarray should be an object with the following properties: - **dtype**: data type. - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-by/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/unary-by/docs/repl.txt index b4665eda517c..6022f2a68349 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/unary-by/docs/repl.txt @@ -4,7 +4,7 @@ according to a callback function and assigns results to elements in an output ndarray. - Each provided "ndarray" should be an `object` with the following properties: + Each provided "ndarray" should be an object with the following properties: - dtype: data type. - data: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-by/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary-by/lib/main.js index 241ccf4181f6..303ea9a09b86 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-by/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-by/lib/main.js @@ -128,7 +128,7 @@ var MAX_DIMS = UNARY.length - 1; * * ## Notes * -* - Each provided ndarray should be an `object` with the following properties: +* - Each provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/unary/lib/main.js index fc1c18dabbb1..7f57768d02a3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary/lib/main.js @@ -129,7 +129,7 @@ var MAX_DIMS = UNARY.length - 1; * * ## Notes * -* - Each provided ndarray should be an `object` with the following properties: +* - Each provided ndarray should be an object with the following properties: * * - **dtype**: data type. * - **data**: data buffer. diff --git a/lib/node_modules/@stdlib/ndarray/ctor/README.md b/lib/node_modules/@stdlib/ndarray/ctor/README.md index 5d23564fcb18..3fc9bca4da83 100644 --- a/lib/node_modules/@stdlib/ndarray/ctor/README.md +++ b/lib/node_modules/@stdlib/ndarray/ctor/README.md @@ -283,11 +283,11 @@ var dtype = arr.dtype; #### ndarray.prototype.flags -Meta information, such as information regarding the memory layout of the array. The returned `object` has the following properties: +Meta information, such as information regarding the memory layout of the array. The returned object has the following properties: -- **ROW_MAJOR_CONTIGUOUS**: `boolean` indicating if an array is row-major contiguous. -- **COLUMN_MAJOR_CONTIGUOUS**: `boolean` indicating if an array is column-major contiguous. -- **READONLY**: `boolean` indicating whether an array is **read-only**. +- **ROW_MAJOR_CONTIGUOUS**: boolean indicating if an array is row-major contiguous. +- **COLUMN_MAJOR_CONTIGUOUS**: boolean indicating if an array is column-major contiguous. +- **READONLY**: boolean indicating whether an array is **read-only**. An array is contiguous if (1) an array is compatible with being stored in a single memory segment and (2) each array element is adjacent to the next array element. Note that an array can be both row-major contiguous and column-major contiguous at the same time (e.g., if an array is a 1-dimensional ndarray with `strides = [1]`).