diff --git a/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js index 4cd1a1ead424..ed6e099bc8cd 100644 --- a/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js @@ -58,94 +58,89 @@ var format = require( '@stdlib/string/format' ); * m = accumulator(); * // returns -5.0 */ -function incrmmin( W ) { - var buf; - var min; - var N; - var i; - if ( !isPositiveInteger( W ) ) { - throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); - } - buf = new Float64Array( W ); - min = PINF; - i = -1; - N = 0; +function incrnanmmin( W ) { + var buf; + var min; + var N; + var i; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + buf = new Float64Array( W ); + min = PINF; + i = -1; + N = 0; - return accumulator; + return accumulator; - /** - * If provided a value, the accumulator function returns an updated minimum. If not provided a value, the accumulator function returns the current minimum. - * - * @private - * @param {number} [x] - input value - * @returns {(number|null)} minimum value or null - */ - function accumulator( x ) { - var v; - var k; - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - return min; - } - // Update the index for managing the circular buffer: - i = (i+1) % W; + /** + * If provided a value, the accumulator function returns an updated minimum, ignoring NaN values. If not provided a value, the accumulator function returns the current minimum. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} minimum value or null + */ + function accumulator( x ) { + var v; + var k; + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return min; + } + if ( isnan( x ) ) { + return min; // Ignore NaN values and return current minimum + } - // Case: update initial window... - if ( N < W ) { - N += 1; - if ( - isnan( x ) || - x < min || - ( x === min && isNegativeZero( x ) ) - ) { - min = x; - } - } - // Case: incoming value is NaN or less than current minimum value... - else if ( isnan( x ) || x < min ) { - min = x; - } - // Case: outgoing value is the current minimum and the new value is greater than the minimum, and, thus, we need to find a new minimum among the current values... - else if ( ( buf[ i ] === min && x > min ) || isnan( buf[ i ] ) ) { - min = x; - for ( k = 0; k < W; k++ ) { - if ( k !== i ) { - v = buf[ k ]; - if ( isnan( v ) ) { - min = v; - break; // no need to continue searching - } - if ( v < min || ( v === min && isNegativeZero( v ) ) ) { - min = v; - } - } - } - } - // Case: outgoing value is the current minimum, which is zero, and the new value is also zero, and, thus, we need to correctly handle signed zeros... - else if ( buf[ i ] === min && x === min && x === 0.0 ) { - if ( isNegativeZero( x ) ) { - min = x; - } else if ( isNegativeZero( buf[ i ] ) ) { - // Because the outgoing and incoming are different signs (-,+), we need to search the buffer to see if it contains a negative zero. If so, the minimum value remains negative zero; otherwise, the minimum value is incoming value... - min = x; - for ( k = 0; k < W; k++ ) { - if ( k !== i && isNegativeZero( buf[ k ] ) ) { - min = buf[ k ]; - break; - } - } - } - // Case: the outgoing and incoming values are both positive zero, so nothing changes - } - // Case: updating existing window; however, the minimum value does not change so nothing to do but update our buffer... + // Update the index for managing the circular buffer: + i = (i + 1) % W; - buf[ i ] = x; - return min; - } -} + // Case: update initial window... + if ( N < W ) { + N += 1; + if ( x < min || ( x === min && isNegativeZero( x ) ) ) { + min = x; + } + } + // Case: incoming value is less than current minimum value... + else if ( x < min ) { + min = x; + } + // Case: outgoing value is the current minimum and the new value is greater than the minimum, requiring a new minimum search... + else if ( buf[ i ] === min && x > min ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i ) { + v = buf[ k ]; + if ( isnan( v ) ) { + continue; // Ignore NaN values + } + if ( v < min || ( v === min && isNegativeZero( v ) ) ) { + min = v; + } + } + } + } + // Case: handling signed zero differences... + else if ( buf[ i ] === min && x === min && x === 0.0 ) { + if ( isNegativeZero( x ) ) { + min = x; + } else if ( isNegativeZero( buf[ i ] ) ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i && isNegativeZero( buf[ k ] ) ) { + min = buf[ k ]; + break; + } + } + } + } + buf[ i ] = x; + return min; + } +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md new file mode 100644 index 000000000000..01c13e7d7a6a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md @@ -0,0 +1,157 @@ + + +# incrnanmmin + +> Compute a moving minimum value incrementally, ignoring `NaN` values. + +
+ +## Usage + +```javascript +var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); +``` + +#### incrnanmmin( window ) + +Returns an accumulator `function` which incrementally computes a moving minimum value. The `window` parameter defines the number of values over which to compute the moving minimum, ignoring `NaN` values. + +```javascript +var accumulator = incrnanmmin( 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated minimum value. If not provided an input value `x`, the accumulator function returns the current minimum value. + +```javascript +var accumulator = incrmmin( 3 ); + +var m = accumulator(); +// returns null + +// Fill the window... +m = accumulator( 2.0 ); // [2.0] +// returns 2.0 + +m = accumulator( 1.0 ); // [2.0, 1.0] +// returns 1.0 + +m = accumulator( NaN ); +// returns 1.0 + +m = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns 1.0 + +// Window begins sliding... +m = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns -7.0 + +m = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns -7.0 + +m = accumulator(); +// returns -7.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmin( 5 ); + +// For each simulated datum, update the moving minimum... +for ( i = 0; i < 100; i++ ) { + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js new file mode 100644 index 000000000000..c642961e9f76 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmmin = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmin( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmmin( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt new file mode 100644 index 000000000000..bbedb222f504 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt @@ -0,0 +1,47 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + minimum value. ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving minimum. + + If provided a value, the accumulator function returns an updated moving + minimum. If not provided a value, the accumulator function returns the + current moving minimum. + + As `W` values are needed to fill the window buffer, the first `W-1` returned + values are calculated from smaller sample sizes. Until the window is full, + each returned value is calculated from all provided values. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var m = accumulator() + null + > m = accumulator( 2.0 ) + 2.0 + > m = accumulator( -5.0 ) + -5.0 + > m = accumulator( NaN ) + -5.0 + > m = accumulator( 3.0 ) + -5.0 + > m = accumulator( 5.0 ) + -5.0 + > m = accumulator() + -5.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts new file mode 100644 index 000000000000..1a39f58b29b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts @@ -0,0 +1,72 @@ +/* +* @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 + +/// + +/** +* If provided a value, returns an updated minimum value; otherwise, returns the current minimum value. +* +* @param x - value +* @returns minimum value +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving minimum value. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving minimum. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( NaN ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ +declare function incrnanmmin( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmin; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts new file mode 100644 index 000000000000..41f6e6cc72fb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @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. +*/ + +import incrnanmmin = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmin( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + incrnanmmin( '5' ); // $ExpectError + incrnanmmin( true ); // $ExpectError + incrnanmmin( false ); // $ExpectError + incrnanmmin( null ); // $ExpectError + incrnanmmin( undefined ); // $ExpectError + incrnanmmin( [] ); // $ExpectError + incrnanmmin( {} ); // $ExpectError + incrnanmmin( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmmin(); // $ExpectError + incrnanmmin( 3, 2 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmin( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmmin( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js new file mode 100644 index 000000000000..ed2d627341a2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var incrnanmmin = require( './../lib' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + +var accumulator; +var m; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmin( 5 ); + +// For each simulated datum, update the moving minimum... +console.log( '\nValue\tMin\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; + m = accumulator( v ); + console.log( '%s\t%s', isnan( v ) ? 'NaN' : v.toFixed( 4 ), m !== null ? m.toFixed( 4 ) : 'null' ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js new file mode 100644 index 000000000000..c4127d796f6c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js @@ -0,0 +1,60 @@ +/** +* @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 a moving minimum incrementally. ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmmin +* +* @example +* var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); +* +* var accumulator = incrnanmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( NaN ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js new file mode 100644 index 000000000000..c48f2a941993 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js @@ -0,0 +1,151 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving minimum value. ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( NaN ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ +function incrnanmmin( W ) { + var buf; + var min; + var N; + var i; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + buf = new Float64Array( W ); + min = PINF; + i = -1; + N = 0; + + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated minimum, ignoring NaN values. If not provided a value, the accumulator function returns the current minimum. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} minimum value or null + */ + function accumulator( x ) { + var v; + var k; + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return min; + } + if ( isnan( x ) ) { + return min; // Ignore NaN values and return current minimum + } + + // Update the index for managing the circular buffer: + i = (i + 1) % W; + + // Case: update initial window... + if ( N < W ) { + N += 1; + if ( x < min || ( x === min && isNegativeZero( x ) ) ) { + min = x; + } + } + // Case: incoming value is less than current minimum value... + else if ( x < min ) { + min = x; + } + // Case: outgoing value is the current minimum and the new value is greater than the minimum, requiring a new minimum search... + else if ( buf[ i ] === min && x > min ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i ) { + v = buf[ k ]; + if ( isnan( v ) ) { + continue; // Ignore NaN values + } + if ( v < min || ( v === min && isNegativeZero( v ) ) ) { + min = v; + } + } + } + } + // Case: handling signed zero differences... + else if ( buf[ i ] === min && x === min && x === 0.0 ) { + if ( isNegativeZero( x ) ) { + min = x; + } else if ( isNegativeZero( buf[ i ] ) ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i && isNegativeZero( buf[ k ] ) ) { + min = buf[ k ]; + break; + } + } + } + } + + buf[ i ] = x; + return min; + } +} + + +// EXPORTS // + +module.exports = incrnanmmin; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json new file mode 100644 index 000000000000..4bb62dfc5f07 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/stats/incr/nanmmin", + "version": "0.0.0", + "description": "Compute a moving minimum incrementally, 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", + "extreme", + "extent", + "range", + "incremental", + "accumulator", + "moving min", + "sliding window", + "sliding", + "window", + "moving" + ] + } + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js new file mode 100644 index 000000000000..08f3822512a7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js @@ -0,0 +1,218 @@ +/** +* @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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmmin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + values.forEach( function( value ) { + t.throws( function() { incrnanmmin( value ); }, TypeError, 'throws an error when provided ' + value ); + }); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmmin( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving minimum incrementally, ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, 4.0, 2.0, NaN, 2.0, 2.0, 2.0, 1.0, 4.0 ]; + N = data.length; + + acc = incrnanmmin( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results while ignoring NaN values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current minimum value while ignoring NaN values', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, NaN, 5.0, 4.0 ]; + acc = incrnanmmin( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 4.0, 'returns expected value while ignoring NaN values' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmmin( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving minimum incrementally, ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, NaN, 4.0, 2.0, 2.0, NaN, 1.0, 4.0 ]; + N = data.length; + + acc = incrnanmmin( 3 ); // Moving window of size 3 + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + + // Expected minimum values, ignoring NaN + expected = [ + 2.0, // [ 2.0 ] + 2.0, // [ 2.0 ] (NaN ignored) + 2.0, // [ 2.0, 3.0 ] + 2.0, // [ 2.0, 3.0, 2.0 ] + 2.0, // [ 2.0, 3.0, 2.0 ] (NaN ignored) + 2.0, // [ 3.0, 2.0, 4.0 ] (window moves) + 2.0, // [ 2.0, 4.0, 3.0 ] + 2.0, // [ 2.0, 4.0, 3.0 ] (NaN ignored) + 3.0, // [ 4.0, 3.0, 4.0 ] + 2.0, // [ 3.0, 4.0, 2.0 ] + 2.0, // [ 4.0, 2.0, 2.0 ] + 2.0, // [ 4.0, 2.0, 2.0 ] (NaN ignored) + 1.0, // [ 2.0, 2.0, 1.0 ] + 1.0 // [ 2.0, 1.0, 4.0 ] + ]; + + // Check the computed values against the expected values + for ( i = 0; i < N; i++ ) { + if ( isNaN( expected[i] ) ) { + t.equal( isNaN(actual[i]), true, 'returns NaN at index ' + i ); + } else { + t.equal( actual[i], expected[i], 'returns expected value at index ' + i ); + } + } + + t.end(); +}); + +tape( 'if provided `NaN`, the accumulated value ignores `NaN` and computes the minimum over valid values', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmin( 3 ); + + data = [ + NaN, // ignored + 3.14, // 3.14 + 3.14, // 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + NaN, // 3.14 (NaN ignored) + NaN, // (NaN ignored) + NaN, // (NaN ignored) + 3.14 // 3.14 + ]; + + expected = [ + null, // No valid numbers yet + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14 + ]; + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( expected[ i ] === null ) { + t.equal( v, null, 'returns expected value for window ' + i ); + } else { + t.equal( v, expected[ i ], 'returns expected value for window ' + i ); + } + } + t.end(); +}); \ No newline at end of file