From 6e4eccf39f0c4304a32e9e5ebe4292635b1a488f Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Mon, 1 Dec 2025 16:37:59 +0530 Subject: [PATCH 1/6] feat: stats/base/ndarray/nanmin-by --- .../stats/base/ndarray/nanmin-by/README.md | 161 ++++++++++ .../ndarray/nanmin-by/benchmark/benchmark.js | 121 ++++++++ .../base/ndarray/nanmin-by/docs/repl.txt | 49 +++ .../ndarray/nanmin-by/docs/types/index.d.ts | 95 ++++++ .../base/ndarray/nanmin-by/docs/types/test.ts | 84 +++++ .../base/ndarray/nanmin-by/examples/index.js | 44 +++ .../stats/base/ndarray/nanmin-by/lib/index.js | 48 +++ .../stats/base/ndarray/nanmin-by/lib/main.js | 74 +++++ .../stats/base/ndarray/nanmin-by/package.json | 65 ++++ .../stats/base/ndarray/nanmin-by/test/test.js | 288 ++++++++++++++++++ 10 files changed, 1029 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md new file mode 100644 index 000000000000..138e6b5da767 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md @@ -0,0 +1,161 @@ + + +# nanmin-by + +> Compute the minimum value of a one-dimensional ndarray via a callback function, ignoring `NaN` values. + +
+ +
+ + + +
+ +## Usage + +```javascript +var nanminBy = require( '@stdlib/stats/base/ndarray/nanmin-by' ); +``` + +#### nanminBy( arrays, clbk\[, thisArg ] ) + +Computes the minimum value of a one-dimensional ndarray via a callback function, ignoring `NaN` values. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +function clbk( value ) { + return value * 2.0; +} + +var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = nanminBy( [ x ], clbk ); +// returns -4.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. +- **clbk**: callback function. +- **thisArg**: callback execution context (_optional_). + +The invoked callback is provided three arguments: + +- **value**: current array element. +- **idx**: current array element index. +- **array**: input ndarray. + +To set the callback execution context, provide a `thisArg`. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +function clbk( value ) { + this.count += 1; + return value * 2.0; +} + +var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +var ctx = { + 'count': 0 +}; + +var v = nanminBy( [ x ], clbk, ctx ); +// returns -4.0 + +var count = ctx.count; +// returns 4 +``` + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. +- A provided callback function should return a numeric value. +- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is **ignored**. + +
+ + + +
+ +## Examples + + + +```javascript +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nanminBy = require( '@stdlib/stats/base/ndarray/nanmin-by' ); + +function rand() { + if ( bernoulli( 0.2 ) > 0 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +function clbk( value ) { + return value * 2.0; +} + +var xbuf = filledarrayBy( 10, 'generic', rand ); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = nanminBy( [ x ], clbk ); +console.log( v ); +``` + +
+ + + +
+ +
+ + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/benchmark/benchmark.js new file mode 100644 index 000000000000..dd248cccdcc3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/benchmark/benchmark.js @@ -0,0 +1,121 @@ +/** +* @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/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var nanminBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Callback function. +* +* @private +* @param {number} value - array element +* @returns {number} callback result +*/ +function clbk( value ) { + return value * 2.0; +} + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = filledarrayBy( len, 'generic', rand ); + x = new ndarray( 'generic', xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = nanminBy( [ x ], clbk ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt new file mode 100644 index 000000000000..5cdf88ddd3a1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( arrays, clbk[, thisArg] ) + Computes the minimum value of a one-dimensional ndarray via a callback + function, ignoring NaN values. + + If provided an empty ndarray, the function returns `NaN`. + + The callback function is provided three arguments: + + - value: current array element. + - index: current array index. + - array: the input ndarray. + + The callback function should return a numeric value. + + If the callback function does not return any value (or equivalently, + explicitly returns `undefined`), the value is ignored. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + + Returns + ------- + out: number + Minimum value. + + Examples + -------- + > var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > function f ( v ) { return v * 2.0; }; + > {{alias}}( [ x ], f ) + -4.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/index.d.ts new file mode 100644 index 000000000000..12db4a277614 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/index.d.ts @@ -0,0 +1,95 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Callback function applied to each element of an ndarray. +* +* @returns result +*/ +type Nullary = ( this: ThisArg ) => number | void; + +/** +* Callback function applied to each element of an ndarray. +* +* @param value - current array element +* @returns result +*/ +type Unary = ( this: ThisArg, value: T ) => number | void; + +/** +* Callback function applied to each element of an ndarray. +* +* @param value - current array element +* @param index - current array element index +* @returns result +*/ +type Binary = ( this: ThisArg, value: T, index: number ) => number | void; + +/** +* Callback function applied to each element of an ndarray. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type Ternary = ( this: ThisArg, value: T, index: number, array: U ) => number | void; + +/** +* Callback function applied to each element of an ndarray. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Computes the minimum value of a one-dimensional ndarray via a callback function, ignoring NaN values. +* +* @param arrays - array-like object containing an input ndarray +* @param clbk - callback function +* @param thisArg - callback execution context +* @returns minimum value +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = nanminBy( [ x ], clbk ); +* // returns -4.0 +*/ +declare function nanminBy = typedndarray, ThisArg = unknown>( arrays: [ U ], clbk: Callback, thisArg?: ThisParameterType> ): number; + + +// EXPORTS // + +export = nanminBy; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts new file mode 100644 index 000000000000..89e7ff254090 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts @@ -0,0 +1,84 @@ +/* +* @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 nanminBy = require( './index' ); + +/** +* Callback function. +* +* @param value - ndarray element +* @returns result +*/ +function clbk( value: any ): number { + return value * 2.0; +} + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + } ); + + nanminBy( [ x ], clbk ); // $ExpectType number + nanminBy( [ x ], clbk, {} ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + nanminBy( '10', clbk ); // $ExpectError + nanminBy( 10, clbk ); // $ExpectError + nanminBy( true, clbk ); // $ExpectError + nanminBy( false, clbk ); // $ExpectError + nanminBy( null, clbk ); // $ExpectError + nanminBy( undefined, clbk ); // $ExpectError + nanminBy( [], clbk ); // $ExpectError + nanminBy( {}, clbk ); // $ExpectError + nanminBy( ( y: number ): number => y, clbk ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + } ); + + nanminBy( [ x ], '10' ); // $ExpectError + nanminBy( [ x ], 10 ); // $ExpectError + nanminBy( [ x ], true ); // $ExpectError + nanminBy( [ x ], false ); // $ExpectError + nanminBy( [ x ], null ); // $ExpectError + nanminBy( [ x ], undefined ); // $ExpectError + nanminBy( [ x ], [] ); // $ExpectError + nanminBy( [ x ], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + } ); + + nanminBy( [ x ] ); // $ExpectError + nanminBy( [ x ], clbk, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/examples/index.js new file mode 100644 index 000000000000..52fbb22f419a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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 bernoulli = require( '@stdlib/random/base/bernoulli' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nanminBy = require( './../lib' ); + +function rand() { + if ( bernoulli( 0.2 ) > 0 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +function clbk( value ) { + return value * 2.0; +} + +var xbuf = filledarrayBy( 10, 'generic', rand ); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = nanminBy( [ x ], clbk ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/index.js new file mode 100644 index 000000000000..ed9d8879904f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/index.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the minimum value of a one-dimensional ndarray via a callback function, ignoring `NaN` values. +* +* @module @stdlib/stats/base/ndarray/nanmin-by +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var nanminBy = require( '@stdlib/stats/base/ndarray/nanmin-by' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = nanminBy( [ x ], clbk ); +* // returns -4.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js new file mode 100644 index 000000000000..4b7168585477 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js @@ -0,0 +1,74 @@ +/** +* @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 getData = require( '@stdlib/ndarray/base/data-buffer' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var strided = require( '@stdlib/stats/strided/nanmin-by' ).ndarray; + + +// MAIN // + +/** +* Computes the minimum value of a one-dimensional ndarray via a callback function, ignoring NaN values. +* +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @returns {number} minimum value +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var nanminBy = require( '@stdlib/stats/base/ndarray/nanmin-by' ); +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* function clbk( value ) { +* return value * 2.0; +* } +* +* var v = nanminBy( [ x ], clbk ); +* // returns -4.0 +*/ +function nanminBy( arrays, clbk, thisArg ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), wrapper, null ); // eslint-disable-line max-len + + /** + * Invokes the provided callback. + * + * @private + * @param {*} value - current array element + * @param {NonNegativeInteger} aidx - current array element index + * @returns {*} result + */ + function wrapper( value, aidx ) { + return clbk.call( thisArg, value, aidx, x ); + } +} + + +// EXPORTS // + +module.exports = nanminBy; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/package.json new file mode 100644 index 000000000000..3d4270771827 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/base/ndarray/nanmin-by", + "version": "0.0.0", + "description": "Compute the minimum value of a one-dimensional ndarray via a callback function, 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", + "nan", + "ndarray", + "callback" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/test/test.js new file mode 100644 index 000000000000..62b99769b833 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/test/test.js @@ -0,0 +1,288 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var nanminBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nanminBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( nanminBy.length, 3, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the minimum value of a one-dimensional ndarray via a callback function, ignoring NaN values', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, NaN, 2.0 ]; + v = nanminBy( [ vector( x, 4, 1, 0 ) ], clbk ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -4.0, -2.0, -5.0, -3.0 ]; + v = nanminBy( [ vector( x, 4, 1, 0 ) ], clbk ); + t.strictEqual( v, -10.0, 'returns expected value' ); + + x = [ 1.0, NaN, 3.0, 2.0, NaN ]; + v = nanminBy( [ vector( x, 5, 1, 0 ) ], clbk ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'if provided an empty ndarray, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = []; + + v = nanminBy( [ vector( x, 0, 1, 0 ) ], clbk ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'if all callback results are `NaN`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ NaN, NaN, NaN ]; + v = nanminBy( [ vector( x, 3, 1, 0 ) ], clbk ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'if provided a one-dimensional ndarray having a single element, the function returns that element (as transformed by the callback)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + v = nanminBy( [ vector( x, 1, 1, 0 ) ], clbk ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN // 4 + ]; + + v = nanminBy( [ vector( x, 5, 2, 0 ) ], clbk ); + t.strictEqual( v, -4.0, 'returns expected value' ); + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 4 + 2.0, + 2.0, // 3 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 1 + 2.0, + NaN // 0 + ]; + + v = nanminBy( [ vector( x, 5, -2, 8 ) ], clbk ); + t.strictEqual( v, -4.0, 'returns expected value' ); + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'if provided a one-dimensional ndarray having a stride equal to `0`, the function returns the first indexed element (as transformed by the callback)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + v = nanminBy( [ vector( x, 5, 0, 0 ) ], clbk ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ]; + + v = nanminBy( [ vector( x, 5, 2, 1 ) ], clbk ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var arr; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN + ]; + ctx = { + 'count': 0 + }; + + indices = []; + values = []; + arrays = []; + + arr = vector( x, 4, 2, 0 ); + v = nanminBy( [ arr ], clbk, ctx ); + + t.strictEqual( v, -4.0, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ + 1.0, + 2.0, + -2.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + 0, + 1, + 2, + 3 + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + arr, + arr, + arr, + arr + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v * 2.0; + } +}); From 1f2e6ef76ca02123d6fe9eb598877b60643e6863 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 21:38:53 -0800 Subject: [PATCH 2/6] docs: fix heading Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md index 138e6b5da767..34b34c3af7ea 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# nanmin-by +# nanminBy > Compute the minimum value of a one-dimensional ndarray via a callback function, ignoring `NaN` values. From 49b698693373fec237b4e16dcd97e5fd01bbe30a Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 21:40:53 -0800 Subject: [PATCH 3/6] docs: add note Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md index 34b34c3af7ea..1a662a27d657 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/README.md @@ -99,6 +99,7 @@ var count = ctx.count; - If provided an empty one-dimensional ndarray, the function returns `NaN`. - A provided callback function should return a numeric value. +- If a provided callback function returns `NaN`, the value is ignored. - If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is **ignored**. From 3f72d99abc68e94a8e2158d3c3298b6ad8746ba4 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 21:42:26 -0800 Subject: [PATCH 4/6] docs: add note Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt index 5cdf88ddd3a1..baeaf3e5144a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/repl.txt @@ -16,6 +16,8 @@ If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored. + If the callback function returns `NaN`, the value is ignored. + Parameters ---------- arrays: ArrayLikeObject From d4f47d184b210dd91991df207da08db10d443781 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 21:45:51 -0800 Subject: [PATCH 5/6] test: add ternary argument tests Signed-off-by: Athan --- .../base/ndarray/nanmin-by/docs/types/test.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts index 89e7ff254090..eaa16203cb74 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/docs/types/test.ts @@ -38,7 +38,7 @@ function clbk( value: any ): number { { const x = zeros( [ 10 ], { 'dtype': 'generic' - } ); + }); nanminBy( [ x ], clbk ); // $ExpectType number nanminBy( [ x ], clbk, {} ); // $ExpectType number @@ -55,13 +55,23 @@ function clbk( value: any ): number { nanminBy( [], clbk ); // $ExpectError nanminBy( {}, clbk ); // $ExpectError nanminBy( ( y: number ): number => y, clbk ); // $ExpectError + + nanminBy( '10', clbk, {} ); // $ExpectError + nanminBy( 10, clbk, {} ); // $ExpectError + nanminBy( true, clbk, {} ); // $ExpectError + nanminBy( false, clbk, {} ); // $ExpectError + nanminBy( null, clbk, {} ); // $ExpectError + nanminBy( undefined, clbk, {} ); // $ExpectError + nanminBy( [], clbk, {} ); // $ExpectError + nanminBy( {}, clbk, {} ); // $ExpectError + nanminBy( ( y: number ): number => y, clbk, {} ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a function... { const x = zeros( [ 10 ], { 'dtype': 'generic' - } ); + }); nanminBy( [ x ], '10' ); // $ExpectError nanminBy( [ x ], 10 ); // $ExpectError @@ -71,13 +81,22 @@ function clbk( value: any ): number { nanminBy( [ x ], undefined ); // $ExpectError nanminBy( [ x ], [] ); // $ExpectError nanminBy( [ x ], {} ); // $ExpectError + + nanminBy( [ x ], '10', {} ); // $ExpectError + nanminBy( [ x ], 10, {} ); // $ExpectError + nanminBy( [ x ], true, {} ); // $ExpectError + nanminBy( [ x ], false, {} ); // $ExpectError + nanminBy( [ x ], null, {} ); // $ExpectError + nanminBy( [ x ], undefined, {} ); // $ExpectError + nanminBy( [ x ], [], {} ); // $ExpectError + nanminBy( [ x ], {}, {} ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( [ 10 ], { 'dtype': 'generic' - } ); + }); nanminBy( [ x ] ); // $ExpectError nanminBy( [ x ], clbk, {}, {} ); // $ExpectError From 07e35de3709c4ff87183c0feac9af6849b12dd6e Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 1 Dec 2025 21:47:43 -0800 Subject: [PATCH 6/6] docs: document provided arguments Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/nanmin-by/lib/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js index 4b7168585477..0c18aecc20fa 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/nanmin-by/lib/main.js @@ -61,6 +61,8 @@ function nanminBy( arrays, clbk, thisArg ) { * @private * @param {*} value - current array element * @param {NonNegativeInteger} aidx - current array element index + * @param {NonNegativeInteger} sidx - current strided array element index + * @param {Collection} arr - input array * @returns {*} result */ function wrapper( value, aidx ) {