From 6ba801e876b9468ce53ac5a7acec8624836fae6f Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:10:15 +0530 Subject: [PATCH 1/9] feat: add stats/base/ndarray/smskrange --- .../stats/base/ndarray/smskrange/README.md | 130 +++++++++ .../ndarray/smskrange/benchmark/benchmark.js | 112 ++++++++ .../base/ndarray/smskrange/docs/repl.txt | 36 +++ .../ndarray/smskrange/docs/types/index.d.ts | 51 ++++ .../base/ndarray/smskrange/docs/types/test.ts | 63 +++++ .../base/ndarray/smskrange/examples/index.js | 40 +++ .../stats/base/ndarray/smskrange/lib/index.js | 50 ++++ .../stats/base/ndarray/smskrange/lib/main.js | 62 +++++ .../stats/base/ndarray/smskrange/package.json | 66 +++++ .../stats/base/ndarray/smskrange/test/test.js | 255 ++++++++++++++++++ 10 files changed, 865 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md new file mode 100644 index 000000000000..96966dd7210b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md @@ -0,0 +1,130 @@ + + +# smskrange + +> Calculate the [range][range] of a one-dimensional single-precision floating-point ndarray according to a mask. + +
+ +The [**range**][range] is defined as the difference between the maximum and minimum values. + +
+ + + +
+ +## Usage + +```javascript +var smskrange = require( '@stdlib/stats/base/ndarray/smskrange' ); +``` + +#### smskrange( arrays ) + +Computes the [range][range] of a one-dimensional single-precision floating- +point ndarray according to a mask. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var maskbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = smskrange( [ 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': 'generic' +}); +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( 'uint8', 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/smskrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/benchmark/benchmark.js new file mode 100644 index 000000000000..24e0fa2b826a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var smskrange = require( './../lib' ); + + +// VARIABLES // + +var xoptions = { + 'dtype': 'float32' +}; +var moptions = { + 'dtype': 'uint8' +}; + + +// 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, xoptions ); + x = new ndarray( 'float32', xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + mbuf = bernoulli( len, 0.2, moptions ); + mask = new ndarray( 'uint8', 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 = smskrange( [ x, mask ] ); + if ( isnanf( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( 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/smskrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/repl.txt new file mode 100644 index 000000000000..abc87387a659 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( arrays ) + Calculates the range of a one-dimensional single-precision floating-point + 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 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 4.0, 2.0 ] ); + > var dt = 'float32'; + > 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 = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 1, 0 ] ); + > var mdt = 'uint8'; + > var mask = new {{alias:@stdlib/ndarray/ctor}}( mdt, mbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, mask ] ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts new file mode 100644 index 000000000000..7324790fbc07 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts @@ -0,0 +1,51 @@ +/* +* @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 single-precision floating-point +* ndarray according to a mask. +* +* @param arrays - array-like object containing an input ndarray and a mask ndarray +* @returns range +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smskrange( [ x, mask ] ); +* // returns 4.0 +*/ +declare function smskrange( arrays: [ T, T ] ): number; + + +// EXPORTS // + +export = smskrange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/test.ts new file mode 100644 index 000000000000..eb6de6766642 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/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 smskrange = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'uint8' + }); + + smskrange( [ x, mask ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + smskrange( '10' ); // $ExpectError + smskrange( 10 ); // $ExpectError + smskrange( true ); // $ExpectError + smskrange( false ); // $ExpectError + smskrange( null ); // $ExpectError + smskrange( undefined ); // $ExpectError + smskrange( [] ); // $ExpectError + smskrange( {} ); // $ExpectError + smskrange( ( 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': 'float32' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'uint8' + }); + + smskrange(); // $ExpectError + smskrange( [ x, mask ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/examples/index.js new file mode 100644 index 000000000000..82a2c6c6180d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/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 smskrange = require( './../lib' ); + +var xbuf = uniform( 10, -50.0, 50.0, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var maskbuf = bernoulli( xbuf.length, 0.2, { + 'dtype': 'uint8' +}); +var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( mask ) ); + +var v = smskrange( [ x, mask ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js new file mode 100644 index 000000000000..1817c79e924c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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 single-precision floating-point +* ndarray according to a mask. +* +* @module @stdlib/stats/base/ndarray/smskrange +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var smskrange = require( '@stdlib/stats/base/ndarray/smskrange' ); +* +* var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smskrange( [ x, mask ] ); +* // returns 4.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js new file mode 100644 index 000000000000..61449868e7e7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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/smskrange' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional single-precision floating-point +* ndarray according to a mask. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a mask ndarray +* @returns {number} range +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var maskbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smskrange( [ x, mask ] ); +* // returns 4.0 +*/ +function smskrange( 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 = smskrange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/package.json new file mode 100644 index 000000000000..45432d711bfa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/stats/base/ndarray/smskrange", + "version": "0.0.0", + "description": "Calculate the range of a one-dimensional single-precision floating-point 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", + "float32", + "single-precision", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js new file mode 100644 index 000000000000..9f943e929633 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js @@ -0,0 +1,255 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var smskrange = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {string} dtype - data type +* @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( dtype, buffer, length, stride, offset ) { + return new ndarray( dtype, buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smskrange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smskrange.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 = new Float32Array( [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 1, 0, 0, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, NaN, -5.0 ] ); + mask = new Uint8Array( [ 0, 1, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); + mask = new Uint8Array( [ 0, 0, 1, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 1 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 1 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 1, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 1 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + mask = new Uint8Array( [ 0, 0 ] ); + v = smskrange( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isnanf( 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 = new Float32Array( [] ); + mask = new Uint8Array( [] ); + + v = smskrange( [ vector( 'float32', x, 0, 1, 0 ), vector( 'uint8', mask, 0, 1, 0 ) ] ); + t.strictEqual( isnanf( 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 = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); + + v = smskrange( [ vector( 'float32', x, 1, 1, 0 ), vector( 'uint8', 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 = new Float32Array([ + 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 = new Uint8Array([ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]); + + v = smskrange( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', 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 = new Float32Array([ + 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 = new Uint8Array([ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]); + + v = smskrange( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', 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 afb170b044221290022869540132cc8f81ac9e4f Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:15:48 +0530 Subject: [PATCH 2/9] feat: Lint Fix --- .../@stdlib/stats/base/ndarray/smskrange/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js index 9f943e929633..7d8c64024c40 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js @@ -248,7 +248,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 1 // 4 ]; - v = mskrange( [ vector( x, 5, 2, 1 ), vector( mask, 5, 2, 1 ) ] ); + v = smskrange( [ vector( x, 5, 2, 1 ), vector( mask, 5, 2, 1 ) ] ); t.strictEqual( v, 6.0, 'returns expected value' ); t.end(); From baf67203a15698d453b73695da827995afe6a17c Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:21:20 +0530 Subject: [PATCH 3/9] feat: Lint Fix2 --- .../@stdlib/stats/base/ndarray/smskrange/lib/index.js | 3 ++- .../@stdlib/stats/base/ndarray/smskrange/test/test.js | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js index 1817c79e924c..85432da5b047 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the range of a one-dimensional single-precision floating-point +* Computes the range of a one-dimensional single-precision floating-point * ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskrange @@ -33,6 +33,7 @@ * var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * +* // cspell:disable-next-line * var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); * var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js index 7d8c64024c40..3bfe3ed210b0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/test/test.js @@ -223,7 +223,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', var x; var v; - x = [ + x = new Float32Array([ 2.0, 1.0, // 0 2.0, @@ -234,8 +234,8 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 4.0, // 3 5.0, 6.0 // 4 - ]; - mask = [ + ]); + mask = new Uint8Array([ 0, 0, // 0 0, @@ -246,9 +246,9 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 0, // 3 1, 1 // 4 - ]; + ]); - v = smskrange( [ vector( x, 5, 2, 1 ), vector( mask, 5, 2, 1 ) ] ); + v = smskrange( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); t.strictEqual( v, 6.0, 'returns expected value' ); t.end(); From 5d72ba2d7f6025d49e76ca2a27ca4d95ab1f6aa6 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:26:10 +0530 Subject: [PATCH 4/9] feat: Styling Issues --- .../@stdlib/stats/base/ndarray/smskrange/lib/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js index 85432da5b047..1e2f3139bfbd 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Computes the range of a one-dimensional single-precision floating-point +* Compute the range of a one-dimensional single-precision floating-point * ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskrange @@ -33,8 +33,7 @@ * var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* // cspell:disable-next-line -* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); // cspell:disable-line * var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smskrange( [ x, mask ] ); From 3487a43f457be25310e38972c32df7c49dc1c0e6 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:29:34 +0530 Subject: [PATCH 5/9] feat: Lint Fix3 --- .../@stdlib/stats/base/ndarray/smskrange/lib/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js index 1e2f3139bfbd..26b494854960 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/index.js @@ -19,8 +19,7 @@ 'use strict'; /** -* Compute the range of a one-dimensional single-precision floating-point -* ndarray according to a mask. +* Calculate the range of a one-dimensional single-precision floating-point ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskrange * @@ -33,8 +32,8 @@ * var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); // cspell:disable-line -* var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* var maskbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mask = new ndarray( 'uint8', maskbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smskrange( [ x, mask ] ); * // returns 4.0 From baa6ab9fd5c01c13365ca340453449a13d644db8 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 21:35:41 +0530 Subject: [PATCH 6/9] feat: Changes Done --- .../@stdlib/stats/base/ndarray/smskrange/lib/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js index 61449868e7e7..ba0cecbd8c12 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/lib/main.js @@ -30,8 +30,7 @@ var strided = require( '@stdlib/stats/strided/smskrange' ).ndarray; // MAIN // /** -* Computes the range of a one-dimensional single-precision floating-point -* ndarray according to a mask. +* Computes the range of a one-dimensional single-precision floating-point ndarray according to a mask. * * @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a mask ndarray * @returns {number} range From 822dcdb0f2fe135aa0d68736f4c84e7f9f395518 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 2 Dec 2025 20:57:20 -0800 Subject: [PATCH 7/9] style: remove line break Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskrange/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md index 96966dd7210b..8ceedd55f39b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md @@ -40,8 +40,7 @@ var smskrange = require( '@stdlib/stats/base/ndarray/smskrange' ); #### smskrange( arrays ) -Computes the [range][range] of a one-dimensional single-precision floating- -point ndarray according to a mask. +Computes the [range][range] of a one-dimensional single-precision floating-point ndarray according to a mask. ```javascript var Float32Array = require( '@stdlib/array/float32' ); From a11d31892d2296ad6f4bd65a65b1aa192ccc84b9 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 2 Dec 2025 20:58:06 -0800 Subject: [PATCH 8/9] docs: fix example Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskrange/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md index 8ceedd55f39b..ddf7c9096d9d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/README.md @@ -91,9 +91,9 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' ); var mskrange = require( '@stdlib/stats/base/ndarray/mskrange' ); var xbuf = uniform( 10, -50.0, 50.0, { - 'dtype': 'generic' + 'dtype': 'float32' }); -var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); var maskbuf = bernoulli( xbuf.length, 0.2, { From 0782613191ba3c2e9dd4e7c23d904ee465b04d34 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 2 Dec 2025 20:59:14 -0800 Subject: [PATCH 9/9] style: remove line break Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts index 7324790fbc07..ef4c225e255f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskrange/docs/types/index.d.ts @@ -23,8 +23,7 @@ import { ndarray } from '@stdlib/types/ndarray'; /** -* Calculates the range of a one-dimensional single-precision floating-point -* ndarray according to a mask. +* Calculates the range of a one-dimensional single-precision floating-point ndarray according to a mask. * * @param arrays - array-like object containing an input ndarray and a mask ndarray * @returns range