From 31b0e92a2ddf997d85009694ddd974f5f5bbe3c6 Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Thu, 4 Dec 2025 20:48:53 +0530 Subject: [PATCH 1/9] feat: add stats/nanmeanwd --- .../@stdlib/stats/nanmeanwd/README.md | 297 +++++++ .../nanmeanwd/benchmark/benchmark.assign.js | 126 +++ .../stats/nanmeanwd/benchmark/benchmark.js | 120 +++ .../@stdlib/stats/nanmeanwd/docs/repl.txt | 79 ++ .../stats/nanmeanwd/docs/types/index.d.ts | 151 ++++ .../stats/nanmeanwd/docs/types/test.ts | 225 +++++ .../@stdlib/stats/nanmeanwd/examples/index.js | 53 ++ .../@stdlib/stats/nanmeanwd/lib/index.js | 63 ++ .../@stdlib/stats/nanmeanwd/lib/main.js | 101 +++ .../@stdlib/stats/nanmeanwd/package.json | 67 ++ .../stats/nanmeanwd/test/test.assign.js | 728 ++++++++++++++++ .../@stdlib/stats/nanmeanwd/test/test.js | 39 + .../@stdlib/stats/nanmeanwd/test/test.main.js | 774 ++++++++++++++++++ 13 files changed, 2823 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/README.md create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/package.json create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/nanmeanwd/test/test.main.js diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md new file mode 100644 index 000000000000..d3fff1f7c251 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md @@ -0,0 +1,297 @@ + + +# nanmeanwd + +> Compute the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using Welford's algorithm, ignoring `NaN` values. + +
+ +The [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var nanmeanwd = require( '@stdlib/stats/nanmeanwd' ); +``` + +#### nanmeanwd( x\[, options] ) + +Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using Welford's algorithm, ignoring `NaN` values. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); + +var y = nanmeanwd( x ); +// returns + +var v = y.get(); +// returns 1.0 +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform a reduction. If not provided, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a real-valued floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +By default, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform a reduction over specific dimensions, provide a `dims` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, NaN, -2.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +var v = ndarray2array( x ); +// returns [ [ 1.0, NaN ], [ -2.0, 4.0 ] ] + +var y = nanmeanwd( x, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ -0.5, 4.0 ] + +y = nanmeanwd( x, { + 'dims': [ 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ 1.0, 1.0 ] + +y = nanmeanwd( x, { + 'dims': [ 0, 1 ] +}); +// returns + +v = y.get(); +// returns 1.0 +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, NaN, -2.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var v = ndarray2array( x ); +// returns [ [ 1.0, NaN ], [ -2.0, 4.0 ] ] + +var y = nanmeanwd( x, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -0.5, 4.0 ] ] + +y = nanmeanwd( x, { + 'dims': [ 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 1.0 ], [ 1.0 ] ] + +y = nanmeanwd( x, { + 'dims': [ 0, 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 1.0 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, NaN, -2.0, 4.0 ], { + 'dtype': 'generic' +}); + +var y = nanmeanwd( x, { + 'dtype': 'float64' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'float64' +``` + +#### nanmeanwd.assign( x, out\[, options] ) + +Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using Welford's algorithm, ignoring `NaN` values, and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); +var y = zeros( [] ); + +var out = nanmeanwd.assign( x, y ); +// returns + +var v = out.get(); +// returns 1.0 + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or generic [data type][@stdlib/ndarray/dtypes]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform a reduction. If not provided, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- This function uses Welford's algorithm for computing the mean, which provides improved numerical stability compared to naive summation approaches, particularly beneficial when dealing with values of different magnitudes or accumulating floating-point errors. +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var nanmeanwd = require( '@stdlib/stats/nanmeanwd' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( 0.0, 20.0 ); +} + +// Generate an array of random numbers: +var xbuf = filledarrayBy( 25, 'generic', rand ); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform a reduction: +var y = nanmeanwd( x, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..fa2568b7819f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js @@ -0,0 +1,126 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var nanmeanwd = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = filledarrayBy( len, options.dtype, rand ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + out = new ndarray( options.dtype, zeros( 1, options.dtype ), [], [ 0 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = nanmeanwd( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + 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:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.js new file mode 100644 index 000000000000..146af80ac0fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.js @@ -0,0 +1,120 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var nanmeanwd = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.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 ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = nanmeanwd( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + 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+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt new file mode 100644 index 000000000000..688cc71c9f60 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt @@ -0,0 +1,79 @@ + +{{alias}}( x[, options] ) + Computes the arithmetic mean along one or more ndarray dimensions, ignoring + `NaN` values, using Welford's algorithm. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + options: Object (optional) + Function options. + + options.dtype: string (optional) + Output array data type. Must be a real-valued floating-point or + "generic" data type. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, NaN, -2.0, 4.0 ] ); + > var y = {{alias}}( x ); + > var v = y.get() + 1.0 + + +{{alias}}.assign( x, out[, options] ) + Computes the arithmetic mean along one or more ndarray dimensions, ignoring + `NaN` values, using Welford's algorithm, and assigns results to a provided + output ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, NaN, -2.0, 4.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [] ); + > var y = {{alias}}.assign( x, out ) + + > var bool = ( out === y ) + true + > var v = out.get() + 1.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/index.d.ts new file mode 100644 index 000000000000..dae466145f02 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/index.d.ts @@ -0,0 +1,151 @@ +/* +* @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 { RealFloatingPointAndGenericDataType as 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 a reduction. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + +/** +* Interface for performing a reduction on an ndarray using Welford's algorithm. +*/ +interface Unary { + /** + * Computes the arithmetic mean along one or more ndarray dimensions using Welford's algorithm, ignoring `NaN` values. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); + * + * var y = nanmeanwd( x ); + * // returns + * + * var v = y.get(); + * // returns 1.0 + */ + ( x: InputArray, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + + /** + * Computes the arithmetic mean along one or more ndarray dimensions using Welford's algorithm, ignoring `NaN` values, and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = nanmeanwd.assign( x, y ); + * // returns + * + * var v = out.get(); + * // returns 1.0 + * + * var bool = ( out === y ); + * // returns true + */ + assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Computes the arithmetic mean along one or more ndarray dimensions using Welford's algorithm, ignoring `NaN` values. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); +* +* var y = nanmeanwd( x ); +* // returns +* +* var v = y.get(); +* // returns 1.0 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ 1.0, NaN, -2.0, 4.0 ] ); +* var y = zeros( [] ); +* +* var out = nanmeanwd.assign( x, y ); +* // returns +* +* var v = out.get(); +* // returns 1.0 +* +* var bool = ( out === y ); +* // returns true +*/ +declare const nanmeanwd: Unary; + + +// EXPORTS // + +export = nanmeanwd; diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/test.ts b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/test.ts new file mode 100644 index 000000000000..e8c7d902ba05 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/types/test.ts @@ -0,0 +1,225 @@ +/* +* @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 zeros = require( '@stdlib/ndarray/zeros' ); +import nanmeanwd = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd( x ); // $ExpectType OutputArray + nanmeanwd( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + nanmeanwd( '5' ); // $ExpectError + nanmeanwd( 5 ); // $ExpectError + nanmeanwd( true ); // $ExpectError + nanmeanwd( false ); // $ExpectError + nanmeanwd( null ); // $ExpectError + nanmeanwd( void 0 ); // $ExpectError + nanmeanwd( {} ); // $ExpectError + nanmeanwd( ( x: number ): number => x ); // $ExpectError + + nanmeanwd( '5', {} ); // $ExpectError + nanmeanwd( 5, {} ); // $ExpectError + nanmeanwd( true, {} ); // $ExpectError + nanmeanwd( false, {} ); // $ExpectError + nanmeanwd( null, {} ); // $ExpectError + nanmeanwd( void 0, {} ); // $ExpectError + nanmeanwd( {}, {} ); // $ExpectError + nanmeanwd( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd( x, '5' ); // $ExpectError + nanmeanwd( x, true ); // $ExpectError + nanmeanwd( x, false ); // $ExpectError + nanmeanwd( x, null ); // $ExpectError + nanmeanwd( x, [] ); // $ExpectError + nanmeanwd( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd( x, { 'dtype': '5' } ); // $ExpectError + nanmeanwd( x, { 'dtype': 5 } ); // $ExpectError + nanmeanwd( x, { 'dtype': true } ); // $ExpectError + nanmeanwd( x, { 'dtype': false } ); // $ExpectError + nanmeanwd( x, { 'dtype': null } ); // $ExpectError + nanmeanwd( x, { 'dtype': [] } ); // $ExpectError + nanmeanwd( x, { 'dtype': {} } ); // $ExpectError + nanmeanwd( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd( x, { 'keepdims': '5' } ); // $ExpectError + nanmeanwd( x, { 'keepdims': 5 } ); // $ExpectError + nanmeanwd( x, { 'keepdims': null } ); // $ExpectError + nanmeanwd( x, { 'keepdims': [] } ); // $ExpectError + nanmeanwd( x, { 'keepdims': {} } ); // $ExpectError + nanmeanwd( x, { 'keepdims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd( x, { 'dims': '5' } ); // $ExpectError + nanmeanwd( x, { 'dims': 5 } ); // $ExpectError + nanmeanwd( x, { 'dims': true } ); // $ExpectError + nanmeanwd( x, { 'dims': false } ); // $ExpectError + nanmeanwd( x, { 'dims': null } ); // $ExpectError + nanmeanwd( x, { 'dims': {} } ); // $ExpectError + nanmeanwd( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd(); // $ExpectError + nanmeanwd( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign( x, x ); // $ExpectType float64ndarray + nanmeanwd.assign( x, x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign( '5', x ); // $ExpectError + nanmeanwd.assign( 5, x ); // $ExpectError + nanmeanwd.assign( true, x ); // $ExpectError + nanmeanwd.assign( false, x ); // $ExpectError + nanmeanwd.assign( null, x ); // $ExpectError + nanmeanwd.assign( void 0, x ); // $ExpectError + nanmeanwd.assign( {}, x ); // $ExpectError + nanmeanwd.assign( ( x: number ): number => x, x ); // $ExpectError + + nanmeanwd.assign( '5', x, {} ); // $ExpectError + nanmeanwd.assign( 5, x, {} ); // $ExpectError + nanmeanwd.assign( true, x, {} ); // $ExpectError + nanmeanwd.assign( false, x, {} ); // $ExpectError + nanmeanwd.assign( null, x, {} ); // $ExpectError + nanmeanwd.assign( void 0, x, {} ); // $ExpectError + nanmeanwd.assign( {}, x, {} ); // $ExpectError + nanmeanwd.assign( ( x: number ): number => x, x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign( x, '5' ); // $ExpectError + nanmeanwd.assign( x, 5 ); // $ExpectError + nanmeanwd.assign( x, true ); // $ExpectError + nanmeanwd.assign( x, false ); // $ExpectError + nanmeanwd.assign( x, null ); // $ExpectError + nanmeanwd.assign( x, void 0 ); // $ExpectError + nanmeanwd.assign( x, ( x: number ): number => x ); // $ExpectError + + nanmeanwd.assign( x, '5', {} ); // $ExpectError + nanmeanwd.assign( x, 5, {} ); // $ExpectError + nanmeanwd.assign( x, true, {} ); // $ExpectError + nanmeanwd.assign( x, false, {} ); // $ExpectError + nanmeanwd.assign( x, null, {} ); // $ExpectError + nanmeanwd.assign( x, void 0, {} ); // $ExpectError + nanmeanwd.assign( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign( x, x, '5' ); // $ExpectError + nanmeanwd.assign( x, x, true ); // $ExpectError + nanmeanwd.assign( x, x, false ); // $ExpectError + nanmeanwd.assign( x, x, null ); // $ExpectError + nanmeanwd.assign( x, x, [] ); // $ExpectError + nanmeanwd.assign( x, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign( x, x, { 'dims': '5' } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': 5 } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': true } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': false } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': null } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': {} } ); // $ExpectError + nanmeanwd.assign( x, x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + nanmeanwd.assign(); // $ExpectError + nanmeanwd.assign( x ); // $ExpectError + nanmeanwd.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/examples/index.js b/lib/node_modules/@stdlib/stats/nanmeanwd/examples/index.js new file mode 100644 index 000000000000..91cb0732eff3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/examples/index.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'; + +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var nanmeanwd = require( './../lib' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( 0.0, 20.0 ); +} + +// Generate an array of random numbers: +var xbuf = filledarrayBy( 25, 'generic', rand ); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform a reduction: +var y = nanmeanwd( x, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/lib/index.js b/lib/node_modules/@stdlib/stats/nanmeanwd/lib/index.js new file mode 100644 index 000000000000..7fcdcf87d04e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/lib/index.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'; + +/** +* Compute the arithmetic mean along one or more ndarray dimensions, ignoring `NaN` values and using Welford's algorithm. +* +* @module @stdlib/stats/nanmeanwd +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var nanmeanwd = require( '@stdlib/stats/nanmeanwd' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, NaN, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = nanmeanwd( x ); +* // returns +* +* var v = out.get(); +* // returns 7.2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/lib/main.js b/lib/node_modules/@stdlib/stats/nanmeanwd/lib/main.js new file mode 100644 index 000000000000..9ab900820de8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/lib/main.js @@ -0,0 +1,101 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gnanmeanwd = require( '@stdlib/stats/base/ndarray/nanmeanwd' ); +var dnanmeanwd = require( '@stdlib/stats/base/ndarray/dnanmeanwd' ); +var snanmeanwd = require( '@stdlib/stats/base/ndarray/snanmeanwd' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'real_and_generic' ); +var odtypes = dtypes( 'real_floating_point_and_generic' ); +var policies = { + 'output': 'real_floating_point_and_generic', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', // input + 'float32' // input + ], + 'fcns': [ + dnanmeanwd, + snanmeanwd + ], + 'default': gnanmeanwd +}; + + +// MAIN // + +/** +* Computes the arithmetic mean along one or more ndarray dimensions, ignoring `NaN` values and using Welford's algorithm. +* +* @name nanmeanwd +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {string} [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 {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, NaN, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = nanmeanwd( x ); +* // returns +* +* var v = out.get(); +* // returns 7.2 +*/ +var nanmeanwd = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = nanmeanwd; diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/package.json b/lib/node_modules/@stdlib/stats/nanmeanwd/package.json new file mode 100644 index 000000000000..d9bb47e50536 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/nanmeanwd", + "version": "0.0.0", + "description": "Compute the arithmetic mean along one or more ndarray dimensions using Welford's algorithm, ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "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", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "mean", + "arithmetic mean", + "welford", + "central tendency", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.assign.js b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.assign.js new file mode 100644 index 000000000000..6968575fddab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.assign.js @@ -0,0 +1,728 @@ +/** +* @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 isSameValue = require( '@stdlib/assert/is-same-value' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var emptyLike = require( '@stdlib/ndarray/empty-like' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nanmeanwd = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nanmeanwd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + nanmeanwd( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + nanmeanwd( value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( x, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + nanmeanwd( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (default)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + nanmeanwd( x, out ); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (all dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + nanmeanwd( x, out, { + 'dims': [ 0, 1 ] + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (some dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + nanmeanwd( x, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function performs a reduction on an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = nanmeanwd( x, out ); + expected = 1.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = nanmeanwd( x, out ); + expected = 1.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 1.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 1.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [] + }); + expected = [ [ 1.0, NaN ], [ -2.0, 4.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [] + }); + expected = [ [ 1.0, -2.0 ], [ NaN, 4.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 0 ] + }); + expected = [ -0.5, 4.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 1 ] + }); + expected = [ 1.0, 1.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 0 ] + }); + expected = [ 1.0, 1.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = nanmeanwd( x, out, { + 'dims': [ 1 ] + }); + expected = [ -0.5, 4.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.js b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.js new file mode 100644 index 000000000000..1b2a9ad3074e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.js @@ -0,0 +1,39 @@ +/** +* @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 isMethod = require( '@stdlib/assert/is-method' ); +var nanmeanwd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nanmeanwd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( nanmeanwd, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.main.js b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.main.js new file mode 100644 index 000000000000..83d596e7bf0b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/test/test.main.js @@ -0,0 +1,774 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameValue = require( '@stdlib/assert/is-same-value' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var nanmeanwd = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nanmeanwd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', 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() { + nanmeanwd( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (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() { + nanmeanwd( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + nanmeanwd( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + 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() { + nanmeanwd( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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() { + nanmeanwd( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + 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() { + nanmeanwd( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `keepdims` option which is not a boolean', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + 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() { + nanmeanwd( x, { + 'keepdims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + nanmeanwd( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmeanwd( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function performs a reduction on an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x ); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ] + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 1.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ] + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 1.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, NaN ], [ -2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, NaN ], [ -2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, -2.0 ], [ NaN, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, -2.0 ], [ NaN, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + + actual = ndarray2array( actual ); + t.strictEqual( isSameValue( actual[ 0 ][ 0 ], expected[ 0 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 0 ][ 1 ], expected[ 0 ][ 1 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 0 ], expected[ 1 ][ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isSameValue( actual[ 1 ][ 1 ], expected[ 1 ][ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ -0.5, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ -0.5, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ 1.0, 1.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ 1.0 ], [ 1.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ 1.0, 1.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ 1.0, 1.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ -0.5, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ -0.5 ], [ 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = nanmeanwd( x, { + 'dtype': 'float64' + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + xbuf = [ 1.0, NaN, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = nanmeanwd( x, { + 'dtype': 'float64' + }); + expected = 1.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); From 56b919c5cbb6abef071bb5b7a782605c43c5d8c1 Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Thu, 4 Dec 2025 20:56:00 +0530 Subject: [PATCH 2/9] Updates benchmark to use assign method for output --- .../@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js index fa2568b7819f..96970bcc0efb 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/benchmark/benchmark.assign.js @@ -84,7 +84,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - o = nanmeanwd( x ); + o = nanmeanwd.assign( x, out ); if ( typeof o !== 'object' ) { b.fail( 'should return an ndarray' ); } From ecacf8aface0e864b8205fee87e016a5a753e0ee Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 17:50:20 -0800 Subject: [PATCH 3/9] docs: update desc Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/nanmeanwd/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/package.json b/lib/node_modules/@stdlib/stats/nanmeanwd/package.json index d9bb47e50536..9122a6c37956 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/package.json +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/nanmeanwd", "version": "0.0.0", - "description": "Compute the arithmetic mean along one or more ndarray dimensions using Welford's algorithm, ignoring `NaN` values.", + "description": "Compute the arithmetic mean along one or more ndarray dimensions, ignoring `NaN` values and using Welford's algorithm.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 69cf75be7115aca56280b028af90d09cc59d2569 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 17:50:49 -0800 Subject: [PATCH 4/9] docs: update note Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/nanmeanwd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md index d3fff1f7c251..b67be437e4b2 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md @@ -216,7 +216,7 @@ The method accepts the following options: ## Notes -- This function uses Welford's algorithm for computing the mean, which provides improved numerical stability compared to naive summation approaches, particularly beneficial when dealing with values of different magnitudes or accumulating floating-point errors. +- This function uses Welford's algorithm for computing the arithmetic mean, providing improved numerical stability compared to naive summation approaches and being particularly beneficial when dealing with values of different magnitudes or accumulating floating-point errors. - Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. - The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. From 59b282d8cb2a020550da37e58c005906c68baf0f Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 4 Dec 2025 17:51:43 -0800 Subject: [PATCH 5/9] docs: update note Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/nanmeanwd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md index b67be437e4b2..5e1f49145768 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md @@ -216,7 +216,7 @@ The method accepts the following options: ## Notes -- This function uses Welford's algorithm for computing the arithmetic mean, providing improved numerical stability compared to naive summation approaches and being particularly beneficial when dealing with values of different magnitudes or accumulating floating-point errors. +- This implementation uses Welford's algorithm for computing the arithmetic mean, providing improved numerical stability compared to naive summation approaches and being particularly beneficial when dealing with values of different magnitudes or accumulating floating-point errors. - Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. - The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued floating-point or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. From 3fe1c645322a868f7737e83fbcf177432ba2130b Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:57:08 +0530 Subject: [PATCH 6/9] Update lib/node_modules/@stdlib/stats/nanmeanwd/README.md Co-authored-by: Athan Signed-off-by: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/nanmeanwd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md index 5e1f49145768..f2a97adca391 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md @@ -20,7 +20,7 @@ limitations under the License. # nanmeanwd -> Compute the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using Welford's algorithm, ignoring `NaN` values. +> Compute the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions, ignoring `NaN` values and using Welford's algorithm.
From 168388ec65b7ba5dc494b6e161109650f2c45d85 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:57:16 +0530 Subject: [PATCH 7/9] Update lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt Co-authored-by: Athan Signed-off-by: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt index 688cc71c9f60..8b7f6eb035d7 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) Computes the arithmetic mean along one or more ndarray dimensions, ignoring - `NaN` values, using Welford's algorithm. + `NaN` values and using Welford's algorithm. Parameters ---------- From d32e4207b44c630b4309d9ead82fe77ead02b351 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:57:25 +0530 Subject: [PATCH 8/9] Update lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt Co-authored-by: Athan Signed-off-by: Sachin Pangal <151670745+Orthodox-64@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt index 8b7f6eb035d7..c3598c751518 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt @@ -39,7 +39,7 @@ {{alias}}.assign( x, out[, options] ) Computes the arithmetic mean along one or more ndarray dimensions, ignoring - `NaN` values, using Welford's algorithm, and assigns results to a provided + `NaN` values and using Welford's algorithm, and assigns results to a provided output ndarray. Parameters From 803515749ce1430f400e98df628f694f440fb4ff Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Fri, 5 Dec 2025 15:05:11 +0530 Subject: [PATCH 9/9] chore: changes --- .../@stdlib/stats/nanmeanwd/README.md | 17 +++++++++++++++++ .../@stdlib/stats/nanmeanwd/docs/repl.txt | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md index f2a97adca391..99cfb3e43a05 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/README.md @@ -270,6 +270,19 @@ console.log( ndarray2array( y ) ); +* * * + +
+ +## References + +- Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022][@welford:1962a]. +- van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961][@vanreeken:1968a]. + +
+ + + diff --git a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt index c3598c751518..461e89b3b5a9 100644 --- a/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/nanmeanwd/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) - Computes the arithmetic mean along one or more ndarray dimensions, ignoring - `NaN` values and using Welford's algorithm. + Computes the arithmetic mean along one or more ndarray dimensions, using + Welford's algorithm and ignoring NaN values. Parameters ---------- @@ -38,9 +38,9 @@ {{alias}}.assign( x, out[, options] ) - Computes the arithmetic mean along one or more ndarray dimensions, ignoring - `NaN` values and using Welford's algorithm, and assigns results to a provided - output ndarray. + Computes the arithmetic mean along one or more ndarray dimensions, using + Welford's algorithm and ignoring NaN values, and assigns results to a + provided output ndarray. Parameters ----------