diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/README.md b/lib/node_modules/@stdlib/stats/incr/nanmax/README.md new file mode 100644 index 000000000000..fe2c70bbc966 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/README.md @@ -0,0 +1,150 @@ + + +# incrnanmax + +> Compute a maximum value incrementally, while ignoring `NaN` values. + +
+ +## Usage + +```javascript +var incrnanmax = require( '@stdlib/stats/incr/nanmax' ); +``` + +#### incrnanmax() + +Returns an accumulator `function` which incrementally computes a maximum value, while ignoring `NaN` values. + +```javascript +var accumulator = incrnanmax(); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated maximum value. If not provided an input value `x`, the accumulator function returns the current maximum value. + +```javascript +var accumulator = incrnanmax(); + +var max = accumulator( 2.0 ); +// returns 2.0 + +max = accumulator( 1.0 ); +// returns 2.0 + +max = accumulator( NaN ); +// returns 2.0 + +max = accumulator( 3.0 ); +// returns 3.0 + +max = accumulator(); +// returns 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. +- For long running accumulations or accumulations of large numbers, care should be taken to prevent overflow. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmax = require( '@stdlib/stats/incr/nanmax' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmax(); + +// For each simulated datum, update the max... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmax/benchmark/benchmark.js new file mode 100644 index 000000000000..8b5b6cbb2083 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/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 incrnanmax = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmax(); + 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 = incrnanmax(); + + 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/nanmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmax/docs/repl.txt new file mode 100644 index 000000000000..07176edde16f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a maximum + value, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated maximum + value. If not provided a value, the accumulator function returns the current + maximum value. + + For long running accumulations or accumulations of large numbers, care + should be taken to prevent overflow. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var m = accumulator() + null + > m = accumulator( 3.14 ) + 3.14 + > m = accumulator( NaN ) + 3.14 + > m = accumulator( -5.0 ) + 3.14 + > m = accumulator( 10.1 ) + 10.1 + > m = accumulator() + 10.1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmax/docs/types/index.d.ts new file mode 100644 index 000000000000..a569138db5ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/docs/types/index.d.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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, returns an updated maximum value; otherwise, returns the current maximum value. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* +* @param x - value +* @returns maximum value +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a maximum value, while ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanmax(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( -4.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( 3.0 ); +* // returns 3.0 +* +* v = accumulator(); +* // returns 3.0 +*/ +declare function incrnanmax(): accumulator; + + +// EXPORTS // + +export = incrnanmax; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmax/docs/types/test.ts new file mode 100644 index 000000000000..2971390a00fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/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 incrnanmax = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmax(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanmax( '5' ); // $ExpectError + incrnanmax( 5 ); // $ExpectError + incrnanmax( true ); // $ExpectError + incrnanmax( false ); // $ExpectError + incrnanmax( null ); // $ExpectError + incrnanmax( undefined ); // $ExpectError + incrnanmax( [] ); // $ExpectError + incrnanmax( {} ); // $ExpectError + incrnanmax( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmax(); + + 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 = incrnanmax(); + + 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/nanmax/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmax/examples/index.js new file mode 100644 index 000000000000..abee9c8bc0b5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 incrnanmax = require( './../lib' ); + +var accumulator; +var max; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmax(); + +// For each simulated datum, update the max... +console.log( '\nValue\tMax\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + max = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), ( max === null ) ? NaN : max.toFixed( 4 ) ); +} +console.log( '\nFinal max: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmax/lib/index.js new file mode 100644 index 000000000000..496747f0cb46 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 maximum value incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmax +* +* @example +* var incrnanmax = require( '@stdlib/stats/incr/nanmax' ); +* +* var accumulator = incrnanmax(); +* +* var max = accumulator(); +* // returns null +* +* max = accumulator( 3.14 ); +* // returns 3.14 +* +* max = accumulator( NaN ); +* // returns 3.14 +* +* max = accumulator( -5.0 ); +* // returns 3.14 +* +* max = accumulator( 10.1 ); +* // returns 10.1 +* +* max = accumulator(); +* // returns 10.1 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmax/lib/main.js new file mode 100644 index 000000000000..b944d174654a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 incrmax = require( '@stdlib/stats/incr/max' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a maximum value, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmax(); +* +* var max = accumulator(); +* // returns null +* +* max = accumulator( 3.14 ); +* // returns 3.14 +* +* max = accumulator( NaN ); +* // returns 3.14 +* +* max = accumulator( -5.0 ); +* // returns 3.14 +* +* max = accumulator( 10.1 ); +* // returns 10.1 +* +* max = accumulator(); +* // returns 10.1 +*/ +function incrnanmax() { + var max = incrmax(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated maximum value. If not provided a value, the accumulator function returns the current max, while ignoring `NaN` values. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} max value or null + */ + function accumulator( x ) { + if ( arguments.length === 0 ) { + return max(); + } + if ( isnan( x ) ) { + return max(); + } + return max( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmax; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/package.json b/lib/node_modules/@stdlib/stats/incr/nanmax/package.json new file mode 100644 index 000000000000..ecdd4a17d7aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/incr/nanmax", + "version": "0.0.0", + "description": "Compute a maximum value incrementally, while 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", + "range", + "variance", + "domain", + "extent", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmax/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmax/test/test.js new file mode 100644 index 000000000000..31d2b230c507 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmax/test/test.js @@ -0,0 +1,117 @@ +/** +* @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 incrnanmax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmax(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'if not provided any values, the initial returned maximum value is `null`', function test( t ) { + var acc = incrnanmax(); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a maximum value, ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var d; + var i; + + data = [ 2.0, NaN, 3.0, NaN, 4.0, 3.0, NaN, 4.0 ]; + N = data.length; + + expected = [ 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0 ]; + actual = []; + + acc = incrnanmax(); + + for ( i = 0; i < N; i++ ) { + d = data[ i ]; + actual.push( acc( d ) ); + } + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current maximum value', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, NaN, 1.0 ]; + acc = incrnanmax(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 3.0, 'returns the current accumulated maximum value' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles signed zeros', function test( t ) { + var acc; + var v; + + acc = incrnanmax(); + + v = acc( -0.0 ); + t.equal( isNegativeZero( v ), true, 'returns expected value' ); + + v = acc( 0.0 ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); + + v = acc( -0.0 ); + t.equal( isPositiveZero( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it and continues computing max value', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnanmax(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 7.0, 'returns expected value' ); + t.end(); +});