From 62d5d2ee2f9c79103532ae5a3c16adc913430704 Mon Sep 17 00:00:00 2001 From: zl4624 Date: Sun, 30 Mar 2025 09:54:32 +0100 Subject: [PATCH 1/2] Implemented nanmminmaxabs --- .../stats/incr/nanmminmaxabs/README.md | 169 ++++++ .../incr/nanmminmaxabs/benchmark/benchmark.js | 69 +++ .../stats/incr/nanmminmaxabs/docs/repl.txt | 51 ++ .../incr/nanmminmaxabs/docs/types/index.d.ts | 113 ++++ .../incr/nanmminmaxabs/docs/types/test.ts | 78 +++ .../incr/nanmminmaxabs/examples/index.js | 42 ++ .../stats/incr/nanmminmaxabs/lib/index.js | 60 ++ .../stats/incr/nanmminmaxabs/lib/main.js | 98 ++++ .../stats/incr/nanmminmaxabs/package.json | 79 +++ .../stats/incr/nanmminmaxabs/test/test.js | 531 ++++++++++++++++++ 10 files changed, 1290 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md new file mode 100644 index 000000000000..46d7f2fc8f56 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md @@ -0,0 +1,169 @@ + + +# incrmminmaxabs + +> Compute moving minimum and maximum absolute values incrementally. + +
+ +## Usage + +```javascript +var incrnanmminmaxabs = require( '@stdlib/stats/incr/mminmaxabs' ); +``` + +#### incrnanmminmaxabs( \[out,] window ) + +Returns an accumulator `function` which incrementally computes moving minimum and maximum absolute values, ignoring `NaN` values. The `window` parameter defines the number of values over which to compute moving minimum and maximum absolute values. + +```javascript +var accumulator = incrnanmminmaxabs( 3 ); +``` + +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. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var accumulator = incrnanmminmaxabs( new Float64Array( 2 ), 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns updated minimum and maximum absolute values. If not provided an input value `x`, the accumulator function returns the current minimum and maximum absolute values. + +```javascript +var accumulator = incrnanmminmaxabs( 3 ); + +var mm = accumulator(); +// returns null + +// Fill the window... +mm = accumulator( 2.0 ); // [2.0] +// returns [ 2.0, 2.0 ] + +mm = accumulator( 1.0 ); // [2.0, 1.0] +// returns [ 1.0, 2.0 ] + +mm = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns [ 1.0, 3.0 ] + +// Window begins sliding... +mm = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns [ 1.0, 7.0 ] + +mm = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns [ 3.0, 7.0 ] + +mm = accumulator(); +// returns [ 3.0, 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 minimum and maximum values are calculated from smaller sample sizes. Until the window is full, each returned minimum and maximum is calculated from all provided values. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmminmaxabs = require( '@stdlib/stats/incr/mminmaxabs' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmminmaxabs( 5 ); + +// For each simulated datum, update the moving minimum and maximum absolute values... +for ( i = 0; i < 100; i++ ) { + v = ( randu()*100.0 ) - 50.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/benchmark/benchmark.js new file mode 100644 index 000000000000..54786f781a05 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/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( '@stdlib/stats/incr/nanmminmaxabs/package.json' ).name; +var incrnanmminmaxabs = require( '@stdlib/stats/incr/nanmminmaxabs/lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmminmaxabs( (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 = incrnanmminmaxabs( 5 ); + + 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/nanmminmaxabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/repl.txt new file mode 100644 index 000000000000..a7ec6d73b15c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( [out,] W ) + Returns an accumulator function which incrementally computes moving minimum + and maximum absolute values, ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute moving + minimum and maximum absolute values. + + If provided a value, the accumulator function returns an updated moving + minimum and maximum. If not provided a value, the accumulator function + returns the current moving minimum and maximum. + + As `W` values are needed to fill the window buffer, the first `W-1` returned + minimum and maximum values are calculated from smaller sample sizes. Until + the window is full, each returned minimum and maximum is calculated from all + provided values. + + Parameters + ---------- + out: Array|TypedArray (optional) + Output array. + + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var mm = accumulator() + null + > mm = accumulator( 2.0 ) + [ 2.0, 2.0 ] + > mm = accumulator( -5.0 ) + [ 2.0, 5.0 ] + > mm = accumulator( NaN ) + [ 2.0, 5.0 ] + > mm = accumulator( 3.0 ) + [ 2.0, 5.0 ] + > mm = accumulator( 5.0 ) + [ 3.0, 5.0 ] + > mm = accumulator() + [ 3.0, 5.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/index.d.ts new file mode 100644 index 000000000000..bd322bd5207c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/index.d.ts @@ -0,0 +1,113 @@ +/* +* @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 absolute values. If not provided a value, the accumulator function returns the current minimum and maximum absolute values. +* +* @param x - input value +* @returns output array or null +*/ +type accumulator = ( x?: number ) => ArrayLike | null; + +/** +* Returns an accumulator function which incrementally computes moving minimum and maximum absolute values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute moving minimum and maximum absolute values. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned minimum and maximum values are calculated from smaller sample sizes. Until the window is full, each returned minimum and maximum is calculated from all provided values. +* +* @param out - output array +* @param window - window size +* @throws window size must be a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmminmaxabs( 3 ); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( NaN ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ 3.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ 3.0, 5.0 ] +*/ +declare function incrmminmaxabs( out: ArrayLike, window: number ): accumulator; + +/** +* Returns an accumulator function which incrementally computes moving minimum and maximum absolute values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute moving minimum and maximum absolute values. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned minimum and maximum values are calculated from smaller sample sizes. Until the window is full, each returned minimum and maximum is calculated from all provided values. +* +* @param window - window size +* @throws window size must be a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmminmaxabs( 3 ); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( NaN ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ 3.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ 3.0, 5.0 ] +*/ +declare function incrmminmaxabs( window: number ): accumulator; + + +// EXPORTS // + +export = incrmminmaxabs; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/test.ts new file mode 100644 index 000000000000..6b43973c3e7b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/docs/types/test.ts @@ -0,0 +1,78 @@ +/* +* @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 incrnanmminmaxabs = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmminmaxabs( 3 ); // $ExpectType accumulator + const out = [ 0.0, 0.0 ]; + incrnanmminmaxabs( out, 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided a last argument that is not a number... +{ + incrnanmminmaxabs( '5' ); // $ExpectError + incrnanmminmaxabs( true ); // $ExpectError + incrnanmminmaxabs( false ); // $ExpectError + incrnanmminmaxabs( null ); // $ExpectError + incrnanmminmaxabs( {} ); // $ExpectError + incrnanmminmaxabs( ( x: number ): number => x ); // $ExpectError + + const out = [ 0.0, 0.0 ]; + incrnanmminmaxabs( out, '5' ); // $ExpectError + incrnanmminmaxabs( out, true ); // $ExpectError + incrnanmminmaxabs( out, false ); // $ExpectError + incrnanmminmaxabs( out, null ); // $ExpectError + incrnanmminmaxabs( out, {} ); // $ExpectError + incrnanmminmaxabs( out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an output array that is not an array-like object of numbers... +{ + incrnanmminmaxabs( '5', 3 ); // $ExpectError + incrnanmminmaxabs( true, 3 ); // $ExpectError + incrnanmminmaxabs( false, 3 ); // $ExpectError + incrnanmminmaxabs( null, 3 ); // $ExpectError + incrnanmminmaxabs( {}, 3 ); // $ExpectError + incrnanmminmaxabs( ( x: number ): number => x, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmminmaxabs( 3 ); + + 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 = incrnanmminmaxabs( 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/nanmminmaxabs/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/examples/index.js new file mode 100644 index 000000000000..bf0c9453e275 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/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 incrnanmminmaxabs = require( './../lib' ); + +var accumulator; +var mm; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmminmaxabs( 5 ); + +// For each simulated datum, update the moving minimum and maximum absolute values... +console.log( '\nValue\tMin Abs\tMax Abs\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = ( randu()*100.0 ) - 50.0; + } + mm = accumulator( v ); + console.log( '%d\t%s\t%s', v.toFixed( 3 ), ( mm === null ) ? NaN : mm[ 0 ].toFixed( 3 ), ( mm === null ) ? NaN : mm[ 1 ].toFixed( 3 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/index.js new file mode 100644 index 000000000000..e77d6cd725ca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/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 moving minimum and maximum absolute values incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmminmaxabs +* +* @example +* var incrnanmminmaxabs = require( '@stdlib/stats/incr/nanmminmaxabs' ); +* +* var accumulator = incrnanmminmaxabs( 3 ); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( NaN ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ 3.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ 3.0, 5.0 ] +*/ + +// MODULES // + +var main = require( '@stdlib/stats/incr/nanmminmaxabs/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/main.js new file mode 100644 index 000000000000..2212c2db84bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/lib/main.js @@ -0,0 +1,98 @@ +/** +* @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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isArrayLike = require( '@stdlib/assert/is-array-like-object' ); +var incrmminmax = require( '@stdlib/stats/incr/mminmax' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes moving minimum and maximum absolute values. +* +* @param {Collection} [out] - output array +* @param {PositiveInteger} window - window size +* @throws {TypeError} output argument must be array-like +* @throws {TypeError} window size must be a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmminmaxabs( 3 ); +* +* var mm = accumulator(); +* // returns null +* +* mm = accumulator( 2.0 ); +* // returns [ 2.0, 2.0 ] +* +* mm = accumulator( -5.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( NaN ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 3.0 ); +* // returns [ 2.0, 5.0 ] +* +* mm = accumulator( 5.0 ); +* // returns [ 3.0, 5.0 ] +* +* mm = accumulator(); +* // returns [ 3.0, 5.0 ] +*/ +function incrnanmminmaxabs( out, window ) { + var minmax; + var o; + var W; + if ( arguments.length === 1 ) { + o = [ 0.0, 0.0 ]; + W = out; + } else { + o = out; + W = window; + } + minmax = incrmminmax( o, W ); + return accumulator; + + /** + * If provided a value, the accumulator function returns updated minimum and maximum absolute values. If not provided a value, the accumulator function returns the current minimum and maximum absolute values. + * + * @private + * @param {number} [x] - input value + * @returns {(ArrayLikeObject|null)} output array or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return minmax(); + } + return minmax( abs( x ) ); + } +} + + +// EXPORTS // + +module.exports = incrnanmminmaxabs; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/package.json b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/package.json new file mode 100644 index 000000000000..fa67c111ab42 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/package.json @@ -0,0 +1,79 @@ +{ + "name": "@stdlib/stats/incr/mminmaxabs", + "version": "0.0.0", + "description": "Compute moving minimum and maximum absolute values incrementally.", + "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", + "absolute", + "value", + "abs", + "magnitude", + "dispersion", + "variance", + "range", + "extent", + "extrema", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving", + "rolling" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/test/test.js new file mode 100644 index 000000000000..794493b42392 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/test/test.js @@ -0,0 +1,531 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmminmaxabs = require( '@stdlib/stats/incr/nanmminmaxabs/lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmminmaxabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer for the window size', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + 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() { + incrnanmminmaxabs( value ); + }; + } +}); + +tape( 'the function throws an error if not provided a positive integer for the window size (output argument)', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + 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() { + incrnanmminmaxabs( [ 0.0, 0.0 ], value ); + }; + } +}); + +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() { + incrnanmminmaxabs( value, 3 ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmminmaxabs( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (output)', function test( t ) { + t.equal( typeof incrnanmminmaxabs( [ 0.0, 0.0 ], 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes moving minimum and maximum absolute values incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ + 2.0, + NaN, + -3.0, + -2.0, + 4.0, + -3.0, + 4.0, + NaN, + -2.0, + 2.0, + -2.0, + -1.0, + 0.0, + NaN, + 4.0, + -1.0 + ]; + N = data.length; + + acc = incrnanmminmaxabs( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( ( acc( data[ i ] ) ).slice() ); + } + expected = [ + [ 2.0, 2.0 ], + [ 2.0, 2.0 ], + [ 2.0, 3.0 ], + [ 2.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 2.0 ], + [ 1.0, 2.0 ], + [ 0.0, 2.0 ], + [ 0.0, 2.0 ], + [ 0.0, 4.0 ], + [ 0.0, 4.0 ] + ]; + + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the accumulator function computes moving minimum and maximum absolute values incrementally (output)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var out; + var N; + var i; + + data = [ + 2.0, + NaN, + -3.0, + -2.0, + 4.0, + -3.0, + 4.0, + NaN, + -2.0, + 2.0, + -2.0, + -1.0, + 0.0, + NaN, + 4.0, + -1.0 + ]; + N = data.length; + + out = [ 0.0, 0.0 ]; + acc = incrnanmminmaxabs( out, 3 ); + + 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, 2.0 ], + [ 2.0, 3.0 ], + [ 2.0, 3.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 3.0, 4.0 ], + [ 3.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 4.0 ], + [ 2.0, 2.0 ], + [ 1.0, 2.0 ], + [ 0.0, 2.0 ], + [ 0.0, 2.0 ], + [ 0.0, 4.0 ], + [ 0.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 absolute values', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, -3.0, -5.0, 4.0 ]; + acc = incrnanmminmaxabs( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.deepEqual( acc(), [ 4.0, 5.0 ], 'returns expected value' ); + t.end(); +}); + +tape( 'if no valid data has been provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmminmaxabs( 3 ); + + t.equal( acc(), null, 'returns null initially' ); + + acc( NaN ); + acc( NaN ); + acc( NaN ); + + t.equal( acc(), null, 'returns null after providing only NaNs' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles signed zeros', function test( t ) { + var expected; + var data; + var sgn1; + var sgn2; + var acc; + var v; + var i; + + acc = incrnanmminmaxabs( 3 ); + + data = [ + 0.0, // 0 => min: 0.0, max: 0.0 (0) + -0.0, // 0, -0 => min: -0.0, max: 0.0 (1) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (2) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (3) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (4) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (5) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (6) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (7) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (8) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (9) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (10) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (11) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (12) + + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (13) + 0.0, // 0, -0, 0 => min: -0.0, max: 0.0 (14) + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (15) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (16) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (17) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (18) + -0.0, // -0, 0, -0 => min: -0.0, max: 0.0 (19) + -0.0, // 0, -0, -0 => min: -0.0, max: 0.0 (20) + -0.0, // -0, -0, -0 => min: -0.0, max: -0.0 (21) + 0.0, // -0, -0, 0 => min: -0.0, max: 0.0 (22) + 0.0, // -0, 0, 0 => min: -0.0, max: 0.0 (23) + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 (24) + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 (25) + + // Case 1: out: -0, in: +0, cnt: 1 + 3.14, // 0, -0, 3.14 => min: -0.0, max: 3.14 + 3.14, // -0, 3.14, 3.14 => min: -0.0, max: 3.14 + 0.0, // 3.14, 3.14, 0 => min: 0.0, max: 3.14 + + // Case 2: out: +0, in: -0, cnt: 1 + 3.14, // 3.14, 0, 3.14 => min: 0.0, max: 3.14 + 3.14, // 0, 3.14, 3.14 => min: 0.0, max: 3.14 + -0.0, // 3.14, 3.14, -0 => min: -0.0, max: 3.14 + + // Case 3: out: -0, in: -0, cnt: 1 + 3.14, // 3.14, -0, 3.14 => min: -0.0, max: 3.14 + 3.14, // -0, 3.14, 3.14 => min: -0.0, max: 3.14 + -0.0, // 3.14, 3.14, -0 => min: -0.0, max: 3.14 + + // Case 4: out: -0, in: +0, cnt: 2 + 3.14, // 3.14, -0, 3.14 => min: -0.0, max: 3.14 + -0.0, // -0, 3.14, -0 => min: -0.0, max: 3.14 + 0.0, // 3.14, -0, 0 => min: -0.0, max: 3.14 + + // Case 5: out: +0, in: +0, cnt: 1 + 3.14, // -0, 0, 3.14 => min: -0.0, max: 3.14 + 3.14, // 0, 3.14, 3.14 => min: 0.0, max: 3.14 + 0.0, // 3.14, 3.14, 0 => min: 0.0, max: 3.14 + + // Case 6: out: +0, in: -0, cnt: 2 + 3.14, // 3.14, 0, 3.14 => min: 0.0, max: 3.14 + -0.0, // 0, 3.14, -0 => min: -0.0, max: 3.14 + 0.0, // 3.14, -0, 0 => min: -0.0, max: 3.14 + + // Case 7: out: +0, in: +0, cnt: 2 + 3.14, // -0, 0, 3.14 => min: -0.0, max: 3.14 + 0.0, // 0, 3.14, 0 => min: 0.0, max: 3.14 + 0.0, // 3.14, 0, 0 => min: 0.0, max: 3.14 + + // Reset: + -0.0, // 0, 0, -0 => min: -0.0, max: 0.0 + + // Case 8: out: -0, in: +0, cnt: 1 + -3.14, // 0, -0, -3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + 0.0, // -3.14, -3.14, 0 => min: -3.14, max: 0.0 + + // Case 9: out: +0, in: -0, cnt: 1 + -3.14, // -3.14, 0, 3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + -0.0, // -3.14, -3.14, -0 => min: -3.14, max: -0.0 + + // Case 10: out: -0, in: -0, cnt: 1 + -3.14, // -3.14, -0, -3.14 => min: -3.14, max: -0.0 + -3.14, // -0, -3.14, -3.14 => min: -3.14, max: -0.0 + -0.0, // -3.14, -3.14, -0 => min: -3.14, max: -0.0 + + // Case 11: out: -0, in: +0, cnt: 2 + -3.14, // -3.14, -0, -3.14 => min: -3.14, max: -0.0 + -0.0, // -0, -3.14, -0 => min: -3.14, max: -0.0 + 0.0, // -3.14, -0, 0 => min: -3.14, max: 0.0 + + // Case 12: out: +0, in: +0, cnt: 1 + -3.14, // -0, 0, -3.14 => min: -3.14, max: 0.0 + -3.14, // 0, -3.14, -3.14 => min: -3.14, max: 0.0 + 0.0, // -3.14, -3.14, 0 => min: -3.14, max: 0.0 + + // Case 13: out: +0, in: -0, cnt: 2 + -3.14, // -3.14, 0, -3.14 => min: -3.14, max: 0.0 + -0.0, // 0, -3.14, -0 => min: -3.14, max: 0.0 + 0.0, // -3.14, -0, 0 => min: -3.14, max: 0.0 + + // Case 14: out: +0, in: +0, cnt: 2 + -3.14, // -0, 0, -3.14 => min: -3.14, max: 0.0 + 0.0, // 0, -3.14, 0 => min: -3.14, max: 0.0 + 0.0, // -3.14, 0, 0 => min: -3.14, max: 0.0 + + // Reset: + 0.0, // 0, 0, 0 => min: 0.0, max: 0.0 + + // Case 15: out: +0, in: -0, cnt: 2 + -3.14, // 0, 0, -3.14 => min: -3.14, max: 0.0 + 0.0, // 0, -3.14, 0 => min: -3.14, max: 0.0 + -0.0 // -3.14, 0, -0 => min: -3.14, max: 0.0 + ]; + expected = [ + [ 0.0, 0.0, 0 ], + [ 0.0, 0.0, 1 ], + [ 0.0, 0.0, 2 ], + [ 0.0, 0.0, 3 ], + [ 0.0, 0.0, 4 ], + [ 0.0, 0.0, 5 ], + [ 0.0, 0.0, 6 ], + [ 0.0, 0.0, 7 ], + [ 0.0, 0.0, 8 ], + [ 0.0, 0.0, 9 ], + [ 0.0, 0.0, 10 ], + [ 0.0, 0.0, 11 ], + [ 0.0, 0.0, 12 ], + + [ 0.0, 0.0, 13 ], + [ 0.0, 0.0, 14 ], + [ 0.0, 0.0, 15 ], + [ 0.0, 0.0, 16 ], + [ 0.0, 0.0, 17 ], + [ 0.0, 0.0, 18 ], + [ 0.0, 0.0, 19 ], + [ 0.0, 0.0, 20 ], + [ 0.0, 0.0, 21 ], + [ 0.0, 0.0, 22 ], + [ 0.0, 0.0, 23 ], + [ 0.0, 0.0, 24 ], + [ 0.0, 0.0, 25 ], + + // Case 1: + [ 0.0, 3.14, 26 ], + [ 0.0, 3.14, 27 ], + [ 0.0, 3.14, 28 ], + + // Case 2: + [ 0.0, 3.14, 29 ], + [ 0.0, 3.14, 30 ], + [ 0.0, 3.14, 31 ], + + // Case 3: + [ 0.0, 3.14, 32 ], + [ 0.0, 3.14, 33 ], + [ 0.0, 3.14, 34 ], + + // Case 4: + [ 0.0, 3.14, 35 ], + [ 0.0, 3.14, 36 ], + [ 0.0, 3.14, 37 ], + + // Case 5: + [ 0.0, 3.14, 38 ], + [ 0.0, 3.14, 39 ], + [ 0.0, 3.14, 40 ], + + // Case 6: + [ 0.0, 3.14, 41 ], + [ 0.0, 3.14, 42 ], + [ 0.0, 3.14, 43 ], + + // Case 7: + [ 0.0, 3.14, 44 ], + [ 0.0, 3.14, 45 ], + [ 0.0, 3.14, 46 ], + + // Reset: + [ 0.0, 0.0, 47 ], + + // Case 8: + [ 0.0, 3.14, 48 ], + [ 0.0, 3.14, 49 ], + [ 0.0, 3.14, 50 ], + + // Case 9: + [ 0.0, 3.14, 51 ], + [ 0.0, 3.14, 52 ], + [ 0.0, 3.14, 53 ], + + // Case 10: + [ 0.0, 3.14, 54 ], + [ 0.0, 3.14, 55 ], + [ 0.0, 3.14, 56 ], + + // Case 11: + [ 0.0, 3.14, 57 ], + [ 0.0, 3.14, 58 ], + [ 0.0, 3.14, 59 ], + + // Case 12: + [ 0.0, 3.14, 60 ], + [ 0.0, 3.14, 61 ], + [ 0.0, 3.14, 62 ], + + // Case 13: + [ 0.0, 3.14, 63 ], + [ 0.0, 3.14, 64 ], + [ 0.0, 3.14, 65 ], + + // Case 14: + [ 0.0, 3.14, 66 ], + [ 0.0, 3.14, 67 ], + [ 0.0, 3.14, 68 ], + + // Reset: + [ 0.0, 0.0, 69 ], + + // Case 15: + [ 0.0, 3.14, 70 ], + [ 0.0, 3.14, 71 ], + [ 0.0, 3.14, 72 ] + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( expected[ i ][ 0 ] === 0.0 ) { + sgn1 = isNegativeZero( v[ 0 ] ); + sgn2 = isNegativeZero( expected[ i ][ 0 ] ); + t.equal( sgn1, sgn2, 'returns expected signed zero minimum for window '+i+'. v: '+( ( isNegativeZero( data[ i ] ) ) ? '-' : '+' )+data[ i ]+'. actual: '+( ( sgn1 ) ? '-' : '+' )+v[ 0 ]+'. expected: '+( ( sgn2 ) ? '-' : '+' )+expected[ i ][ 0 ]+'.' ); + } else { + t.equal( v[ 0 ], expected[ i ][ 0 ], 'returns expected minimum for window '+i+'. v: '+data[ i ]+'. actual: '+v[ 0 ]+'. expected: '+expected[ i ][ 0 ]+'.' ); + } + if ( expected[ i ][ 1 ] === 0.0 ) { + sgn1 = isNegativeZero( v[ 1 ] ); + sgn2 = isNegativeZero( expected[ i ][ 1 ] ); + t.equal( sgn1, sgn2, 'returns expected signed zero maximum for window '+i+'. v: '+( ( isNegativeZero( data[ i ] ) ) ? '-' : '+' )+data[ i ]+'. actual: '+( ( sgn1 ) ? '-' : '+' )+v[ 1 ]+'. expected: '+( ( sgn2 ) ? '-' : '+' )+expected[ i ][ 1 ]+'.' ); + } else { + t.equal( v[ 1 ], expected[ i ][ 1 ], 'returns expected maximum for window '+i+'. v: '+data[ i ]+'. actual: '+v[ 1 ]+'. expected: '+expected[ i ][ 1 ]+'.' ); + } + } + t.end(); +}); From 565997e09d6c5bd26ca1ae8300798bbbc7fbcfa7 Mon Sep 17 00:00:00 2001 From: zl4624 Date: Sun, 30 Mar 2025 10:14:48 +0100 Subject: [PATCH 2/2] Fix linting errors --- lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md index 46d7f2fc8f56..66d0e57cf692 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmminmaxabs/README.md @@ -131,11 +131,17 @@ console.log( accumulator() ); - [`@stdlib/stats/incr/mminmaxabs][@stdlib/stats/incr/mminmaxabs] : compute moving minimum and maximum absolute values incrementally. + - [`@stdlib/stats/incr/minmaxabs`][@stdlib/stats/incr/minmaxabs]: compute minimum and maximum absolute values incrementally. + - [`@stdlib/stats/incr/mmax`][@stdlib/stats/incr/mmax]: compute a moving maximum incrementally. + - [`@stdlib/stats/incr/mmaxabs`][@stdlib/stats/incr/mmaxabs]: compute a moving maximum absolute value incrementally. + - [`@stdlib/stats/incr/mmin`][@stdlib/stats/incr/mmin]: compute a moving minimum incrementally. + - [`@stdlib/stats/incr/mminabs`][@stdlib/stats/incr/mminabs]: compute a moving minimum absolute value incrementally. + - [`@stdlib/stats/incr/mminmax`][@stdlib/stats/incr/mminmax]: compute a moving minimum and maximum incrementally.