From 511d980eb59bd201f0044b72ee50906cb72d8a65 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Wed, 12 Mar 2025 20:12:42 +0530 Subject: [PATCH 1/5] feat: add nanminmax package to handle NaN values --- .../@stdlib/stats/incr/nanminmax/README.md | 157 ++++++++++++ .../incr/nanminmax/benchmark/benchmark.js | 69 ++++++ .../stats/incr/nanminmax/docs/repl.txt | 40 ++++ .../incr/nanminmax/docs/types/index.d.ts | 68 ++++++ .../stats/incr/nanminmax/docs/types/test.ts | 61 +++++ .../stats/incr/nanminmax/examples/index.js | 42 ++++ .../@stdlib/stats/incr/nanminmax/lib/index.js | 60 +++++ .../@stdlib/stats/incr/nanminmax/lib/main.js | 87 +++++++ .../@stdlib/stats/incr/nanminmax/package.json | 70 ++++++ .../@stdlib/stats/incr/nanminmax/test/test.js | 223 ++++++++++++++++++ 10 files changed, 877 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md new file mode 100644 index 000000000000..91d24bbab542 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md @@ -0,0 +1,157 @@ + + +# incrnanminmax + +> Compute a minimum and maximum incrementally, ignoring `NaN` values. + +
+ +## Usage + +```javascript +var incrnanminmax = require( '@stdlib/stats/incr/nanminmax' ); +``` + +#### incrnanminmax( \[out] ) + +Returns an accumulator `function` which incrementally computes a minimum and maximum, ignoring `NaN` values. + +```javascript +var accumulator = incrnanminmax(); +``` + +By default, the returned accumulator `function` returns the minimum and maximum as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. + + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns updated minimum and maximum values. If not provided an input value `x`, the accumulator function returns the current minimum and maximum values. + +```javascript +var accumulator = incrnanminmax(); + +var mm = accumulator(); +// returns null + +mm = accumulator( 2.0 ); +// returns [ 2.0, 2.0 ] + +mm = accumulator( 1.0 ); +// returns [ 1.0, 2.0 ] + +mm = accumulator( 3.0 ); +// returns [ 1.0, 3.0 ] + +mm = accumulator( -7.0 ); +// returns [ -7.0, 3.0 ] + +mm = accumulator( NaN ); +// returns [ -7.0, 3.0 ] + +mm = accumulator( -5.0 ); +// returns [ -7.0, 3.0 ] + +mm = accumulator(); +// returns [ -7.0, 3.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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanminmax = require( '@stdlib/stats/incr/nanminmax' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanminmax(); + +// For each simulated datum, update the minimum and maximum... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/benchmark/benchmark.js new file mode 100644 index 000000000000..369745414825 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/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 incrnanminmax = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanminmax(); + 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 = incrnanminmax(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v.length !== 2 ) { + b.fail( 'should contain two elements' ); + } + } + b.toc(); + if ( v[ 0 ] !== v[ 0 ] || v[ 1 ] !== v[ 1 ] ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt new file mode 100644 index 000000000000..4a5ec35d5c91 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( [out] ) + Returns an accumulator function which incrementally computes a minimum and + maximum, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated minimum and + maximum. If not provided a value, the accumulator function returns the + current minimum and maximum. + + Parameters + ---------- + out: Array|TypedArray (optional) + Output array. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var mm = accumulator() + null + > mm = accumulator( 2.0 ) + [ 2.0, 2.0 ] + > mm = accumulator( -5.0 ) + [ -5.0, 2.0 ] + > mm = accumulator( 3.0 ) + [ -5.0, 3.0 ] + > mm = accumulator( NaN ) + [ -5.0, 3.0 ] + > mm = accumulator( 5.0 ) + [ -5.0, 5.0 ] + > mm = accumulator() + [ -5.0, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts new file mode 100644 index 000000000000..47dd889a88a0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts @@ -0,0 +1,68 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; + +/** +* If provided a value, the accumulator function returns updated minimum and maximum values. If not provided a value, the accumulator function returns the current minimum and maximum values. +* +* @param x - input value +* @returns output array or null +*/ +type accumulator = ( x?: number ) => ArrayLike | null; + +/** +* Returns an accumulator function which incrementally computes minimum and maximum values. +* +* @param out - output array +* @returns accumulator function +* +* @example +* var accumulator = incrminmax(); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ -5.0, 2.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( NaN ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ -5.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ -5.0, 5.0 ] +*/ +declare function incrnanminmax( out?: ArrayLike ): accumulator; + + +// EXPORTS // + +export = incrnanminmax; diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/test.ts new file mode 100644 index 000000000000..ad697883cf09 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/test.ts @@ -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. +*/ + +import incrnanminmax = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanminmax(); // $ExpectType accumulator + const out = [ 0.0, 0.0 ]; + incrnanminmax( out ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not an array-like object of numbers... +{ + incrnanminmax( '5' ); // $ExpectError + incrnanminmax( 5 ); // $ExpectError + incrnanminmax( true ); // $ExpectError + incrnanminmax( false ); // $ExpectError + incrnanminmax( null ); // $ExpectError + incrnanminmax( {} ); // $ExpectError + incrnanminmax( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanminmax(); + + acc(); // $ExpectType ArrayLike | null + acc( 3.14 ); // $ExpectType ArrayLike | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanminmax(); + + 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/nanminmax/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/examples/index.js new file mode 100644 index 000000000000..409a7ecb827d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanminmax = require( './../lib' ); + +var accumulator; +var mm; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanminmax(); + +// For each simulated datum, update the minimum and maximum... +console.log( '\nValue\tMin\tMax\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + mm = accumulator( v ); + console.log( '%d\t%d\t%d', v.toFixed( 4 ), ( mm === null ) ? NaN : mm[ 0 ].toFixed( 4 ), ( mm === null ) ? NaN : mm[ 1 ].toFixed( 4 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js new file mode 100644 index 000000000000..050c117fd0db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/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 minimum and maximum incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanminmax +* +* @example +* var incrminmax = require( '@stdlib/stats/incr/nanminmax' ); +* +* var accumulator = incrnanminmax(); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ -5.0, 2.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( NaN ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ -5.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ -5.0, 5.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js new file mode 100644 index 000000000000..b6b6607696eb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js @@ -0,0 +1,87 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrminmax = require( '@stdlib/stats/incr/minmax' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes minimum and maximum values, ignoring `NaN` values. +* +* @param {Collection} [out] - output array +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrminmax(); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ -5.0, 2.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( NaN ); +* // returns [ -5.0, 3.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ -5.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ -5.0, 5.0 ] +*/ +function incrnanminmax( out ) { + var nanminmax; + if ( arguments.length === 0 ) { + nanminmax = incrminmax(); + } + else { + nanminmax = incrminmax( out ); + } + return accumulator; + + /** + * If provided a value, the accumulator function returns updated minimum and maximum values. If not provided a value, the accumulator function returns the current minimum and maximum values. + * + * @private + * @param {number} [x] - input value + * @returns {(ArrayLikeObject|null)} output array or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return nanminmax(); + } + return nanminmax( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanminmax; diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/package.json b/lib/node_modules/@stdlib/stats/incr/nanminmax/package.json new file mode 100644 index 000000000000..778cd69e0378 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/stats/incr/nanminmax", + "version": "0.0.0", + "description": "Compute a minimum and maximum 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", + "maximum", + "max", + "minimum", + "min", + "dispersion", + "variance", + "range", + "extent", + "extrema", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js new file mode 100644 index 000000000000..d51d684b8d18 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js @@ -0,0 +1,223 @@ +/** +* @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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var incrnanminmax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanminmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an array-like object for an output argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + true, + false, + null, + void 0, + NaN, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanminmax( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanminmax(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (output)', function test( t ) { + t.equal( typeof incrnanminmax( [ 0.0, 0.0 ] ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a minimum and maximum incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 2.0, 4.0, NaN, 4.0, 2.0, 2.0, NaN, 1.0, 0.0, 4.0, -1.0 ]; + N = data.length; + + acc = incrnanminmax(); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( ( acc( data[ i ] ) ).slice() ); + } + expected = [ + [ 2.0, 2.0 ], + [ 2.0, 3.0 ], + [ 2.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 1.0, 4.0 ], + [ 0.0, 4.0 ], + [ 0.0, 4.0 ], + [ -1.0, 4.0 ] + ]; + + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the accumulator function computes a minimum and maximum incrementally (output)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var out; + var N; + var i; + + data = [ 2.0, 3.0, 2.0, 4.0, NaN, 4.0, 2.0, 2.0, NaN, 1.0, 0.0, 4.0, -1.0 ]; + N = data.length; + + out = [ 0.0, 0.0 ]; + acc = incrnanminmax( out ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + t.equal( actual[ i ], out, 'returns output array' ); + actual[ i ] = actual[ i ].slice(); + } + expected = [ + [ 2.0, 2.0 ], + [ 2.0, 3.0 ], + [ 2.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 1.0, 4.0 ], + [ 0.0, 4.0 ], + [ 0.0, 4.0 ], + [ -1.0, 4.0 ] + ]; + + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current minimum and maximum values', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 5.0, 4.0 ]; + acc = incrnanminmax(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.deepEqual( acc(), [ 2.0, 5.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanminmax(); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles signed zeros', function test( t ) { + var acc; + var v; + + acc = incrnanminmax(); + + v = acc( 0.0 ); + t.equal( isPositiveZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + v = acc( -0.0 ); + t.equal( isNegativeZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + v = acc( 0.0 ); + t.equal( isNegativeZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + acc = incrnanminmax(); + + v = acc( -0.0 ); + t.equal( isNegativeZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isNegativeZero( v[ 1 ] ), true, 'returns expected value' ); + + v = acc( 0.0 ); + t.equal( isNegativeZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + v = acc( -0.0 ); + t.equal( isNegativeZero( v[ 0 ] ), true, 'returns expected value' ); + t.equal( isPositiveZero( v[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `NaN`, the accumulated minimum and maximum values remain unchanged', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ 2.0, NaN, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnanminmax(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + v = acc(); + t.equal( v[ 0 ], 1.0, false, 'returns expected value' ); + t.equal( v[ 1 ], 7.0, false, 'returns expected value' ); + t.end(); +}); From f71eed20166361dd47d4bf47b53d10297ce16310 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 20:24:13 +0530 Subject: [PATCH 2/5] update main.js --- lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js index b6b6607696eb..ff28163441dd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js @@ -33,7 +33,7 @@ var incrminmax = require( '@stdlib/stats/incr/minmax' ); * @returns {Function} accumulator function * * @example -* var accumulator = incrminmax(); +* var accumulator = incrnanminmax(); * * var mm = accumulator(); * // returns null From 37d221019913faf014f108b62cf8c22805abd29b Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Sat, 15 Mar 2025 13:45:05 +0530 Subject: [PATCH 3/5] made suggested change --- .../@stdlib/stats/incr/nanminmax/README.md | 7 ++----- .../@stdlib/stats/incr/nanminmax/docs/repl.txt | 2 +- .../@stdlib/stats/incr/nanminmax/lib/main.js | 13 ++++++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md index 91d24bbab542..fa92c5915085 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md @@ -32,15 +32,12 @@ var incrnanminmax = require( '@stdlib/stats/incr/nanminmax' ); #### incrnanminmax( \[out] ) -Returns an accumulator `function` which incrementally computes a minimum and maximum, ignoring `NaN` values. +Returns an accumulator function which incrementally computes a minimum and maximum, ignoring `NaN` values. ```javascript var accumulator = incrnanminmax(); ``` -By default, the returned accumulator `function` returns the minimum and maximum as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. - - #### accumulator( \[x] ) If provided an input value `x`, the accumulator function returns updated minimum and maximum values. If not provided an input value `x`, the accumulator function returns the current minimum and maximum values. @@ -112,7 +109,7 @@ for ( i = 0; i < 100; i++ ) { v = randu() * 100.0; } } -console.log( accumulator() ); +console.log( accumulator( v ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt index 4a5ec35d5c91..467c4e1df6ba 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( [out] ) Returns an accumulator function which incrementally computes a minimum and - maximum, ignoring `NaN` values. + maximum,, ignoring `NaN` values. If provided a value, the accumulator function returns an updated minimum and maximum. If not provided a value, the accumulator function returns the diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js index ff28163441dd..5f2d4b133342 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/main.js @@ -57,12 +57,11 @@ var incrminmax = require( '@stdlib/stats/incr/minmax' ); * // returns [ -5.0, 5.0 ] */ function incrnanminmax( out ) { - var nanminmax; + var minmax; if ( arguments.length === 0 ) { - nanminmax = incrminmax(); - } - else { - nanminmax = incrminmax( out ); + minmax = incrminmax(); + } else { + minmax = incrminmax( out ); } return accumulator; @@ -75,9 +74,9 @@ function incrnanminmax( out ) { */ function accumulator( x ) { if ( arguments.length === 0 || isnan( x ) ) { - return nanminmax(); + return minmax(); } - return nanminmax( x ); + return minmax( x ); } } From dbff122f84f5a6a50113cfd972f5e3c6f609b2c8 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 27 Sep 2025 15:06:21 -0500 Subject: [PATCH 4/5] chore: minor clean-up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanminmax/README.md | 3 ++- .../@stdlib/stats/incr/nanminmax/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md index fa92c5915085..d253ba8c33cf 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/README.md @@ -108,8 +108,9 @@ for ( i = 0; i < 100; i++ ) { } else { v = randu() * 100.0; } + accumulator( v ); } -console.log( accumulator( v ) ); +console.log( accumulator() ); ``` diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts index 47dd889a88a0..69950d9d50da 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/types/index.d.ts @@ -37,7 +37,7 @@ type accumulator = ( x?: number ) => ArrayLike | null; * @returns accumulator function * * @example -* var accumulator = incrminmax(); +* var accumulator = incrnanminmax(); * * var mm = accumulator(); * // returns null diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js index 050c117fd0db..4d19e0f3fdd7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/lib/index.js @@ -24,7 +24,7 @@ * @module @stdlib/stats/incr/nanminmax * * @example -* var incrminmax = require( '@stdlib/stats/incr/nanminmax' ); +* var incrnanminmax = require( '@stdlib/stats/incr/nanminmax' ); * * var accumulator = incrnanminmax(); * diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js index d51d684b8d18..9a4ef628ccab 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/test/test.js @@ -217,7 +217,7 @@ tape( 'if provided `NaN`, the accumulated minimum and maximum values remain unch acc( data[ i ] ); } v = acc(); - t.equal( v[ 0 ], 1.0, false, 'returns expected value' ); - t.equal( v[ 1 ], 7.0, false, 'returns expected value' ); + t.equal( v[ 0 ], 1.0, 'returns expected value' ); + t.equal( v[ 1 ], 7.0, 'returns expected value' ); t.end(); }); From 521a40ce17932025a37594e1faadf778a1d9f577 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 27 Sep 2025 15:12:06 -0500 Subject: [PATCH 5/5] docs: remove extra comma Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt index 467c4e1df6ba..4a5ec35d5c91 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanminmax/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( [out] ) Returns an accumulator function which incrementally computes a minimum and - maximum,, ignoring `NaN` values. + maximum, ignoring `NaN` values. If provided a value, the accumulator function returns an updated minimum and maximum. If not provided a value, the accumulator function returns the