From 4cc08fcc0caaadd5fb4cd6595172ad35f0839a3c Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Dec 2025 18:49:26 +0530 Subject: [PATCH 1/7] feat: add stats/base/ndarray/snanmskmin --- .../stats/base/ndarray/snanmskmin/README.md | 125 +++++++++ .../ndarray/snanmskmin/benchmark/benchmark.js | 111 ++++++++ .../base/ndarray/snanmskmin/docs/repl.txt | 37 +++ .../ndarray/snanmskmin/docs/types/index.d.ts | 50 ++++ .../ndarray/snanmskmin/docs/types/test.ts | 63 +++++ .../base/ndarray/snanmskmin/examples/index.js | 40 +++ .../base/ndarray/snanmskmin/lib/index.js | 49 ++++ .../stats/base/ndarray/snanmskmin/lib/main.js | 61 +++++ .../base/ndarray/snanmskmin/package.json | 68 +++++ .../base/ndarray/snanmskmin/test/test.js | 253 ++++++++++++++++++ 10 files changed, 857 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md new file mode 100644 index 000000000000..60d3a8b014c4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md @@ -0,0 +1,125 @@ + + +# snanmskmin + +> Calculate the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. + +
+ +
+ + + +
+ +## Usage + +```javascript +var snanmskmin = require( '@stdlib/stats/base/ndarray/snanmskmin' ); +``` + +#### snanmskmin( arrays ) + +Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. + +```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, NaN ] ); +var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + +var maskbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +var mask = new ndarray( 'uint8', maskbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + +var v = snanmskmin( [ x, mask ] ); +// returns -2.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 snanmskmin = require( '@stdlib/stats/base/ndarray/snanmskmin' ); + +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 = nanmskmin( [ x, mask ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/benchmark/benchmark.js new file mode 100644 index 000000000000..4a0685fe4bf2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/benchmark/benchmark.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 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 snanmskmin = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// 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, { + 'dtype': 'uint8' + }); + 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 = snanmskmin( [ 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/snanmskmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt new file mode 100644 index 000000000000..7b5c26ada8d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt @@ -0,0 +1,37 @@ + +{{alias}}( arrays ) + Calculates the minimum value of a one-dimensional single-precision + floating-point ndarray according to a mask, ignoring `NaN` values. + + 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 + Minimum value. + + Examples + -------- + > var Float32Array = require( '@stdlib/array/float32' ); + > var Uint8Array = require( '@stdlib/array/uint8' ); + > var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] ); + > 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 Uint8Array( [ 0, 0, 1, 0, 0 ] ); + > var mdt = 'uint8'; + > var mask = new {{alias:@stdlib/ndarray/ctor}}( mdt, mbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, mask ] ) + -2.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts new file mode 100644 index 000000000000..b01532bfdd1b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. +* +* @param arrays - array-like object containing an input ndarray and a mask ndarray +* @returns minimum value +* +* @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, NaN ] ); +* var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +* var mask = new ndarray( 'uint8', mbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var v = snanmskmin( [ x, mask ] ); +* // returns -2.0 +*/ +declare function snanmskmin( arrays: [ T, T ] ): number; + + +// EXPORTS // + +export = snanmskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts new file mode 100644 index 000000000000..d0f925ee40f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/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 snanmskmin = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + snanmskmin( [ x, mask ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + snanmskmin( '10' ); // $ExpectError + snanmskmin( 10 ); // $ExpectError + snanmskmin( true ); // $ExpectError + snanmskmin( false ); // $ExpectError + snanmskmin( null ); // $ExpectError + snanmskmin( undefined ); // $ExpectError + snanmskmin( [] ); // $ExpectError + snanmskmin( {} ); // $ExpectError + snanmskmin( ( 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': 'generic' + }); + + snanmskmin(); // $ExpectError + snanmskmin( [ x, mask ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/examples/index.js new file mode 100644 index 000000000000..bb0ea905bfd3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/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 snanmskmin = 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 = snanmskmin( [ x, mask ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js new file mode 100644 index 000000000000..829c7d900ecc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js @@ -0,0 +1,49 @@ +/** +* @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'; + +/** +* Calculate the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. +* +* @module @stdlib/stats/base/ndarray/snanmskmin +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var snanmskmin = require( '@stdlib/stats/base/ndarray/snanmskmin' ); +* +* var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] ); +* var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var mbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +* var mask = new ndarray( 'uint8', mbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var v = snanmskmin( [ x, mask ] ); +* // returns -2.0 +*/ + +// MODULES // + +var main = require( '@stdlib/stats/base/ndarray/snanmskmin/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/main.js new file mode 100644 index 000000000000..fe5591cac433 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/main.js @@ -0,0 +1,61 @@ +/** +* @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/snanmskmin' ).ndarray; + + +// MAIN // + +/** +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a mask ndarray +* @returns {number} minimum value +* +* @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, NaN ] ); +* var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var maskbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +* var mask = new ndarray( 'uint8', maskbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* var v = snanmskmin( [ x, mask ] ); +* // returns -2.0 +*/ +function snanmskmin( 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 = snanmskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/package.json new file mode 100644 index 000000000000..faf1f641a0b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/stats/base/ndarray/snanmskmin", + "version": "0.0.0", + "description": "Calculate the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring NaN values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "minimum", + "min", + "masked", + "mask", + "nan", + "float32", + "single", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js new file mode 100644 index 000000000000..d9141ed0ddd5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js @@ -0,0 +1,253 @@ +/** +* @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 isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var snanmskmin = 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 snanmskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( snanmskmin.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring NaN values', 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 = snanmskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, NaN, -5.0 ] ); + mask = new Uint8Array( [ 0, 1, 0 ] ); + v = snanmskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -5.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); + mask = new Uint8Array( [ 0, 0, 1, 0 ] ); + v = snanmskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' ); + + x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0 ] ); + v = snanmskmin( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + mask = new Uint8Array( [ 0 ] ); + v = snanmskmin( [ 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 = snanmskmin( [ 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 = snanmskmin( [ 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 = snanmskmin( [ 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 = snanmskmin( [ 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 = snanmskmin( [ 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 = snanmskmin( [ 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 the first element', 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 = snanmskmin( [ vector( 'float32', x, 1, 1, 0 ), vector( 'uint8', mask, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.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 = snanmskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); + t.strictEqual( v, -2.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 = snanmskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); + t.strictEqual( v, -2.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 = new Float32Array( [ + 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 = new Uint8Array( [ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ] ); + + v = snanmskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + + t.end(); +}); From d66502cfebb6755ec476e3024015a57a9d4d1e5a Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Dec 2025 18:59:34 +0530 Subject: [PATCH 2/7] changes --- .../@stdlib/stats/base/ndarray/snanmskmin/README.md | 2 +- .../stats/base/ndarray/snanmskmin/docs/types/index.d.ts | 4 ++-- .../@stdlib/stats/base/ndarray/snanmskmin/lib/index.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md index 60d3a8b014c4..0b4a0e4174f9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/README.md @@ -100,7 +100,7 @@ var maskbuf = bernoulli( xbuf.length, 0.2, { var mask = new ndarray( 'uint8', maskbuf, [ maskbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( mask ) ); -var v = nanmskmin( [ x, mask ] ); +var v = snanmskmin( [ x, mask ] ); console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts index b01532bfdd1b..a910352e8e88 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts @@ -36,8 +36,8 @@ import { ndarray } from '@stdlib/types/ndarray'; * var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] ); * var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); * -* var mbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); -* var mask = new ndarray( 'uint8', mbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* var maskbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +* var mask = new ndarray( 'uint8', maskbuf, [ 5 ], [ 1 ], 0, 'row-major' ); * * var v = snanmskmin( [ x, mask ] ); * // returns -2.0 diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js index 829c7d900ecc..60fa8e9ff9e8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/lib/index.js @@ -32,8 +32,8 @@ * var xbuf = new Float32Array( [ 1.0, -2.0, 4.0, 2.0, NaN ] ); * var x = new ndarray( 'float32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); * -* var mbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); -* var mask = new ndarray( 'uint8', mbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* var maskbuf = new Uint8Array( [ 0, 0, 1, 0, 0 ] ); +* var mask = new ndarray( 'uint8', maskbuf, [ 5 ], [ 1 ], 0, 'row-major' ); * * var v = snanmskmin( [ x, mask ] ); * // returns -2.0 @@ -41,7 +41,7 @@ // MODULES // -var main = require( '@stdlib/stats/base/ndarray/snanmskmin/lib/main.js' ); +var main = require( './main.js' ); // EXPORTS // From 486f3627b69333d2008a349f4a7ccf5e2cb21b09 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Dec 2025 19:05:18 +0530 Subject: [PATCH 3/7] Lint --- .../@stdlib/stats/base/ndarray/snanmskmin/test/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js index d9141ed0ddd5..57ca0569fc33 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js @@ -162,7 +162,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 2.0, 5.0, // 4 6.0 - ] ); + ]); mask = new Uint8Array( [ 0, // 0 0, @@ -197,7 +197,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 3.0, 4.0, // 0 2.0 - ] ); + ]); mask = new Uint8Array( [ 1, // 4 1, @@ -232,7 +232,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 4.0, // 3 5.0, 6.0 // 4 - ] ); + ]); mask = new Uint8Array( [ 0, 0, // 0 From 3db53ca9b1687b76b97a5e98d8030ca80157a0df Mon Sep 17 00:00:00 2001 From: kaustubh Date: Wed, 3 Dec 2025 19:11:14 +0530 Subject: [PATCH 4/7] Lint2 --- .../stats/base/ndarray/snanmskmin/test/test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js index 57ca0569fc33..bd0e89d4f939 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/test/test.js @@ -151,7 +151,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', var x; var v; - x = new Float32Array( [ + x = new Float32Array([ 1.0, // 0 2.0, 2.0, // 1 @@ -163,7 +163,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 5.0, // 4 6.0 ]); - mask = new Uint8Array( [ + mask = new Uint8Array([ 0, // 0 0, 0, // 1 @@ -174,7 +174,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 0, 1, // 4 1 - ] ); + ]); v = snanmskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); @@ -186,7 +186,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', var x; var v; - x = new Float32Array( [ + x = new Float32Array([ 5.0, // 4 6.0, 1.0, // 3 @@ -198,7 +198,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 4.0, // 0 2.0 ]); - mask = new Uint8Array( [ + mask = new Uint8Array([ 1, // 4 1, 0, // 3 @@ -209,7 +209,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 0, 0, // 0 0 - ] ); + ]); v = snanmskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); @@ -221,7 +221,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', var x; var v; - x = new Float32Array( [ + x = new Float32Array([ 2.0, 1.0, // 0 2.0, @@ -233,7 +233,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 5.0, 6.0 // 4 ]); - mask = new Uint8Array( [ + mask = new Uint8Array([ 0, 0, // 0 0, @@ -244,7 +244,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 0, // 3 1, 1 // 4 - ] ); + ]); v = snanmskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); From 8af1432368d75c3e59369f212b331a63a882cce6 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 21:02:38 -0800 Subject: [PATCH 5/7] docs: fix line wrapping Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt index 7b5c26ada8d1..da1ff0056cc2 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Calculates the minimum value of a one-dimensional single-precision - floating-point ndarray according to a mask, ignoring `NaN` values. + Calculates the minimum value of a one-dimensional single-precision floating- + point ndarray according to a mask, ignoring `NaN` values. If provided an empty ndarray or a mask with all elements set to `1`, the function returns `NaN`. From ac4c7538e054337eac27418ea752c1e56919b5f7 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 21:03:28 -0800 Subject: [PATCH 6/7] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts index d0f925ee40f2..87d668bb1baa 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/test.ts @@ -30,7 +30,7 @@ import snanmskmin = require( './index' ); 'dtype': 'float32' }); const mask = zeros( [ 10 ], { - 'dtype': 'generic' + 'dtype': 'uint8' }); snanmskmin( [ x, mask ] ); // $ExpectType number @@ -55,7 +55,7 @@ import snanmskmin = require( './index' ); 'dtype': 'float32' }); const mask = zeros( [ 10 ], { - 'dtype': 'generic' + 'dtype': 'uint8' }); snanmskmin(); // $ExpectError From 4eb922fc4f256f6f4fae8a264b668ed52bd4a743 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 21:04:36 -0800 Subject: [PATCH 7/7] fix: update types Signed-off-by: Athan --- .../stats/base/ndarray/snanmskmin/docs/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts index a910352e8e88..8a3532023372 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanmskmin/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray'; /** * Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask, ignoring `NaN` values. @@ -42,7 +42,7 @@ import { ndarray } from '@stdlib/types/ndarray'; * var v = snanmskmin( [ x, mask ] ); * // returns -2.0 */ -declare function snanmskmin( arrays: [ T, T ] ): number; +declare function snanmskmin( arrays: [ float32ndarray, uint8ndarray ] ): number; // EXPORTS //