From f3d4fea3430bc7f62b2aa7c12e795794ac53b505 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 1 Dec 2025 23:12:46 +0530 Subject: [PATCH 1/8] feat: add stats/base/ndarray/smskmax --- .../stats/base/ndarray/smskmax/README.md | 125 +++++++++ .../ndarray/smskmax/benchmark/benchmark.js | 109 ++++++++ .../stats/base/ndarray/smskmax/docs/repl.txt | 36 +++ .../ndarray/smskmax/docs/types/index.d.ts | 50 ++++ .../base/ndarray/smskmax/docs/types/test.ts | 63 +++++ .../base/ndarray/smskmax/examples/index.js | 40 +++ .../stats/base/ndarray/smskmax/lib/index.js | 49 ++++ .../stats/base/ndarray/smskmax/lib/main.js | 61 +++++ .../stats/base/ndarray/smskmax/package.json | 67 +++++ .../stats/base/ndarray/smskmax/test/test.js | 255 ++++++++++++++++++ 10 files changed, 855 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md new file mode 100644 index 000000000000..819732440750 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md @@ -0,0 +1,125 @@ + + +# smskmax + +> Calculate the maximum value of a single-precision floating-point ndarray according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); +``` + +#### smskmax( arrays ) + +Computes the maximum value of a 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 = smskmax( [ 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 smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); + +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 = smskmax( [ x, mask ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js new file mode 100644 index 000000000000..cc7532746c2b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var 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 smskmax = 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( 'float32', 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 = smskmax( [ 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/smskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt new file mode 100644 index 000000000000..7515b8496642 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( arrays ) + Computes the maximum value of a single-precision floating-point one- + dimensional ndarray according to a mask. + + If provided an empty ndarray or a mask with all elements set to `1`, the + function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing one single-precision floating-point ndarray + and one mask ndarray. + + Returns + ------- + out: number + Maximum 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 mask = new {{alias:@stdlib/ndarray/ctor}}( 'uint8', mbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, mask ] ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts new file mode 100644 index 000000000000..f4da7473ada9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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 { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the maximum value of a single-precision floating-point one-dimensional ndarray according to a mask. +* +* @param arrays - array-like object containing one single-precision floating-point ndarray and one mask ndarray +* @returns maximum 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 mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); +* var mask = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smskmax( [ x, mask ] ); +* // returns 2.0 +*/ +declare function smskmax( arrays: [ float32ndarray, uint8ndarray ] ): number; + + +// EXPORTS // + +export = smskmax; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/test.ts new file mode 100644 index 000000000000..2e8746e2b2c2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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 smskmax = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const mask = zeros( [ 10 ], { + 'dtype': 'uint8' + }); + + smskmax( [ x, mask ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + smskmax( '10' ); // $ExpectError + smskmax( 10 ); // $ExpectError + smskmax( true ); // $ExpectError + smskmax( false ); // $ExpectError + smskmax( null ); // $ExpectError + smskmax( undefined ); // $ExpectError + smskmax( [] ); // $ExpectError + smskmax( {} ); // $ExpectError + smskmax( ( 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' + }); + + smskmax(); // $ExpectError + smskmax( [ x, mask ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/examples/index.js new file mode 100644 index 000000000000..8e4e6081e0be --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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 smskmax = 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 = smskmax( [ x, mask ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js new file mode 100644 index 000000000000..6772ee5dda8f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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'; + +/** +* Compute the maximum value of a single-precision floating-point one-dimensional ndarray according to a mask. +* +* @module @stdlib/stats/base/ndarray/smskmax +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); +* +* 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 = smskmax( [ x, mask ] ); +* // returns 2.0 +*/ + +// MODULES // + +var main = require( '@stdlib/stats/base/ndarray/smskmax/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js new file mode 100644 index 000000000000..a790081e7180 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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/smskmax' ).ndarray; + + +// MAIN // + +/** +* Computes the maximum value of a 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} maximum 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 = smskmax( [ x, mask ] ); +* // returns 2.0 +*/ +function smskmax( 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 = smskmax; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json new file mode 100644 index 000000000000..746e59802b3c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ndarray/smskmax", + "version": "0.0.0", + "description": "Calculate the maximum value of a 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", + "maximum", + "max", + "masked", + "mask", + "float32", + "single-precision", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js new file mode 100644 index 000000000000..90da9b74363f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var smskmax = 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 smskmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smskmax.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum 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 = smskmax( [ 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( [ -4.0, NaN, -5.0 ] ); + mask = new Uint8Array( [ 0, 1, 0 ] ); + v = smskmax( [ 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( [ -0.0, 0.0, NaN, -0.0 ] ); + mask = new Uint8Array( [ 0, 0, 1, 0 ] ); + v = smskmax( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = new Float32Array( [ -4.0, 0.0, NaN, 5.0 ] ); + mask = new Uint8Array( [ 0, 0, 0, 0 ] ); + v = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ 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 = smskmax( [ vector( 'float32', x, 5, 2, 0 ), vector( 'uint8', mask, 5, 2, 0 ) ] ); + + t.strictEqual( v, 4.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 = smskmax( [ vector( 'float32', x, 5, -2, 8 ), vector( 'uint8', mask, 5, -2, 8 ) ] ); + + t.strictEqual( v, 4.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 = smskmax( [ vector( 'float32', x, 5, 2, 1 ), vector( 'uint8', mask, 5, 2, 1 ) ] ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); From a6b4237838702f2efd588145b4ef8504873f55ae Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 1 Dec 2025 23:18:19 +0530 Subject: [PATCH 2/8] feat : Lint Fix --- .../@stdlib/stats/base/ndarray/smskmax/lib/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js index 6772ee5dda8f..b7530a48a4a0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js @@ -32,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 ] ); -* 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 = smskmax( [ x, mask ] ); * // returns 2.0 @@ -41,7 +41,7 @@ // MODULES // -var main = require( '@stdlib/stats/base/ndarray/smskmax/lib/main.js' ); +var main = require( './main.js' ); // EXPORTS // From 2c7bfeb37f0256f32d8a99b5ecf1ec1428e8e627 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Mon, 1 Dec 2025 23:24:30 +0530 Subject: [PATCH 3/8] feat: Lint Fix2 --- .../@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js | 4 +++- .../@stdlib/stats/base/ndarray/smskmax/docs/repl.txt | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js index cc7532746c2b..cf1ff3c633e7 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/benchmark/benchmark.js @@ -55,7 +55,9 @@ function createBenchmark( len ) { xbuf = uniform( len, -100.0, 100.0, options ); x = new ndarray( 'float32', xbuf, [ len ], [ 1 ], 0, 'row-major' ); - mbuf = bernoulli( len, 0.2, { 'dtype': 'uint8' } ); + mbuf = bernoulli( len, 0.2, { + 'dtype': 'uint8' + }); mask = new ndarray( 'uint8', mbuf, [ len ], [ 1 ], 0, 'row-major' ); return benchmark; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt index 7515b8496642..c21c74dca66c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt @@ -9,8 +9,8 @@ Parameters ---------- arrays: ArrayLikeObject - Array-like object containing one single-precision floating-point ndarray - and one mask ndarray. + Array-like object containing one single-precision floating-point + ndarray and one mask ndarray. Returns ------- From 8910bdf8ee1c0891cc7e0eaaabe759d45f2f40fe Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 18:54:28 -0800 Subject: [PATCH 4/8] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md index 819732440750..404f5058cdd6 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/README.md @@ -20,7 +20,7 @@ limitations under the License. # smskmax -> Calculate the maximum value of a single-precision floating-point ndarray according to a mask. +> Calculate the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask.
@@ -38,7 +38,7 @@ var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' ); #### smskmax( arrays ) -Computes the maximum value of a single-precision floating-point ndarray according to a mask. +Computes the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask. ```javascript var Float32Array = require( '@stdlib/array/float32' ); From 4e7d9ecc614b7717d8a4fc20c876e5ef546dbf75 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 18:55:38 -0800 Subject: [PATCH 5/8] docs: update copy Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskmax/docs/repl.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt index c21c74dca66c..15d67091cf06 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt @@ -9,8 +9,7 @@ Parameters ---------- arrays: ArrayLikeObject - Array-like object containing one single-precision floating-point - ndarray and one mask ndarray. + Array-like object containing an input ndarray and a mask ndarray. Returns ------- From 0258f7c2b461d0e0c7d0d8e4be4fcdb6410cc937 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 18:56:21 -0800 Subject: [PATCH 6/8] docs: fix desc Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskmax/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt index 15d67091cf06..ee4ecd9d38ab 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Computes the maximum value of a single-precision floating-point one- - dimensional ndarray according to a mask. + Computes the maximum 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 b1b20b66909fbc5e2988f18918ba96a0e6e42132 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 18:59:27 -0800 Subject: [PATCH 7/8] test: use single-precision utility Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskmax/test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js index 90da9b74363f..2278a4184462 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/test/test.js @@ -24,7 +24,7 @@ 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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var smskmax = require( './../lib' ); @@ -78,7 +78,7 @@ tape( 'the function calculates the maximum value of a one-dimensional ndarray ac x = new Float32Array( [ -0.0, 0.0, NaN, -0.0 ] ); mask = new Uint8Array( [ 0, 0, 1, 0 ] ); v = smskmax( [ vector( 'float32', x, x.length, 1, 0 ), vector( 'uint8', mask, mask.length, 1, 0 ) ] ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + 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 ] ); From 1c49ede00956e574ba894e8a8ed268e5feccffd1 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 19:01:32 -0800 Subject: [PATCH 8/8] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts | 4 ++-- .../@stdlib/stats/base/ndarray/smskmax/lib/index.js | 2 +- .../@stdlib/stats/base/ndarray/smskmax/lib/main.js | 2 +- .../@stdlib/stats/base/ndarray/smskmax/package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts index f4da7473ada9..ae1603403234 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/docs/types/index.d.ts @@ -23,9 +23,9 @@ import { float32ndarray, uint8ndarray } from '@stdlib/types/ndarray'; /** -* Computes the maximum value of a single-precision floating-point one-dimensional ndarray according to a mask. +* Computes the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask. * -* @param arrays - array-like object containing one single-precision floating-point ndarray and one mask ndarray +* @param arrays - array-like object containing an input ndarray and a mask ndarray * @returns maximum value * * @example diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js index b7530a48a4a0..6e195274431d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the maximum value of a single-precision floating-point one-dimensional ndarray according to a mask. +* Compute the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask. * * @module @stdlib/stats/base/ndarray/smskmax * diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js index a790081e7180..3a76a841665f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/lib/main.js @@ -30,7 +30,7 @@ var strided = require( '@stdlib/stats/strided/smskmax' ).ndarray; // MAIN // /** -* Computes the maximum value of a single-precision floating-point ndarray according to a mask. +* Computes the maximum value 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} maximum value diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json index 746e59802b3c..5e96e24e3dab 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smskmax/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/base/ndarray/smskmax", "version": "0.0.0", - "description": "Calculate the maximum value of a single-precision floating-point ndarray according to a mask.", + "description": "Calculate the maximum value of a one-dimensional single-precision floating-point ndarray according to a mask.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors",