From 359495f4a88243c2bd5c426d015104b670a1c23e Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 12:19:12 +0530 Subject: [PATCH 1/7] feat: add stats/base/ndarray/smskmin --- .../stats/base/ndarray/smskmin/README.md | 127 +++++++++ .../ndarray/smskmin/benchmark/benchmark.js | 112 ++++++++ .../stats/base/ndarray/smskmin/docs/repl.txt | 35 +++ .../ndarray/smskmin/docs/types/index.d.ts | 50 ++++ .../base/ndarray/smskmin/docs/types/test.ts | 63 +++++ .../base/ndarray/smskmin/examples/index.js | 42 +++ .../stats/base/ndarray/smskmin/lib/index.js | 49 ++++ .../stats/base/ndarray/smskmin/lib/main.js | 61 +++++ .../stats/base/ndarray/smskmin/package.json | 67 +++++ .../stats/base/ndarray/smskmin/test/test.js | 253 ++++++++++++++++++ 10 files changed, 859 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md new file mode 100644 index 000000000000..557fa9e24450 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/README.md @@ -0,0 +1,127 @@ + + +# smskmin + +> Calculate the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var smskmin = require( '@stdlib/stats/base/ndarray/smskmin' ); +``` + +#### smskmin( arrays ) + +Computes the minimum value 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 = smskmin( [ 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 Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +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 smskmin = require( '@stdlib/stats/base/ndarray/smskmin' ); + +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 = smskmin( [ x, mask ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/benchmark/benchmark.js new file mode 100644 index 000000000000..8a6f86d8561f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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 smskmin = 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( xoptions.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + mbuf = bernoulli( len, 0.2, moptions ); + mask = new ndarray( moptions.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 = smskmin( [ 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/smskmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt new file mode 100644 index 000000000000..fc144546f60a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( arrays ) + Computes the minimum value 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 + Minimum value. + + 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 ] ) + -2.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/index.d.ts new file mode 100644 index 000000000000..cd50efe47589 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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. +* +* @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 ] ); +* 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 = smskmin( [ x, mask ] ); +* // returns -2.0 +*/ +declare function smskmin( arrays: [ T, T ] ): number; + + +// EXPORTS // + +export = smskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/types/test.ts new file mode 100644 index 000000000000..364f31a67422 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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 smskmin = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'uint8' + }); + + smskmin( [ x, mask ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + smskmin( '10' ); // $ExpectError + smskmin( 10 ); // $ExpectError + smskmin( true ); // $ExpectError + smskmin( false ); // $ExpectError + smskmin( null ); // $ExpectError + smskmin( undefined ); // $ExpectError + smskmin( [] ); // $ExpectError + smskmin( {} ); // $ExpectError + smskmin( ( 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' + }); + + smskmin(); // $ExpectError + smskmin( [ x, mask ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js new file mode 100644 index 000000000000..fbfe821ae00b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +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 smskmin = 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 = smskmin( [ x, mask ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/index.js new file mode 100644 index 000000000000..0879fc5f737e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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. +* +* @module @stdlib/stats/base/ndarray/smskmin +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var smskmin = require( '@stdlib/stats/base/ndarray/smskmin' ); +* +* 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 = smskmin( [ x, mask ] ); +* // returns -2.0 +*/ + +// MODULES // + +var smskmin = require( './main.js' ); + + +// EXPORTS // + +module.exports = smskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js new file mode 100644 index 000000000000..91913b012fec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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/smskmin' ).ndarray; + + +// MAIN // + +/** +* Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. +* +* @param {ArrayLikeObject} arrays - array-like object containing one single-precision floating-point ndarray and one 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 ] ); +* 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 = smskmin( [ x, mask ] ); +* // returns -2.0 +*/ +function smskmin( 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 = smskmin; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json new file mode 100644 index 000000000000..b5a31a67c58a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ndarray/smskmin", + "version": "0.0.0", + "description": "Calculate the minimum value 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", + "minimum", + "min", + "masked", + "mask", + "float32", + "single-precision", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js new file mode 100644 index 000000000000..311facc47566 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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 smskmin = 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 smskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smskmin.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the minimum 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ 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 = smskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); + t.strictEqual( v, -2.0, 'returns expected value' ); + + t.end(); +}); From ab14b572331d981cf6cd4a19afaa65e0bdb384d5 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 12:24:40 +0530 Subject: [PATCH 2/7] feat: Lint Fix --- .../@stdlib/stats/base/ndarray/smskmin/examples/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js index fbfe821ae00b..25b500f6bf07 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/examples/index.js @@ -18,8 +18,6 @@ 'use strict'; -var Float32Array = require( '@stdlib/array/float32' ); -var Uint8Array = require( '@stdlib/array/uint8' ); var uniform = require( '@stdlib/random/array/uniform' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); From 5056468949b21d2c4392fb18e56d414c2ffe01b7 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 12:28:58 +0530 Subject: [PATCH 3/7] feat: Lint Fix2 --- .../@stdlib/stats/base/ndarray/smskmin/test/test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js index 311facc47566..6dd55e1a07f9 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/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, @@ -174,7 +174,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 0, 1, // 4 1 - ] ); + ]); v = smskmin( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); @@ -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, @@ -209,7 +209,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 0, 0, // 0 0 - ] ); + ]); v = smskmin( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); @@ -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 @@ -244,7 +244,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 0, // 3 1, 1 // 4 - ] ); + ]); v = smskmin( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); t.strictEqual( v, -2.0, 'returns expected value' ); From 0bdcad8cf72b26b32975bf4b6f0ca905b2eb3c86 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 2 Dec 2025 12:32:44 +0530 Subject: [PATCH 4/7] feat: Lint Fix3 --- .../stats/base/ndarray/smskmin/test/test.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js index 6dd55e1a07f9..c097933b1f0e 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js @@ -151,8 +151,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', var x; var v; - x = new Float32Array( [ - 1.0, // 0 + x = new Float32Array( [ 1.0, // 0 2.0, 2.0, // 1 -7.0, @@ -163,8 +162,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 5.0, // 4 6.0 ]); - mask = new Uint8Array( [ - 0, // 0 + mask = new Uint8Array( [ 0, // 0 0, 0, // 1 0, @@ -186,8 +184,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', var x; var v; - x = new Float32Array( [ - 5.0, // 4 + x = new Float32Array( [ 5.0, // 4 6.0, 1.0, // 3 2.0, @@ -198,8 +195,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 4.0, // 0 2.0 ]); - mask = new Uint8Array( [ - 1, // 4 + mask = new Uint8Array( [ 1, // 4 1, 0, // 3 0, @@ -221,8 +217,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', var x; var v; - x = new Float32Array( [ - 2.0, + x = new Float32Array( [ 2.0, 1.0, // 0 2.0, -2.0, // 1 @@ -233,8 +228,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 5.0, 6.0 // 4 ]); - mask = new Uint8Array( [ - 0, + mask = new Uint8Array( [ 0, 0, // 0 0, 0, // 1 From e4cc86e075df88db7aa3d691dbffaefc33cc0840 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 23:38:12 -0800 Subject: [PATCH 5/7] style: re-wrap lines Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskmin/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt index fc144546f60a..c73148d904fa 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Computes the minimum value of a one-dimensional single-precision - floating-point ndarray according to a mask. + Computes the minimum value 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`. From ca0dbdae1f74829f4e7e952bebd3427772fd343d Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 23:39:30 -0800 Subject: [PATCH 6/7] docs: update desc Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js index 91913b012fec..3cc90f3b10c8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/lib/main.js @@ -32,7 +32,7 @@ var strided = require( '@stdlib/stats/strided/smskmin' ).ndarray; /** * Computes the minimum value of a one-dimensional single-precision floating-point ndarray according to a mask. * -* @param {ArrayLikeObject} arrays - array-like object containing one single-precision floating-point ndarray and one mask ndarray +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a mask ndarray * @returns {number} minimum value * * @example From 423498fd4b2a18d7c3c846771e00088eb5446b87 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 23:41:21 -0800 Subject: [PATCH 7/7] style: fix unconventional line breaks Signed-off-by: Athan --- .../stats/base/ndarray/smskmin/test/test.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js index c097933b1f0e..58e0ea796b5c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmin/test/test.js @@ -151,7 +151,8 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', var x; var v; - x = new Float32Array( [ 1.0, // 0 + x = new Float32Array([ + 1.0, // 0 2.0, 2.0, // 1 -7.0, @@ -162,7 +163,8 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 5.0, // 4 6.0 ]); - mask = new Uint8Array( [ 0, // 0 + mask = new Uint8Array([ + 0, // 0 0, 0, // 1 0, @@ -184,7 +186,8 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', var x; var v; - x = new Float32Array( [ 5.0, // 4 + x = new Float32Array([ + 5.0, // 4 6.0, 1.0, // 3 2.0, @@ -195,7 +198,8 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 4.0, // 0 2.0 ]); - mask = new Uint8Array( [ 1, // 4 + mask = new Uint8Array([ + 1, // 4 1, 0, // 3 0, @@ -217,7 +221,8 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', var x; var v; - x = new Float32Array( [ 2.0, + x = new Float32Array([ + 2.0, 1.0, // 0 2.0, -2.0, // 1 @@ -228,7 +233,8 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 5.0, 6.0 // 4 ]); - mask = new Uint8Array( [ 0, + mask = new Uint8Array([ + 0, 0, // 0 0, 0, // 1