From 68ca019450892f8321daecfc01b489d4521d8e88 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sat, 6 Dec 2025 21:40:28 +0530 Subject: [PATCH 01/16] stats/mskmax --- .../@stdlib/stats/mskmax/README.md | 286 ++++++ .../mskmax/benchmark/benchmark.assign.js | 121 +++ .../stats/mskmax/benchmark/benchmark.js | 117 +++ .../@stdlib/stats/mskmax/docs/repl.txt | 91 ++ .../stats/mskmax/docs/types/index.d.ts | 158 ++++ .../@stdlib/stats/mskmax/docs/types/test.ts | 225 +++++ .../@stdlib/stats/mskmax/examples/index.js | 55 ++ .../@stdlib/stats/mskmax/lib/index.js | 63 ++ .../@stdlib/stats/mskmax/lib/main.js | 113 +++ .../@stdlib/stats/mskmax/package.json | 67 ++ .../@stdlib/stats/mskmax/test/test.assign.js | 819 ++++++++++++++++ .../@stdlib/stats/mskmax/test/test.js | 39 + .../@stdlib/stats/mskmax/test/test.main.js | 872 ++++++++++++++++++ 13 files changed, 3026 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/mskmax/README.md create mode 100644 lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/mskmax/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/mskmax/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/package.json create mode 100644 lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/mskmax/test/test.main.js diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md new file mode 100644 index 000000000000..bb5886cf2010 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -0,0 +1,286 @@ + + +# mskmax + +> Compute the maximum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions according to a mask. + +
+ +## Usage + +```javascript +var mskmax = require( '@stdlib/stats/mskmax' ); +``` + +#### mskmax( x, mask\[, options] ) + +Compute the maximum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions according to a mask. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var mask = array( [ 0, 0, 1 ] ); + +var y = mskmax( x, mask ); +// returns + +var v = y.get(); +// returns 2.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]. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. +- **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 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, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +var mask = array( [ 0, 0, 1, 0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +var v = ndarray2array( x ); +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] + +var y = mskmax( x, mask, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ -1.0, 4.0 ] + +y = mskmax( x, mask, { + 'dims': [ 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ 2.0, 4.0 ] + +y = mskmax( x, mask, { + 'dims': [ 0, 1 ] +}); +// returns + +v = y.get(); +// returns 4.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, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +var mask = array( [ 0, 0, 1, 0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var v = ndarray2array( x ); +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] + +var y = mskmax( x, mask, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -1.0, 4.0 ] ] + +y = mskmax( x, mask, { + 'dims': [ 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 2.0 ], [ 4.0 ] ] + +y = mskmax( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 4.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, 2.0, -3.0 ], { + 'dtype': 'generic' +}); +var mask = array( [ 0, 0, 1 ] ); + +var y = mskmax( x, mask, { + 'dtype': 'float64' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'float64' +``` + +#### mskmax.assign( x, mask, out\[, options] ) + +Computes the maximum value of [ndarray][@stdlib/ndarray/ctor] along one or more dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor] according to mask. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var mask = array( [ 0, 0, 1 ] ); +var y = zeros( [] ); + +var out = mskmax.assign( x, mask, y ); +// returns + +var v = out.get(); +// returns 2.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]. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. +- **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 + +- 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 the same [data type][@stdlib/ndarray/dtypes] as the input [ndarray][@stdlib/ndarray/ctor]. 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var mskmax = require( '@stdlib/stats/mskmax' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// Generate a mask array: +var mbuf = discreteUniform( 25, 0, 1, { + 'dtype': 'generic' +}); + +// Wrap in ndarrays: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +var mask = new ndarray( 'generic', mbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); +console.log( ndarray2array( mask ) ); + +// Perform a reduction: +var y = mskmax( x, mask, { + '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/mskmax/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..893c8f6d95ab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var mskmax = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var mbuf; + var out; + var x; + var i; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + // Create a mask (mask out every 5th element): + mbuf = new Array( len ); + for ( i = 0; i < len; i++ ) { + mbuf[ i ] = ( i % 5 === 0 ) ? 1 : 0; + } + mask = new ndarray( 'uint8', mbuf, [ 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 = mskmax.assign( x, mask, out ); + 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/mskmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js new file mode 100644 index 000000000000..2a88b51867a1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.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 uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var mskmax = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var mbuf; + var x; + var i; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + // Create a mask (mask out every 5th element): + mbuf = new Array( len ); + for ( i = 0; i < len; i++ ) { + mbuf[ i ] = ( i % 5 === 0 ) ? 1 : 0; + } + mask = new ndarray( 'uint8', mbuf, [ 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 = mskmax( x, mask ); + 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/mskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt new file mode 100644 index 000000000000..aa5510a8454b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt @@ -0,0 +1,91 @@ + +{{alias}}( x, mask[, options] ) + Computes the maximum value along one or more ndarray dimensions + according to a mask. + + If a `mask` array element is `0`, the corresponding element in `x` is + considered valid and included in computation. + + If a `mask` array element is `1`, the corresponding element in `x` is + considered invalid/missing and excluded from computation. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + mask: ndarray + Mask array. Must have an integer data type and the same shape as `x`. + + options: Object (optional) + Function options. + + options.dtype: string (optional) + Output array data type. Must be a real-valued 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, 2.0, -3.0, 4.0 ] ); + > var mask = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 1, 0 ] ); + > var y = {{alias}}( x, mask ); + > var v = y.get() + 2.0 + + +{{alias}}.assign( x, mask, out[, options] ) + Computes the maximum value along one or more ndarray dimensions and assigns + results to a provided output ndarray according to a mask. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or generic data type. + + mask: ndarray + Mask array. Must have an integer data type and the same shape as `x`. + + 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, 2.0, -3.0, 4.0 ] ); + > var mask = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 1, 0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [] ); + > var y = {{alias}}.assign( x, mask, out ) + + > var bool = ( out === y ) + true + > var v = out.get() + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts new file mode 100644 index 000000000000..3d3ff74fe742 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts @@ -0,0 +1,158 @@ +/* +* @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 { RealAndGenericDataType 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. +*/ +interface Unary { + /** + * Computes the maximum value along one or more ndarray dimensions according to a mask. + * + * @param x - input ndarray + * @param mask - mask ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); + * var mask = array( [ 0, 0, 1, 0 ] ); + * + * var y = mskmax( x, mask ); + * // returns + * + * var v = y.get(); + * // returns 2.0 + */ + ( x: InputArray, mask: 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 maximum value along one or more ndarray dimensions and assigns results to a provided output ndarray according to a mask. + * + * @param x - input ndarray + * @param mask - mask 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, 2.0, -3.0, 4.0 ] ); + * var mask = array( [ 0, 0, 1, 0 ] ); + * var y = zeros( [] ); + * + * var out = mskmax.assign( x, mask, y ); + * // returns + * + * var v = out.get(); + * // returns 2.0 + * + * var bool = ( out === y ); + * // returns true + */ + assign = OutputArray>( x: InputArray, mask: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Computes the maximum value along one or more ndarray dimensions according to a mask. +* +* @param x - input ndarray +* @param mask - mask ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ) +* var mask = array( [ 0, 0, 1, 0 ] ); +* +* var y = mskmax( x, mask ); +* // returns +* +* var v = y.get(); +* // returns 2.0 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ) +* var mask = array( [ 0, 0, 1, 0 ] ); +* var y = zeros( [] ); +* +* var out = mskmax.assign( x, mask, y ); +* // returns +* +* var v = out.get(); +* // returns 2.0 +* +* var bool = ( out === y ); +* // returns true +*/ +declare const mskmax: Unary; + + +// EXPORTS // + +export = mskmax; diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/mskmax/docs/types/test.ts new file mode 100644 index 000000000000..24a831499f9c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/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 mskmax = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + mskmax( x ); // $ExpectType OutputArray + mskmax( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + mskmax( '5' ); // $ExpectError + mskmax( 5 ); // $ExpectError + mskmax( true ); // $ExpectError + mskmax( false ); // $ExpectError + mskmax( null ); // $ExpectError + mskmax( void 0 ); // $ExpectError + mskmax( {} ); // $ExpectError + mskmax( ( x: number ): number => x ); // $ExpectError + + mskmax( '5', {} ); // $ExpectError + mskmax( 5, {} ); // $ExpectError + mskmax( true, {} ); // $ExpectError + mskmax( false, {} ); // $ExpectError + mskmax( null, {} ); // $ExpectError + mskmax( void 0, {} ); // $ExpectError + mskmax( {}, {} ); // $ExpectError + mskmax( ( 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' + }); + + mskmax( x, '5' ); // $ExpectError + mskmax( x, true ); // $ExpectError + mskmax( x, false ); // $ExpectError + mskmax( x, null ); // $ExpectError + mskmax( x, [] ); // $ExpectError + mskmax( 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' + }); + + mskmax( x, { 'dtype': '5' } ); // $ExpectError + mskmax( x, { 'dtype': 5 } ); // $ExpectError + mskmax( x, { 'dtype': true } ); // $ExpectError + mskmax( x, { 'dtype': false } ); // $ExpectError + mskmax( x, { 'dtype': null } ); // $ExpectError + mskmax( x, { 'dtype': [] } ); // $ExpectError + mskmax( x, { 'dtype': {} } ); // $ExpectError + mskmax( 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' + }); + + mskmax( x, { 'keepdims': '5' } ); // $ExpectError + mskmax( x, { 'keepdims': 5 } ); // $ExpectError + mskmax( x, { 'keepdims': null } ); // $ExpectError + mskmax( x, { 'keepdims': [] } ); // $ExpectError + mskmax( x, { 'keepdims': {} } ); // $ExpectError + mskmax( 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' + }); + + mskmax( x, { 'dims': '5' } ); // $ExpectError + mskmax( x, { 'dims': 5 } ); // $ExpectError + mskmax( x, { 'dims': true } ); // $ExpectError + mskmax( x, { 'dims': false } ); // $ExpectError + mskmax( x, { 'dims': null } ); // $ExpectError + mskmax( x, { 'dims': {} } ); // $ExpectError + mskmax( 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' + }); + + mskmax(); // $ExpectError + mskmax( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + mskmax.assign( x, x ); // $ExpectType float64ndarray + mskmax.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' + }); + + mskmax.assign( '5', x ); // $ExpectError + mskmax.assign( 5, x ); // $ExpectError + mskmax.assign( true, x ); // $ExpectError + mskmax.assign( false, x ); // $ExpectError + mskmax.assign( null, x ); // $ExpectError + mskmax.assign( void 0, x ); // $ExpectError + mskmax.assign( {}, x ); // $ExpectError + mskmax.assign( ( x: number ): number => x, x ); // $ExpectError + + mskmax.assign( '5', x, {} ); // $ExpectError + mskmax.assign( 5, x, {} ); // $ExpectError + mskmax.assign( true, x, {} ); // $ExpectError + mskmax.assign( false, x, {} ); // $ExpectError + mskmax.assign( null, x, {} ); // $ExpectError + mskmax.assign( void 0, x, {} ); // $ExpectError + mskmax.assign( {}, x, {} ); // $ExpectError + mskmax.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' + }); + + mskmax.assign( x, '5' ); // $ExpectError + mskmax.assign( x, 5 ); // $ExpectError + mskmax.assign( x, true ); // $ExpectError + mskmax.assign( x, false ); // $ExpectError + mskmax.assign( x, null ); // $ExpectError + mskmax.assign( x, void 0 ); // $ExpectError + mskmax.assign( x, ( x: number ): number => x ); // $ExpectError + + mskmax.assign( x, '5', {} ); // $ExpectError + mskmax.assign( x, 5, {} ); // $ExpectError + mskmax.assign( x, true, {} ); // $ExpectError + mskmax.assign( x, false, {} ); // $ExpectError + mskmax.assign( x, null, {} ); // $ExpectError + mskmax.assign( x, void 0, {} ); // $ExpectError + mskmax.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' + }); + + mskmax.assign( x, x, '5' ); // $ExpectError + mskmax.assign( x, x, true ); // $ExpectError + mskmax.assign( x, x, false ); // $ExpectError + mskmax.assign( x, x, null ); // $ExpectError + mskmax.assign( x, x, [] ); // $ExpectError + mskmax.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' + }); + + mskmax.assign( x, x, { 'dims': '5' } ); // $ExpectError + mskmax.assign( x, x, { 'dims': 5 } ); // $ExpectError + mskmax.assign( x, x, { 'dims': true } ); // $ExpectError + mskmax.assign( x, x, { 'dims': false } ); // $ExpectError + mskmax.assign( x, x, { 'dims': null } ); // $ExpectError + mskmax.assign( x, x, { 'dims': {} } ); // $ExpectError + mskmax.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' + }); + + mskmax.assign(); // $ExpectError + mskmax.assign( x ); // $ExpectError + mskmax.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/mskmax/examples/index.js b/lib/node_modules/@stdlib/stats/mskmax/examples/index.js new file mode 100644 index 000000000000..e4ab38912d15 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/examples/index.js @@ -0,0 +1,55 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var mskmax = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Generate a mask (mask out random elements): +var mbuf = discreteUniform( 25, 0, 2, { + 'dtype': 'generic' +}); + +// Wrap mask in an ndarray: +var mask = new ndarray( 'uint8', mbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( mask ) ); + +// Perform a reduction: +var y = mskmax( x, mask, { + '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/mskmax/lib/index.js b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js new file mode 100644 index 000000000000..f50726c93dae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/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 maximum value along one or more ndarray dimensions according to a mask. +* +* @module @stdlib/stats/mskmax +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var mskmax = require( '@stdlib/stats/mskmax' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.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 = mskmax( x ); +* // returns +* +* var v = out.get(); +* // returns 11.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js new file mode 100644 index 000000000000..e6e23dfbb781 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js @@ -0,0 +1,113 @@ +/** +* @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 gmskmax = require( '@stdlib/stats/base/ndarray/mskmax' ); +var dmskmax = require( '@stdlib/stats/base/ndarray/dmskmax' ); +var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); +var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'real_and_generic' ); +var mdtypes = dtypes( 'integer' ); +var odtypes = dtypes( 'real_and_generic' ); +var policies = { + 'output': 'promoted', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', 'uint8', // dmskmax: x, mask + 'float32', 'uint8' // smskmax: x, mask + ], + 'fcns': [ + dmskmax, + smskmax + ], + 'default': gmskmax +}; + + +// MAIN // + +/** +* Computes the maximum value along one or more ndarray dimensions according to a mask. +* +* @name max +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} mask - mask 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} second 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 Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Create a mask buffer: +* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sm = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* var om = 0; +* +* // Create the input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create the mask ndarray: +* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); +* +* // Perform reduction: +* var out = mskmax( x, mask ); +* // returns +* +* var v = out.get(); +* // returns 5.0 +*/ +var mskmax = factory( table, [ idtypes, mdtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = mskmax; diff --git a/lib/node_modules/@stdlib/stats/mskmax/package.json b/lib/node_modules/@stdlib/stats/mskmax/package.json new file mode 100644 index 000000000000..a1890c8ee07a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/mskmax", + "version": "0.0.0", + "description": "Compute the maximum value along one or more ndarray dimensions according to a mask.", + "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", + "maximum", + "max", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js new file mode 100644 index 000000000000..d6cfec6cd178 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js @@ -0,0 +1,819 @@ +/** +* @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 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 mskmax = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmax, '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 mask; + var out; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( value, mask, 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 mask; + var out; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( value, mask, 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 mask; + var out; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( value, mask, 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 mask; + var out; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( value, mask, 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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() { + mskmax( x, mask, 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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() { + mskmax( x, mask, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { + var values; + var mask; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( x, mask, 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 mask; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( x, mask, 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 mask; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( x, mask, 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 mask; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( x, mask, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var mask; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + 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() { + mskmax( x, mask, 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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' + }); + mskmax( x, mask, 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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' + }); + mskmax( x, mask, 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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' + }); + mskmax( x, mask, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function performs a reduction on an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = mskmax( x, mask, out ); + expected = 2.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 mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = mskmax( x, mask, out ); + expected = 2.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 mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 0, 1 ] + }); + expected = 2.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 mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 0, 1 ] + }); + expected = 2.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 mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [] + }); + + t.strictEqual( actual, out, 'returns expected value' ); + var arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); + t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [] + }); + + t.strictEqual( actual, out, 'returns expected value' ); + var arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); + t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 0 ] + }); + expected = [ -1.0, 2.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 1 ] + }); + expected = [ 2.0, -3.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 mbuf; + var mask; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 0 ] + }); + expected = [ 2.0, -3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = mskmax( x, mask, out, { + 'dims': [ 1 ] + }); + expected = [ -1.0, 2.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/mskmax/test/test.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.js new file mode 100644 index 000000000000..e53eacc98f42 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/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 mskmax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( mskmax, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js new file mode 100644 index 000000000000..1fcd23c744fd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js @@ -0,0 +1,872 @@ +/** +* @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 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 mskmax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmax, '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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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() { + mskmax( 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 mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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() { + mskmax( x, mask, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + mask = zeros( [ 2, 2 ], { + 'dtype': 'uint8' + }); + + 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() { + mskmax( x, mask, { + '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() { + mskmax( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function performs a reduction on an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask ); + expected = 2.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 mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask ); + expected = 2.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 mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ] + }); + expected = 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 2.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 mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ] + }); + expected = 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 2.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 mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': false + }); + + 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' ); + var arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); + t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': true + }); + + 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' ); + arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); + t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var arr; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': false + }); + + 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' ); + arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); + t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': true + }); + + 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' ); + arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); + t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': false + }); + + 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' ); + var arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); + t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ -1.0, 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ 2.0, -3.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': true + }); + + 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' ); + arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); + t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function supports specifying reduction dimensions (column-major)', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ 2.0, -3.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ 2.0, -3.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': false + }); + + 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' ); + var arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); + t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dims': [], + 'keepdims': true + }); + + 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' ); + arr = ndarray2array( actual ); + t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); + t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); + t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); + t.ok( arr[1][1] !== arr[1][1], 'returns NaN for masked value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var mbuf; + var mask; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = mskmax( x, mask, { + 'dtype': 'float64' + }); + expected = 2.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, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + mbuf = [ 0, 0, 0, 1 ]; + mask = new ndarray( 'uint8', mbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = mskmax( x, mask, { + 'dtype': 'float64' + }); + expected = 2.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 425209102576c7fc3356f7d8a6c0a567919dcbdd Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sat, 6 Dec 2025 22:00:28 +0530 Subject: [PATCH 02/16] Fix documentation examples to use native Uint8Array instead of @stdlib/array/uint8 --- lib/node_modules/@stdlib/stats/mskmax/README.md | 15 ++++++++++----- .../@stdlib/stats/mskmax/docs/repl.txt | 6 +++--- .../@stdlib/stats/mskmax/docs/types/index.d.ts | 8 ++++---- .../@stdlib/stats/mskmax/lib/index.js | 11 +++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md index bb5886cf2010..dc5783479d63 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/README.md +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -35,10 +35,11 @@ var mskmax = require( '@stdlib/stats/mskmax' ); Compute the maximum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions according to a mask. ```javascript +var Uint8Array = require( '@stdlib/array/uint8' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ -1.0, 2.0, -3.0 ] ); -var mask = array( [ 0, 0, 1 ] ); +var mask = array( new Uint8Array( [ 0, 0, 1 ] ) ); var y = mskmax( x, mask ); // returns @@ -62,6 +63,7 @@ The function accepts the following options: 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 mskmax = require( '@stdlib/stats/mskmax' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); @@ -69,7 +71,7 @@ var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { 'shape': [ 2, 2 ], 'order': 'row-major' }); -var mask = array( [ 0, 0, 1, 0 ], { +var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ), { 'shape': [ 2, 2 ], 'order': 'row-major' }); @@ -104,6 +106,7 @@ v = y.get(); 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 mskmax = require( '@stdlib/stats/mskmax' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); @@ -111,7 +114,7 @@ var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { 'shape': [ 2, 2 ], 'order': 'row-major' }); -var mask = array( [ 0, 0, 1, 0 ], { +var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ), { 'shape': [ 2, 2 ], 'order': 'row-major' }); @@ -150,13 +153,14 @@ v = ndarray2array( y ); 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 mskmax = require( '@stdlib/stats/mskmax' ); var getDType = require( '@stdlib/ndarray/dtype' ); var array = require( '@stdlib/ndarray/array' ); var x = array( [ -1.0, 2.0, -3.0 ], { 'dtype': 'generic' }); -var mask = array( [ 0, 0, 1 ] ); +var mask = array( new Uint8Array( [ 0, 0, 1 ] ) ); var y = mskmax( x, mask, { 'dtype': 'float64' @@ -172,11 +176,12 @@ var dt = String( getDType( y ) ); Computes the maximum value of [ndarray][@stdlib/ndarray/ctor] along one or more dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor] according to mask. ```javascript +var mskmax = require( '@stdlib/stats/mskmax' ); var array = require( '@stdlib/ndarray/array' ); var zeros = require( '@stdlib/ndarray/zeros' ); var x = array( [ -1.0, 2.0, -3.0 ] ); -var mask = array( [ 0, 0, 1 ] ); +var mask = array( new Uint8Array( [ 0, 0, 1 ] ) ); var y = zeros( [] ); var out = mskmax.assign( x, mask, y ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt index aa5510a8454b..88b9a69eb837 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt @@ -34,13 +34,13 @@ Returns ------- - out: ndarray + y: ndarray Output array. Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, 4.0 ] ); - > var mask = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 1, 0 ] ); + > var mask = {{alias:@stdlib/ndarray/array}}( new Uint8Array( [ 0, 0, 1, 0 ] ) ); > var y = {{alias}}( x, mask ); > var v = y.get() 2.0 @@ -77,7 +77,7 @@ Examples -------- > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, 4.0 ] ); - > var mask = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 1, 0 ] ); + > var mask = {{alias:@stdlib/ndarray/array}}( new Uint8Array( [ 0, 0, 1, 0 ] ) ); > var out = {{alias:@stdlib/ndarray/zeros}}( [] ); > var y = {{alias}}.assign( x, mask, out ) diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts index 3d3ff74fe742..d84e88978901 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts @@ -74,7 +74,7 @@ interface Unary { * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); - * var mask = array( [ 0, 0, 1, 0 ] ); + * var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ) ); * * var y = mskmax( x, mask ); * // returns @@ -98,7 +98,7 @@ interface Unary { * var zeros = require( '@stdlib/ndarray/zeros' ); * * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ); - * var mask = array( [ 0, 0, 1, 0 ] ); + * var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ) ); * var y = zeros( [] ); * * var out = mskmax.assign( x, mask, y ); @@ -125,7 +125,7 @@ interface Unary { * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ) -* var mask = array( [ 0, 0, 1, 0 ] ); +* var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ) ); * * var y = mskmax( x, mask ); * // returns @@ -138,7 +138,7 @@ interface Unary { * var zeros = require( '@stdlib/ndarray/zeros' ); * * var x = array( [ -1.0, 2.0, -3.0, 4.0 ] ) -* var mask = array( [ 0, 0, 1, 0 ] ); +* var mask = array( new Uint8Array( [ 0, 0, 1, 0 ] ) ); * var y = zeros( [] ); * * var out = mskmax.assign( x, mask, y ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js index f50726c93dae..7533bff43bd7 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js @@ -25,12 +25,16 @@ * * @example * var Float64Array = require( '@stdlib/array/float64' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * var mskmax = require( '@stdlib/stats/mskmax' ); * * // Create a data buffer: * var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.0 ] ); * +* // Create a mask buffer: +* var mbuf = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ] ); +* * // Define the shape of the input array: * var sh = [ 3, 1, 2 ]; * @@ -43,12 +47,15 @@ * // Create an input ndarray: * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * +* // Create a mask ndarray: +* var mask = new ndarray( 'uint8', mbuf, sh, sx, ox, 'row-major' ); +* * // Perform reduction: -* var out = mskmax( x ); +* var out = mskmax( x, mask ); * // returns * * var v = out.get(); -* // returns 11.0 +* // returns 10.0 */ // MODULES // From 83f5c1478eea23d6deb952a80625fa75329fdebf Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 15:44:43 +0530 Subject: [PATCH 03/16] fix: examples updated --- lib/node_modules/@stdlib/stats/mskmax/README.md | 8 ++++++-- lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt | 8 ++++---- .../@stdlib/stats/mskmax/docs/types/index.d.ts | 8 ++++---- lib/node_modules/@stdlib/stats/mskmax/examples/index.js | 4 ++-- lib/node_modules/@stdlib/stats/mskmax/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/mskmax/lib/main.js | 8 +++++--- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md index dc5783479d63..9e2b01340959 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/README.md +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -37,6 +37,7 @@ Compute the maximum value along one or more [ndarray][@stdlib/ndarray/ctor] dime ```javascript var Uint8Array = require( '@stdlib/array/uint8' ); var array = require( '@stdlib/ndarray/array' ); +var mskmax = require( '@stdlib/stats/mskmax' ); var x = array( [ -1.0, 2.0, -3.0 ] ); var mask = array( new Uint8Array( [ 0, 0, 1 ] ) ); @@ -106,6 +107,7 @@ v = y.get(); 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 Uint8Array = require( '@stdlib/array/uint8' ); var mskmax = require( '@stdlib/stats/mskmax' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); @@ -153,6 +155,7 @@ v = ndarray2array( y ); 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 Uint8Array = require( '@stdlib/array/uint8' ); var mskmax = require( '@stdlib/stats/mskmax' ); var getDType = require( '@stdlib/ndarray/dtype' ); var array = require( '@stdlib/ndarray/array' ); @@ -176,6 +179,7 @@ var dt = String( getDType( y ) ); Computes the maximum value of [ndarray][@stdlib/ndarray/ctor] along one or more dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor] according to mask. ```javascript +var Uint8Array = require( '@stdlib/array/uint8' ); var mskmax = require( '@stdlib/stats/mskmax' ); var array = require( '@stdlib/ndarray/array' ); var zeros = require( '@stdlib/ndarray/zeros' ); @@ -240,12 +244,12 @@ var xbuf = discreteUniform( 25, 0, 20, { // Generate a mask array: var mbuf = discreteUniform( 25, 0, 1, { - 'dtype': 'generic' + 'dtype': 'uint8' }); // Wrap in ndarrays: var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); -var mask = new ndarray( 'generic', mbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +var mask = new ndarray( 'uint8', mbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); console.log( ndarray2array( mask ) ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt index 88b9a69eb837..3683db427347 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/repl.txt @@ -2,13 +2,13 @@ {{alias}}( x, mask[, options] ) Computes the maximum value along one or more ndarray dimensions according to a mask. - + If a `mask` array element is `0`, the corresponding element in `x` is considered valid and included in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and excluded from computation. - + Parameters ---------- x: ndarray @@ -43,7 +43,7 @@ > var mask = {{alias:@stdlib/ndarray/array}}( new Uint8Array( [ 0, 0, 1, 0 ] ) ); > var y = {{alias}}( x, mask ); > var v = y.get() - 2.0 + 4.0 {{alias}}.assign( x, mask, out[, options] ) @@ -84,7 +84,7 @@ > var bool = ( out === y ) true > var v = out.get() - 2.0 + 4.0 See Also -------- diff --git a/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts index d84e88978901..4373d4390377 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/mskmax/docs/types/index.d.ts @@ -80,7 +80,7 @@ interface Unary { * // returns * * var v = y.get(); - * // returns 2.0 + * // returns 4.0 */ ( x: InputArray, mask: 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`. @@ -105,7 +105,7 @@ interface Unary { * // returns * * var v = out.get(); - * // returns 2.0 + * // returns 4.0 * * var bool = ( out === y ); * // returns true @@ -131,7 +131,7 @@ interface Unary { * // returns * * var v = y.get(); -* // returns 2.0 +* // returns 4.0 * * @example * var array = require( '@stdlib/ndarray/array' ); @@ -145,7 +145,7 @@ interface Unary { * // returns * * var v = out.get(); -* // returns 2.0 +* // returns 4.0 * * var bool = ( out === y ); * // returns true diff --git a/lib/node_modules/@stdlib/stats/mskmax/examples/index.js b/lib/node_modules/@stdlib/stats/mskmax/examples/index.js index e4ab38912d15..d459cb992d70 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/examples/index.js +++ b/lib/node_modules/@stdlib/stats/mskmax/examples/index.js @@ -34,8 +34,8 @@ var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Generate a mask (mask out random elements): -var mbuf = discreteUniform( 25, 0, 2, { - 'dtype': 'generic' +var mbuf = discreteUniform( 25, 0, 1, { + 'dtype': 'uint8' }); // Wrap mask in an ndarray: diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js index 7533bff43bd7..1113894489b2 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js @@ -33,7 +33,7 @@ * var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.0 ] ); * * // Create a mask buffer: -* var mbuf = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ] ); +* var mbuf = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ] ); // eslint-disable-line id-length * * // Define the shape of the input array: * var sh = [ 3, 1, 2 ]; diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js index e6e23dfbb781..342055c95643 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js @@ -38,8 +38,10 @@ var policies = { }; var table = { 'types': [ - 'float64', 'uint8', // dmskmax: x, mask - 'float32', 'uint8' // smskmax: x, mask + 'float64', + 'uint8', // dmskmax: x, mask + 'float32', + 'uint8' // smskmax: x, mask ], 'fcns': [ dmskmax, @@ -79,7 +81,7 @@ var table = { * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * // Create a mask buffer: -* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); +* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); // eslint-disable-line id-length * * // Define the shape of the input array: * var sh = [ 3, 2 ]; From de416fd4c065a10f58fad2524fe71bf7799ce10d Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 15:56:48 +0530 Subject: [PATCH 04/16] fix: import added --- lib/node_modules/@stdlib/stats/mskmax/README.md | 1 + lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md index 9e2b01340959..9dff7ec21c6b 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/README.md +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -64,6 +64,7 @@ The function accepts the following options: 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 Uint8Array = require( '@stdlib/array/uint8' ); var mskmax = require( '@stdlib/stats/mskmax' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js index d6cfec6cd178..56042b75ce73 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js +++ b/lib/node_modules/@stdlib/stats/mskmax/test/test.assign.js @@ -663,12 +663,12 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m }); tape( 'the function performs a reduction on an ndarray (no dimensions, row-major)', function test( t ) { - var expected; var actual; var mbuf; var mask; var xbuf; var out; + var arr; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; @@ -686,7 +686,7 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major }); t.strictEqual( actual, out, 'returns expected value' ); - var arr = ndarray2array( actual ); + arr = ndarray2array( actual ); t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); @@ -696,12 +696,12 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major }); tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { - var expected; var actual; var mbuf; var mask; var xbuf; var out; + var arr; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; @@ -719,7 +719,7 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, column-ma }); t.strictEqual( actual, out, 'returns expected value' ); - var arr = ndarray2array( actual ); + arr = ndarray2array( actual ); t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); From 2719c4b4a86ff18907999c2197322dc7c343ad79 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 16:07:20 +0530 Subject: [PATCH 05/16] fix: lint --- lib/node_modules/@stdlib/stats/mskmax/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/mskmax/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/mskmax/test/test.main.js | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js index 1113894489b2..5e268d873f85 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js @@ -48,7 +48,7 @@ * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create a mask ndarray: -* var mask = new ndarray( 'uint8', mbuf, sh, sx, ox, 'row-major' ); +* var mask = new ndarray( 'uint8', mbuf, sh, sx, ox, 'row-major' ); // eslint-disable-line id-length, stdlib/jsdoc-cspell-check * * // Perform reduction: * var out = mskmax( x, mask ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js index 342055c95643..a9118fcaa7d8 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js @@ -98,7 +98,7 @@ var table = { * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create the mask ndarray: -* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); +* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); // eslint-disable-line id-length, stdlib/jsdoc-cspell-check * * // Perform reduction: * var out = mskmax( x, mask ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js index 1fcd23c744fd..8e1af8483bdb 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js @@ -542,11 +542,11 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m }); tape( 'the function performs a reduction on an ndarray (no dimensions, row-major)', function test( t ) { - var expected; var actual; var mbuf; var mask; var xbuf; + var arr; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; @@ -564,7 +564,7 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major 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' ); - var arr = ndarray2array( actual ); + arr = ndarray2array( actual ); t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); @@ -595,7 +595,6 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major }); tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { - var expected; var actual; var mbuf; var mask; @@ -654,6 +653,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct var mbuf; var mask; var xbuf; + var arr; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; @@ -743,6 +743,7 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu var mbuf; var mask; var xbuf; + var arr; var x; xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; @@ -796,7 +797,7 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 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' ); - var arr = ndarray2array( actual ); + arr = ndarray2array( actual ); t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); t.strictEqual( arr[0][1], -3.0, 'returns expected value' ); t.strictEqual( arr[1][0], 2.0, 'returns expected value' ); From 4b59b7e767a50eda920f9e504e79935dc4787e7b Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 16:17:44 +0530 Subject: [PATCH 06/16] fix: lint --- lib/node_modules/@stdlib/stats/mskmax/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/mskmax/lib/main.js | 2 +- .../@stdlib/stats/mskmax/test/test.main.js | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js index 5e268d873f85..c04de4252ffd 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/index.js @@ -48,7 +48,7 @@ * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create a mask ndarray: -* var mask = new ndarray( 'uint8', mbuf, sh, sx, ox, 'row-major' ); // eslint-disable-line id-length, stdlib/jsdoc-cspell-check +* var mask = new ndarray( 'uint8', mbuf, sh, sx, ox, 'row-major' ); // cspell:disable-line * * // Perform reduction: * var out = mskmax( x, mask ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js index a9118fcaa7d8..c41dcb76f5c0 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js @@ -98,7 +98,7 @@ var table = { * var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * * // Create the mask ndarray: -* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); // eslint-disable-line id-length, stdlib/jsdoc-cspell-check +* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); // cspell:disable-line * * // Perform reduction: * var out = mskmax( x, mask ); diff --git a/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js index 8e1af8483bdb..5256254d6be4 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/test/test.main.js @@ -543,9 +543,9 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m tape( 'the function performs a reduction on an ndarray (no dimensions, row-major)', function test( t ) { var actual; + var xbuf; var mbuf; var mask; - var xbuf; var arr; var x; @@ -596,9 +596,9 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major tape( 'the function performs a reduction on an ndarray (no dimensions, column-major)', function test( t ) { var actual; + var xbuf; var mbuf; var mask; - var xbuf; var arr; var x; @@ -650,9 +650,9 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, column-ma tape( 'the function supports specifying reduction dimensions (row-major)', function test( t ) { var expected; var actual; + var xbuf; var mbuf; var mask; - var xbuf; var arr; var x; @@ -671,7 +671,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 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' ); - var arr = ndarray2array( actual ); + arr = ndarray2array( actual ); t.strictEqual( arr[0][0], -1.0, 'returns expected value' ); t.strictEqual( arr[0][1], 2.0, 'returns expected value' ); t.strictEqual( arr[1][0], -3.0, 'returns expected value' ); @@ -740,9 +740,9 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct tape( 'the function supports specifying reduction dimensions (column-major)', function test( t ) { var expected; var actual; + var xbuf; var mbuf; var mask; - var xbuf; var arr; var x; From 2b738a6dbf6da050346a749f80352f9fc44e0172 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 16:29:17 +0530 Subject: [PATCH 07/16] fix: lint --- .../@stdlib/stats/mskmax/benchmark/benchmark.assign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js index 893c8f6d95ab..674f055d30d6 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.assign.js @@ -57,9 +57,9 @@ function createBenchmark( len ) { x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); // Create a mask (mask out every 5th element): - mbuf = new Array( len ); + mbuf = []; for ( i = 0; i < len; i++ ) { - mbuf[ i ] = ( i % 5 === 0 ) ? 1 : 0; + mbuf.push( ( i % 5 === 0 ) ? 1 : 0 ); } mask = new ndarray( 'uint8', mbuf, [ len ], [ 1 ], 0, 'row-major' ); From 26bf0d28554d04ad54a923d2f11bcaddb38d0a70 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 16:36:37 +0530 Subject: [PATCH 08/16] fix: lint --- lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js index 2a88b51867a1..7b99e9b1c45e 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/mskmax/benchmark/benchmark.js @@ -55,9 +55,9 @@ function createBenchmark( len ) { x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); // Create a mask (mask out every 5th element): - mbuf = new Array( len ); + mbuf = []; for ( i = 0; i < len; i++ ) { - mbuf[ i ] = ( i % 5 === 0 ) ? 1 : 0; + mbuf.push( ( i % 5 === 0 ) ? 1 : 0 ); } mask = new ndarray( 'uint8', mbuf, [ len ], [ 1 ], 0, 'row-major' ); From 59061c4cceafd75366e00a2bb29dc3d6751f15e2 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 8 Dec 2025 19:47:00 -0800 Subject: [PATCH 09/16] docs: update example Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/mskmax/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md index 9dff7ec21c6b..99fcd4f5ec0f 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/README.md +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -37,7 +37,6 @@ Compute the maximum value along one or more [ndarray][@stdlib/ndarray/ctor] dime ```javascript var Uint8Array = require( '@stdlib/array/uint8' ); var array = require( '@stdlib/ndarray/array' ); -var mskmax = require( '@stdlib/stats/mskmax' ); var x = array( [ -1.0, 2.0, -3.0 ] ); var mask = array( new Uint8Array( [ 0, 0, 1 ] ) ); From f279faa30273950f78010dbd8fb60cc3599f510d Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 5 Dec 2025 14:52:13 +0530 Subject: [PATCH 10/16] stats/meanpw --- .../@stdlib/stats/meanpw/README.md | 304 +++++++ .../meanpw/benchmark/benchmark.assign.js | 111 +++ .../stats/meanpw/benchmark/benchmark.js | 105 +++ .../@stdlib/stats/meanpw/docs/repl.txt | 79 ++ .../stats/meanpw/docs/types/index.d.ts | 151 ++++ .../@stdlib/stats/meanpw/docs/types/test.ts | 225 ++++++ .../@stdlib/stats/meanpw/examples/index.js | 46 ++ .../@stdlib/stats/meanpw/lib/index.js | 63 ++ .../@stdlib/stats/meanpw/lib/main.js | 101 +++ .../@stdlib/stats/meanpw/package.json | 67 ++ .../@stdlib/stats/meanpw/test/test.assign.js | 717 +++++++++++++++++ .../@stdlib/stats/meanpw/test/test.js | 39 + .../@stdlib/stats/meanpw/test/test.main.js | 753 ++++++++++++++++++ 13 files changed, 2761 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/meanpw/README.md create mode 100644 lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/meanpw/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/meanpw/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/package.json create mode 100644 lib/node_modules/@stdlib/stats/meanpw/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/meanpw/test/test.main.js diff --git a/lib/node_modules/@stdlib/stats/meanpw/README.md b/lib/node_modules/@stdlib/stats/meanpw/README.md new file mode 100644 index 000000000000..6b5d4c6dfe7a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/README.md @@ -0,0 +1,304 @@ + + +# meanpw + +> Compute the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using pairwise summation. + +
+ +The [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var meanpw = require( '@stdlib/stats/meanpw' ); +``` + +#### meanpw( x\[, options] ) + +Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using pairwise summation. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, -2.0, 4.0 ] ); + +var y = meanpw( x ); +// returns + +var v = y.get(); +// returns 1.25 +``` + +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, 2.0, -2.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +var v = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ -2.0, 4.0 ] ] + +var y = meanpw( x, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ -0.5, 3.0 ] + +y = meanpw( x, { + 'dims': [ 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ 1.5, 1.0 ] + +y = meanpw( x, { + 'dims': [ 0, 1 ] +}); +// returns + +v = y.get(); +// returns 1.25 +``` + +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, 2.0, -2.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var v = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ -2.0, 4.0 ] ] + +var y = meanpw( x, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -0.5, 3.0 ] ] + +y = meanpw( x, { + 'dims': [ 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 1.5 ], [ 1.0 ] ] + +y = meanpw( x, { + 'dims': [ 0, 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 1.25 ] ] +``` + +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, 2.0, -2.0, 4.0 ], { + 'dtype': 'generic' +}); + +var y = meanpw( x, { + 'dtype': 'float64' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'float64' +``` + +#### meanpw.assign( x, out\[, options] ) + +Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions, using pairwise summation, 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, 2.0, -2.0, 4.0 ] ); +var y = zeros( [] ); + +var out = meanpw.assign( x, y ); +// returns + +var v = out.get(); +// returns 1.25 + +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 + +- 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]. +- In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var meanpw = require( '@stdlib/stats/meanpw' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// 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 = meanpw( x, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); +``` + +
+ + + +* * * + +
+ +## References + +- Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050][@higham:1993a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..d60d5698c993 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.assign.js @@ -0,0 +1,111 @@ +/** +* @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/array/uniform' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var meanpw = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = uniform( len, -50.0, 50.0, options ); + 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 = meanpw.assign( x, out ); + 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/meanpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.js new file mode 100644 index 000000000000..b7a62040bb97 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @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/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var meanpw = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -50.0, 50.0, options ); + 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 = meanpw( 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/meanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt new file mode 100644 index 000000000000..dd84aeb9a634 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt @@ -0,0 +1,79 @@ + +{{alias}}( x[, options] ) + Computes the arithmetic mean along one or more ndarray dimensions + using pairwise summation. + + 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, 2.0, -3.0, -4.0 ] ); + > var y = {{alias}}( x ); + > var v = y.get() + -1.5 + + +{{alias}}.assign( x, out[, options] ) + Computes the arithmetic mean along one or more ndarray dimensions, + using pairwise summation, 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, 2.0, -3.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.5 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts new file mode 100644 index 000000000000..b8b33c9b1f36 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/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. +*/ +interface Unary { + /** + * Computes the arithmetic mean along one or more ndarray dimensions using pairwise summation. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 1.0, 2.0, -2.0, 4.0 ] ); + * + * var y = meanpw( x ); + * // returns + * + * var v = y.get(); + * // returns 1.25 + */ + ( 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 pairwise summation, 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, 2.0, -2.0, 4.0 ] ); + * var y = zeros( [] ); + * + * var out = meanpw.assign( x, y ); + * // returns + * + * var v = out.get(); + * // returns 1.25 + * + * 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 pairwise summation. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, -2.0, 4.0 ] ); +* +* var y = meanpw( x ); +* // returns +* +* var v = y.get(); +* // returns 1.25 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ 1.0, 2.0, -2.0, 4.0 ] ); +* var y = zeros( [] ); +* +* var out = meanpw.assign( x, y ); +* // returns +* +* var v = out.get(); +* // returns 1.25 +* +* var bool = ( out === y ); +* // returns true +*/ +declare const meanpw: Unary; + + +// EXPORTS // + +export = meanpw; diff --git a/lib/node_modules/@stdlib/stats/meanpw/docs/types/test.ts b/lib/node_modules/@stdlib/stats/meanpw/docs/types/test.ts new file mode 100644 index 000000000000..558dfb7a1b0c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/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 meanpw = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + meanpw( x ); // $ExpectType OutputArray + meanpw( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + meanpw( '5' ); // $ExpectError + meanpw( 5 ); // $ExpectError + meanpw( true ); // $ExpectError + meanpw( false ); // $ExpectError + meanpw( null ); // $ExpectError + meanpw( void 0 ); // $ExpectError + meanpw( {} ); // $ExpectError + meanpw( ( x: number ): number => x ); // $ExpectError + + meanpw( '5', {} ); // $ExpectError + meanpw( 5, {} ); // $ExpectError + meanpw( true, {} ); // $ExpectError + meanpw( false, {} ); // $ExpectError + meanpw( null, {} ); // $ExpectError + meanpw( void 0, {} ); // $ExpectError + meanpw( {}, {} ); // $ExpectError + meanpw( ( 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' + }); + + meanpw( x, '5' ); // $ExpectError + meanpw( x, true ); // $ExpectError + meanpw( x, false ); // $ExpectError + meanpw( x, null ); // $ExpectError + meanpw( x, [] ); // $ExpectError + meanpw( 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' + }); + + meanpw( x, { 'dtype': '5' } ); // $ExpectError + meanpw( x, { 'dtype': 5 } ); // $ExpectError + meanpw( x, { 'dtype': true } ); // $ExpectError + meanpw( x, { 'dtype': false } ); // $ExpectError + meanpw( x, { 'dtype': null } ); // $ExpectError + meanpw( x, { 'dtype': [] } ); // $ExpectError + meanpw( x, { 'dtype': {} } ); // $ExpectError + meanpw( 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' + }); + + meanpw( x, { 'keepdims': '5' } ); // $ExpectError + meanpw( x, { 'keepdims': 5 } ); // $ExpectError + meanpw( x, { 'keepdims': null } ); // $ExpectError + meanpw( x, { 'keepdims': [] } ); // $ExpectError + meanpw( x, { 'keepdims': {} } ); // $ExpectError + meanpw( 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' + }); + + meanpw( x, { 'dims': '5' } ); // $ExpectError + meanpw( x, { 'dims': 5 } ); // $ExpectError + meanpw( x, { 'dims': true } ); // $ExpectError + meanpw( x, { 'dims': false } ); // $ExpectError + meanpw( x, { 'dims': null } ); // $ExpectError + meanpw( x, { 'dims': {} } ); // $ExpectError + meanpw( 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' + }); + + meanpw(); // $ExpectError + meanpw( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + meanpw.assign( x, x ); // $ExpectType float64ndarray + meanpw.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' + }); + + meanpw.assign( '5', x ); // $ExpectError + meanpw.assign( 5, x ); // $ExpectError + meanpw.assign( true, x ); // $ExpectError + meanpw.assign( false, x ); // $ExpectError + meanpw.assign( null, x ); // $ExpectError + meanpw.assign( void 0, x ); // $ExpectError + meanpw.assign( {}, x ); // $ExpectError + meanpw.assign( ( x: number ): number => x, x ); // $ExpectError + + meanpw.assign( '5', x, {} ); // $ExpectError + meanpw.assign( 5, x, {} ); // $ExpectError + meanpw.assign( true, x, {} ); // $ExpectError + meanpw.assign( false, x, {} ); // $ExpectError + meanpw.assign( null, x, {} ); // $ExpectError + meanpw.assign( void 0, x, {} ); // $ExpectError + meanpw.assign( {}, x, {} ); // $ExpectError + meanpw.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' + }); + + meanpw.assign( x, '5' ); // $ExpectError + meanpw.assign( x, 5 ); // $ExpectError + meanpw.assign( x, true ); // $ExpectError + meanpw.assign( x, false ); // $ExpectError + meanpw.assign( x, null ); // $ExpectError + meanpw.assign( x, void 0 ); // $ExpectError + meanpw.assign( x, ( x: number ): number => x ); // $ExpectError + + meanpw.assign( x, '5', {} ); // $ExpectError + meanpw.assign( x, 5, {} ); // $ExpectError + meanpw.assign( x, true, {} ); // $ExpectError + meanpw.assign( x, false, {} ); // $ExpectError + meanpw.assign( x, null, {} ); // $ExpectError + meanpw.assign( x, void 0, {} ); // $ExpectError + meanpw.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' + }); + + meanpw.assign( x, x, '5' ); // $ExpectError + meanpw.assign( x, x, true ); // $ExpectError + meanpw.assign( x, x, false ); // $ExpectError + meanpw.assign( x, x, null ); // $ExpectError + meanpw.assign( x, x, [] ); // $ExpectError + meanpw.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' + }); + + meanpw.assign( x, x, { 'dims': '5' } ); // $ExpectError + meanpw.assign( x, x, { 'dims': 5 } ); // $ExpectError + meanpw.assign( x, x, { 'dims': true } ); // $ExpectError + meanpw.assign( x, x, { 'dims': false } ); // $ExpectError + meanpw.assign( x, x, { 'dims': null } ); // $ExpectError + meanpw.assign( x, x, { 'dims': {} } ); // $ExpectError + meanpw.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' + }); + + meanpw.assign(); // $ExpectError + meanpw.assign( x ); // $ExpectError + meanpw.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js new file mode 100644 index 000000000000..a6417e8cd839 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var meanpw = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// 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 = meanpw( 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/meanpw/lib/index.js b/lib/node_modules/@stdlib/stats/meanpw/lib/index.js new file mode 100644 index 000000000000..d4d674ee9d75 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/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 using pairwise summation. +* +* @module @stdlib/stats/meanpw +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var meanpw = require( '@stdlib/stats/meanpw' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.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 = meanpw( x ); +* // returns +* +* var v = out.get(); +* // returns 6.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/meanpw/lib/main.js b/lib/node_modules/@stdlib/stats/meanpw/lib/main.js new file mode 100644 index 000000000000..cf2239f6f2ca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/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 gmeanpw = require( '@stdlib/stats/base/ndarray/meanpw' ); +var dmeanpw = require( '@stdlib/stats/base/ndarray/dmeanpw' ); +var smeanpw = require( '@stdlib/stats/base/ndarray/smeanpw' ); +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': [ + dmeanpw, + smeanpw + ], + 'default': gmeanpw +}; + + +// MAIN // + +/** +* Computes the arithmetic mean along one or more ndarray dimensions using pairwise summation. +* +* @name mean +* @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( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.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 = meanpw( x ); +* // returns +* +* var v = out.get(); +* // returns 6.5 +*/ +var meanpw = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = meanpw; diff --git a/lib/node_modules/@stdlib/stats/meanpw/package.json b/lib/node_modules/@stdlib/stats/meanpw/package.json new file mode 100644 index 000000000000..703d9bc73952 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/meanpw", + "version": "0.0.0", + "description": "Compute the arithmetic mean along one or more ndarray dimensions using pairwise summation.", + "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", + "central tendency", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/meanpw/test/test.assign.js b/lib/node_modules/@stdlib/stats/meanpw/test/test.assign.js new file mode 100644 index 000000000000..d5488e64ac56 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/test/test.assign.js @@ -0,0 +1,717 @@ +/** +* @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 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 meanpw = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof meanpw, '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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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' + }); + meanpw( 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' + }); + meanpw( 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' + }); + meanpw( 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = meanpw( x, out ); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = meanpw( x, out ); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = meanpw( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [] + }); + + actual = meanpw( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [] + }); + expected = [ [ 1.0, 2.0 ], [ -2.0, 4.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, '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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2, 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [] + }); + expected = [ [ 1.0, -2.0 ], [ 2.0, 4.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 (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [ 0 ] + }); + expected = [ -0.5, 3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [ 1 ] + }); + expected = [ 1.5, 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [ 0 ] + }); + expected = [ 1.5, 1.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x, { + 'shape': [ 2 ] + }); + + actual = meanpw( x, out, { + 'dims': [ 1 ] + }); + expected = [ -0.5, 3.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/meanpw/test/test.js b/lib/node_modules/@stdlib/stats/meanpw/test/test.js new file mode 100644 index 000000000000..77182b89ef17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/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 meanpw = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof meanpw, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( meanpw, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/meanpw/test/test.main.js b/lib/node_modules/@stdlib/stats/meanpw/test/test.main.js new file mode 100644 index 000000000000..4ad825b1aa46 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/meanpw/test/test.main.js @@ -0,0 +1,753 @@ +/** +* @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 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 meanpw = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof meanpw, '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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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() { + meanpw( 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x ); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x ); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ] + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 1.25 ] ]; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ] + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 1.25 ] ]; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, 2.0 ], [ -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' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, 2.0 ], [ -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' ); + t.deepEqual( ndarray2array( actual ), expected, '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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, -2.0 ], [ 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' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, -2.0 ], [ 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' ); + t.deepEqual( ndarray2array( actual ), expected, '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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ -0.5, 3.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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ -0.5, 3.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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ 1.5, 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ 1.5 ], [ 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ 1.5, 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ 1.5, 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ -0.5, 3.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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ -0.5 ], [ 3.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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = meanpw( x, { + 'dtype': 'float64' + }); + expected = 1.25; + + 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, 2.0, -2.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = meanpw( x, { + 'dtype': 'float64' + }); + expected = 1.25; + + 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 c437bea2b8b03e40b059c4cf1fa02d5fc18c9d06 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 04:26:28 -0800 Subject: [PATCH 11/16] docs: update desc Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/meanpw/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/meanpw/README.md b/lib/node_modules/@stdlib/stats/meanpw/README.md index 6b5d4c6dfe7a..7a20a2d93fa5 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/README.md +++ b/lib/node_modules/@stdlib/stats/meanpw/README.md @@ -179,7 +179,7 @@ var dt = String( getDType( y ) ); #### meanpw.assign( x, out\[, options] ) -Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions, using pairwise summation, and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. +Computes the [arithmetic mean][arithmetic-mean] along one or more [ndarray][@stdlib/ndarray/ctor] dimensions using pairwise summation and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. ```javascript var array = require( '@stdlib/ndarray/array' ); From a28cff6654471117645015612805223574312852 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 15:05:41 +0530 Subject: [PATCH 12/16] fix: changes done --- lib/node_modules/@stdlib/stats/meanpw/README.md | 11 ++++------- lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt | 9 ++++----- .../@stdlib/stats/meanpw/docs/types/index.d.ts | 2 +- .../@stdlib/stats/meanpw/examples/index.js | 11 ++++------- lib/node_modules/@stdlib/stats/meanpw/lib/main.js | 2 +- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/meanpw/README.md b/lib/node_modules/@stdlib/stats/meanpw/README.md index 7a20a2d93fa5..c42f0515362e 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/README.md +++ b/lib/node_modules/@stdlib/stats/meanpw/README.md @@ -231,19 +231,16 @@ The method accepts the following options: ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); var meanpw = require( '@stdlib/stats/meanpw' ); // Generate an array of random numbers: -var xbuf = discreteUniform( 25, 0, 20, { - 'dtype': 'generic' +var x = array( uniform( 25, 0.0, 20.0 ), { + 'shape': [ 5, 5 ] }); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Perform a reduction: diff --git a/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt index dd84aeb9a634..3886a34865ad 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/meanpw/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x[, options] ) - Computes the arithmetic mean along one or more ndarray dimensions - using pairwise summation. + Computes the arithmetic mean along one or more ndarray dimensions using + pairwise summation. Parameters ---------- @@ -38,9 +38,8 @@ {{alias}}.assign( x, out[, options] ) - Computes the arithmetic mean along one or more ndarray dimensions, - using pairwise summation, and assigns results to a provided - output ndarray. + Computes the arithmetic mean along one or more ndarray dimensions using + pairwise summation and assigns results to a provided output ndarray. Parameters ---------- diff --git a/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts index b8b33c9b1f36..fb6525c94d6c 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/meanpw/docs/types/index.d.ts @@ -83,7 +83,7 @@ interface Unary { ( 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 pairwise summation, and assigns results to a provided output ndarray. + * Computes the arithmetic mean along one or more ndarray dimensions using pairwise summation and assigns results to a provided output ndarray. * * @param x - input ndarray * @param out - output ndarray diff --git a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js index a6417e8cd839..fb61295871f6 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js +++ b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js @@ -18,19 +18,16 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); var meanpw = require( './../lib' ); // Generate an array of random numbers: -var xbuf = discreteUniform( 25, 0, 20, { - 'dtype': 'generic' +var x = array( uniform( 25, 0.0, 20.0 ), { + 'shape': [ 5, 5 ] }); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); // Perform a reduction: diff --git a/lib/node_modules/@stdlib/stats/meanpw/lib/main.js b/lib/node_modules/@stdlib/stats/meanpw/lib/main.js index cf2239f6f2ca..3ee02c0184c9 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/lib/main.js +++ b/lib/node_modules/@stdlib/stats/meanpw/lib/main.js @@ -53,7 +53,7 @@ var table = { /** * Computes the arithmetic mean along one or more ndarray dimensions using pairwise summation. * -* @name mean +* @name meanpw * @type {Function} * @param {ndarray} x - input ndarray * @param {Options} [options] - function options From 34f480ffbe786e608196c75b3752ca57049b6e55 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 8 Dec 2025 02:22:54 -0800 Subject: [PATCH 13/16] style: align comments Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/meanpw/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/meanpw/lib/main.js b/lib/node_modules/@stdlib/stats/meanpw/lib/main.js index 3ee02c0184c9..0743b1300d6d 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/lib/main.js +++ b/lib/node_modules/@stdlib/stats/meanpw/lib/main.js @@ -38,7 +38,7 @@ var policies = { var table = { 'types': [ 'float64', // input - 'float32' // input + 'float32' // input ], 'fcns': [ dmeanpw, From e868c0712aed81b9e9f593f5ea1c097a85f5c532 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 19:19:24 +0530 Subject: [PATCH 14/16] changes done --- lib/node_modules/@stdlib/stats/meanpw/README.md | 2 +- lib/node_modules/@stdlib/stats/meanpw/examples/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/meanpw/README.md b/lib/node_modules/@stdlib/stats/meanpw/README.md index c42f0515362e..000f05b1af75 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/README.md +++ b/lib/node_modules/@stdlib/stats/meanpw/README.md @@ -231,7 +231,7 @@ The method accepts the following options: ```javascript -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); diff --git a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js index fb61295871f6..a7018ad2b30a 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js +++ b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js @@ -18,7 +18,7 @@ 'use strict'; -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var array = require( '@stdlib/ndarray/array' ); From c84342ae3d7c69bbcfec205a7069f00b870cffac Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 8 Dec 2025 19:25:25 +0530 Subject: [PATCH 15/16] fix: examples updated --- lib/node_modules/@stdlib/stats/meanpw/README.md | 5 +---- lib/node_modules/@stdlib/stats/meanpw/examples/index.js | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/meanpw/README.md b/lib/node_modules/@stdlib/stats/meanpw/README.md index 000f05b1af75..ba54dfc14459 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/README.md +++ b/lib/node_modules/@stdlib/stats/meanpw/README.md @@ -234,13 +234,10 @@ The method accepts the following options: var uniform = require( '@stdlib/random/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var array = require( '@stdlib/ndarray/array' ); var meanpw = require( '@stdlib/stats/meanpw' ); // Generate an array of random numbers: -var x = array( uniform( 25, 0.0, 20.0 ), { - 'shape': [ 5, 5 ] -}); +var x = uniform( [ 5, 5 ], 0.0, 20.0 ); console.log( ndarray2array( x ) ); // Perform a reduction: diff --git a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js index a7018ad2b30a..352961b9b183 100644 --- a/lib/node_modules/@stdlib/stats/meanpw/examples/index.js +++ b/lib/node_modules/@stdlib/stats/meanpw/examples/index.js @@ -21,13 +21,10 @@ var uniform = require( '@stdlib/random/uniform' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var array = require( '@stdlib/ndarray/array' ); var meanpw = require( './../lib' ); // Generate an array of random numbers: -var x = array( uniform( 25, 0.0, 20.0 ), { - 'shape': [ 5, 5 ] -}); +var x = uniform( [ 5, 5 ], 0.0, 20.0 ); console.log( ndarray2array( x ) ); // Perform a reduction: From 68376840abc8d3d1bca6e0898cf51a0b93ea6cd2 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 9 Dec 2025 11:48:45 +0530 Subject: [PATCH 16/16] changes done --- .../@stdlib/stats/mskmax/README.md | 4 +- .../@stdlib/stats/mskmax/lib/base.js | 80 +++++++++++ .../@stdlib/stats/mskmax/lib/main.js | 134 +++++++++++++----- 3 files changed, 183 insertions(+), 35 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/mskmax/lib/base.js diff --git a/lib/node_modules/@stdlib/stats/mskmax/README.md b/lib/node_modules/@stdlib/stats/mskmax/README.md index 99fcd4f5ec0f..bb4b8dfc148c 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/README.md +++ b/lib/node_modules/@stdlib/stats/mskmax/README.md @@ -51,7 +51,7 @@ var v = y.get(); The function has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. -- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. - **options**: function options (_optional_). The function accepts the following options: @@ -201,7 +201,7 @@ var bool = ( out === y ); The method has the following parameters: - **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or generic [data type][@stdlib/ndarray/dtypes]. -- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored. - **out**: output [ndarray][@stdlib/ndarray/ctor]. - **options**: function options (_optional_). diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/base.js b/lib/node_modules/@stdlib/stats/mskmax/lib/base.js new file mode 100644 index 000000000000..e329a2e82a01 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/base.js @@ -0,0 +1,80 @@ +/** +* @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 gmskmax = require( '@stdlib/stats/base/ndarray/mskmax' ); +var dmskmax = require( '@stdlib/stats/base/ndarray/dmskmax' ); +var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); +var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'real_and_generic' ); +var mdtypes = dtypes( 'mask_index_and_generic' ); +var odtypes = dtypes( 'real_and_generic' ); +var policies = { + 'output': 'promoted', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', + 'uint8', // dmskmax: x, mask + 'float32', + 'uint8' // smskmax: x, mask + ], + 'fcns': [ + dmskmax, + smskmax + ], + 'default': gmskmax +}; + + +// MAIN // + +/** +* Base implementation for computing the maximum value along one or more ndarray dimensions according to a mask. +* +* @name base +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} mask - mask 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} second 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 +*/ +var base = factory( table, [ idtypes, mdtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = base; diff --git a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js index c41dcb76f5c0..4def17733364 100644 --- a/lib/node_modules/@stdlib/stats/mskmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/mskmax/lib/main.js @@ -20,35 +20,10 @@ // MODULES // -var dtypes = require( '@stdlib/ndarray/dtypes' ); -var gmskmax = require( '@stdlib/stats/base/ndarray/mskmax' ); -var dmskmax = require( '@stdlib/stats/base/ndarray/dmskmax' ); -var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); -var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' ); - - -// VARIABLES // - -var idtypes = dtypes( 'real_and_generic' ); -var mdtypes = dtypes( 'integer' ); -var odtypes = dtypes( 'real_and_generic' ); -var policies = { - 'output': 'promoted', - 'casting': 'none' -}; -var table = { - 'types': [ - 'float64', - 'uint8', // dmskmax: x, mask - 'float32', - 'uint8' // smskmax: x, mask - ], - 'fcns': [ - dmskmax, - smskmax - ], - 'default': gmskmax -}; +var isNdarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var maybeBroadcastArrays = require( '@stdlib/ndarray/base/maybe-broadcast-arrays' ); +var base = require( './base.js' ); // MAIN // @@ -56,8 +31,6 @@ var table = { /** * Computes the maximum value along one or more ndarray dimensions according to a mask. * -* @name max -* @type {Function} * @param {ndarray} x - input ndarray * @param {ndarray} mask - mask ndarray * @param {Options} [options] - function options @@ -81,7 +54,7 @@ var table = { * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * // Create a mask buffer: -* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); // eslint-disable-line id-length +* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); * * // Define the shape of the input array: * var sh = [ 3, 2 ]; @@ -107,7 +80,102 @@ var table = { * var v = out.get(); * // returns 5.0 */ -var mskmax = factory( table, [ idtypes, mdtypes ], odtypes, policies ); +function mskmax( x, mask ) { + var arrs; + if ( !isNdarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( !isNdarrayLike( mask ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', mask ) ); + } + arrs = maybeBroadcastArrays( [ x, mask ] ); + if ( arguments.length > 2 ) { + return base( arrs[ 0 ], arrs[ 1 ], arguments[ 2 ] ); + } + return base( arrs[ 0 ], arrs[ 1 ] ); +} + +/** +* Computes the maximum value along one or more ndarray dimensions according to a mask and assigns the results to a provided output ndarray. +* +* @name assign +* @memberof mskmax +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} mask - mask ndarray +* @param {ndarray} out - output 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 +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} third 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 Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* // Create a mask buffer: +* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); +* +* // Create an output buffer: +* var obuf = new Float64Array( [ 0.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* var sm = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* var om = 0; +* +* // Create the input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Create the mask ndarray: +* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); // cspell:disable-line +* +* // Create the output ndarray: +* var out = new ndarray( 'float64', obuf, [], [ 0 ], 0, 'row-major' ); +* +* // Perform reduction: +* var res = mskmax.assign( x, mask, out ); +* // returns +* +* var v = res.get(); +* // returns 5.0 +*/ +function assign( x, mask, out ) { + var arrs; + if ( !isNdarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( !isNdarrayLike( mask ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', mask ) ); + } + if ( !isNdarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); + } + arrs = maybeBroadcastArrays( [ x, mask ] ); + if ( arguments.length > 3 ) { + return base.assign( arrs[ 0 ], arrs[ 1 ], out, arguments[ 3 ] ); + } + return base.assign( arrs[ 0 ], arrs[ 1 ], out ); +} + +mskmax.assign = assign; // EXPORTS //