From d8a774b3f32ccea1278a2d09a9ead12bd445cc71 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sun, 30 Nov 2025 01:29:11 +0530 Subject: [PATCH 1/8] feat/add-stats-base-ndarray-mskrange --- .../stats/base/ndarray/mskrange/README.md | 123 +++++++++ .../ndarray/mskrange/benchmark/benchmark.js | 109 ++++++++ .../stats/base/ndarray/mskrange/docs/repl.txt | 35 +++ .../ndarray/mskrange/docs/types/index.d.ts | 48 ++++ .../base/ndarray/mskrange/docs/types/test.ts | 63 +++++ .../base/ndarray/mskrange/examples/index.js | 40 +++ .../stats/base/ndarray/mskrange/lib/index.js | 47 ++++ .../stats/base/ndarray/mskrange/lib/main.js | 59 ++++ .../stats/base/ndarray/mskrange/package.json | 64 +++++ .../stats/base/ndarray/mskrange/test/test.js | 252 ++++++++++++++++++ 10 files changed, 840 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/mskrange/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md new file mode 100644 index 000000000000..927d470a3f70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md @@ -0,0 +1,123 @@ + + +# mskrange + +> Calculate the [range][range] of a one-dimensional ndarray according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var mskrange = require( '@stdlib/stats/base/ndarray/mskrange' ); +``` + +#### mskrange( arrays ) + +Computes the [range][range] of a one-dimensional ndarray according to a mask. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var maskbuf = [ 0, 0, 1, 0 ]; +var mask = new ndarray( 'generic', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = mskrange( [ x, mask ] ); +// returns 4.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing an input ndarray and a mask ndarray. + +If a `mask` array element is `0`, the corresponding element in the input ndarray is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in the input ndarray is considered invalid/missing and **excluded** from computation. + +
+ + + +
+ +## Notes + +- If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var mskrange = require( '@stdlib/stats/base/ndarray/mskrange' ); + +var xbuf = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var maskbuf = bernoulli( xbuf.length, 0.2, { + 'dtype': 'uint8' +}); +var mask = new ndarray( 'generic', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( mask ) ); + +var v = mskrange( [ x, mask ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/benchmark/benchmark.js new file mode 100644 index 000000000000..94eae97cb043 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var mskrange = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var mbuf; + var xbuf; + var x; + + xbuf = uniform( len, -100.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + mbuf = bernoulli( len, 0.2, options ); + mask = new ndarray( options.dtype, mbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + xbuf[ i%len ] = i; + v = mskrange( [ x, mask ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt new file mode 100644 index 000000000000..4b4ed992437f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( arrays ) + Calculates the range of a one-dimensional ndarray according to a + mask. + + If provided an empty ndarray or a mask with all elements set to `1`, the + function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing an input ndarray and a mask ndarray. + + Returns + ------- + out: number + Range. + + Examples + -------- + > var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var mbuf = [ 0, 0, 1, 0 ]; + > var mask = new {{alias:@stdlib/ndarray/ctor}}( dt, mbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, mask ] ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/index.d.ts new file mode 100644 index 000000000000..6f8dca347052 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/index.d.ts @@ -0,0 +1,48 @@ +/* +* @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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Calculates the range of a one-dimensional ndarray according to a mask. +* +* @param arrays - array-like object containing an input ndarray and a mask ndarray +* @returns range +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = [ 0, 0, 1, 0 ]; +* var mask = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = mskrange( [ x, mask ] ); +* // returns 4.0 +*/ +declare function mskrange( arrays: [ T, T ] ): number; + + +// EXPORTS // + +export = mskrange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/test.ts new file mode 100644 index 000000000000..435b1d5eca0b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/types/test.ts @@ -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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import mskrange = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + mskrange( [ x, mask ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + mskrange( '10' ); // $ExpectError + mskrange( 10 ); // $ExpectError + mskrange( true ); // $ExpectError + mskrange( false ); // $ExpectError + mskrange( null ); // $ExpectError + mskrange( undefined ); // $ExpectError + mskrange( [] ); // $ExpectError + mskrange( {} ); // $ExpectError + mskrange( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + mskrange(); // $ExpectError + mskrange( [ x, mask ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js new file mode 100644 index 000000000000..ab6f0319f4e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var mskrange = require( './../lib' ); + +var xbuf = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var maskbuf = bernoulli( xbuf.length, 0.2, { + 'dtype': 'uint8' +}); +var mask = new ndarray( 'generic', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( mask ) ); + +var v = mskrange( [ x, mask ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js new file mode 100644 index 000000000000..18ee2f543b38 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js @@ -0,0 +1,47 @@ +/** +* @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 range of a one-dimensional ndarray according to a mask. +* +* @module @stdlib/stats/base/ndarray/mskrange +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var mskrange = require( '@stdlib/stats/base/ndarray/mskrange' ); +* +* var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = [ 0, 0, 1, 0 ]; +* var mask = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = mskrange( [ x, mask ] ); +* // returns 2.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/main.js new file mode 100644 index 000000000000..abda05a87178 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/main.js @@ -0,0 +1,59 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/stats/strided/mskrange' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional ndarray according to a mask. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a mask ndarray +* @returns {number} range +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var maskbuf = [ 0, 0, 1, 0 ]; +* var mask = new ndarray( 'generic', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = mskrange( [ x, mask ] ); +* // returns 4.0 +*/ +function mskrange( arrays ) { + var mask = arrays[ 1 ]; + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), getData( mask ), getStride( mask, 0 ), getOffset( mask ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = mskrange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/package.json new file mode 100644 index 000000000000..43b47ddb0ea0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/stats/base/ndarray/mskrange", + "version": "0.0.0", + "description": "Calculate the range of a one-dimensional ndarray 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", + "range", + "masked", + "mask", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/test/test.js new file mode 100644 index 000000000000..068daf8b97bb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/test/test.js @@ -0,0 +1,252 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var mskrange = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskrange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( mskrange.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range value of a one-dimensional ndarray according to a mask', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 0, 0, 0, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskrange( [ vector( x, x.length, 1, 0 ), vector( mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { + var mask; + var x; + var v; + + x = []; + mask = []; + + v = mskrange( [ vector( x, 0, 1, 0 ), vector( mask, 0, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an ndarray containing a single element, the function returns zero', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 0, 0, 0, 0, 0 ]; + + v = mskrange( [ vector( x, 1, 1, 0 ), vector( mask, 1, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var mask; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]; + mask = [ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]; + + v = mskrange( [ vector( x, 5, 2, 0 ), vector( mask, 5, 2, 0 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var mask; + var x; + var v; + + x = [ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + mask = [ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]; + + v = mskrange( [ vector( x, 5, -2, 8 ), vector( mask, 5, -2, 8 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var mask; + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 5.0, + 6.0 // 4 + ]; + mask = [ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ]; + + v = mskrange( [ vector( x, 5, 2, 1 ), vector( mask, 5, 2, 1 ) ] ); + t.strictEqual( v, 6.0, 'returns expected value' ); + + t.end(); +}); From a97d03c37c4d7c534558cb53950e0cfcc3f8d975 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sun, 30 Nov 2025 01:45:07 +0530 Subject: [PATCH 2/8] docs: add missing reference --- .../@stdlib/stats/base/ndarray/mskrange/README.md | 2 ++ .../@stdlib/stats/base/ndarray/mskrange/lib/index.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md index 927d470a3f70..5820905e8752 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md @@ -118,6 +118,8 @@ console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js index 18ee2f543b38..bdd88059a226 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js @@ -30,11 +30,11 @@ * var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var mbuf = [ 0, 0, 1, 0 ]; +* var mbuf = [ 0, 0, 1, 0 ]; // eslint-disable-line @cspell/spellchecker * var mask = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = mskrange( [ x, mask ] ); -* // returns 2.0 +* // returns 4.0 */ // MODULES // From d1b498692c481aac11dfaa42126a41438fca0722 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 12:57:28 -0800 Subject: [PATCH 3/8] docs: update intro Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md index 5820905e8752..06d89a0d4212 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md @@ -24,6 +24,8 @@ limitations under the License.
+The [**range**][range] is defined as the difference between the maximum and minimum values. +
From bfff98b895f298885d3429eaf39a99bdd434dddc Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 12:59:21 -0800 Subject: [PATCH 4/8] docs: update dtype in example Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md index 06d89a0d4212..ef25c75b4359 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md @@ -97,7 +97,7 @@ console.log( ndarray2array( x ) ); var maskbuf = bernoulli( xbuf.length, 0.2, { 'dtype': 'uint8' }); -var mask = new ndarray( 'generic', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); +var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( mask ) ); var v = mskrange( [ x, mask ] ); From f598a84e463954855bfb962cb6388b94b6c8f7c0 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 13:00:31 -0800 Subject: [PATCH 5/8] style: fix line wrapping Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/mskrange/docs/repl.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt index 4b4ed992437f..60370a079b37 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/docs/repl.txt @@ -1,7 +1,6 @@ {{alias}}( arrays ) - Calculates the range of a one-dimensional ndarray according to a - mask. + Calculates the range of a one-dimensional ndarray according to a mask. If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`. From 58d0ae3d0b35d0f474a2fda5594764460bc93189 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 13:02:53 -0800 Subject: [PATCH 6/8] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/mskrange/examples/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js index ab6f0319f4e3..129c53b93005 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/examples/index.js @@ -25,7 +25,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var mskrange = require( './../lib' ); var xbuf = uniform( 10, -50.0, 50.0, { - 'dtype': 'float64' + 'dtype': 'generic' }); var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); @@ -33,7 +33,7 @@ console.log( ndarray2array( x ) ); var maskbuf = bernoulli( xbuf.length, 0.2, { 'dtype': 'uint8' }); -var mask = new ndarray( 'generic', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); +var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( mask ) ); var v = mskrange( [ x, mask ] ); From c4b4320d7fe7501b6bcd313498b58c643bd8a406 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 13:03:16 -0800 Subject: [PATCH 7/8] docs: fix dtype Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md index ef25c75b4359..dfe155dc27e8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/README.md @@ -89,7 +89,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var mskrange = require( '@stdlib/stats/base/ndarray/mskrange' ); var xbuf = uniform( 10, -50.0, 50.0, { - 'dtype': 'float64' + 'dtype': 'generic' }); var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); From 11916a43aed0f6b1ae06d70d1517d9afd157d3de Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Nov 2025 13:03:56 -0800 Subject: [PATCH 8/8] docs: remove comment Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/mskrange/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js index bdd88059a226..501cf6da6fd0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/mskrange/lib/index.js @@ -30,7 +30,7 @@ * var xbuf = [ 1.0, -2.0, 4.0, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var mbuf = [ 0, 0, 1, 0 ]; // eslint-disable-line @cspell/spellchecker +* var mbuf = [ 0, 0, 1, 0 ]; * var mask = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = mskrange( [ x, mask ] );