From c2e9f5cd8b96c4c741154288e420680044047006 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 16:43:41 +0530 Subject: [PATCH 01/11] feat: setup `stats/incr/nanmprod` --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - 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: na - 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 --- --- .../@stdlib/stats/incr/nanmprod/lib/index.js | 60 ++++++++++++++ .../@stdlib/stats/incr/nanmprod/lib/main.js | 82 +++++++++++++++++++ .../@stdlib/stats/incr/nanmprod/package.json | 71 ++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/package.json diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js new file mode 100644 index 000000000000..c566bb518f7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 product incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmprod +* +* @example +* var incrnanmprod = require( '@stdlib/stats/incr/nanmprod' ); +* +* var accumulator = incrnanmprod( 3 ); +* +* var p = accumulator(); +* // returns null +* +* p = accumulator( 2.0 ); +* // returns 2.0 +* +* p = accumulator( -5.0 ); +* // returns -10.0 +* +* p = accumulator( NaN ); +* // returns -10.0 +* +* p = accumulator( 3.0 ); +* // returns -30.0 +* +* p = accumulator( 5.0 ); +* // returns -75.0 +* +* p = accumulator(); +* // returns -75.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js new file mode 100644 index 000000000000..83d79ddc3d60 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 incrmprod = require( '@stdlib/stats/incr/mprod' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving product, ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmprod( 3 ); +* +* var p = accumulator(); +* // returns null +* +* p = accumulator( 2.0 ); +* // returns 2.0 +* +* p = accumulator( -5.0 ); +* // returns -10.0 +* +* p = accumulator( 3.0 ); +* // returns -30.0 +* +* p = accumulator( 5.0 ); +* // returns -75.0 +* +* p = accumulator(); +* // returns -75.0 +*/ +function incrnanmprod( W ) { + var acc = incrmprod( W ); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated product. If not provided a value or provided `NaN` values, the accumulator function returns the current product. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} product or null + */ + function accumulator( x ) { + if ( arguments.length === 0 ) { + return acc(); + } + if ( isnan(x) ) { + return acc(); + } + return acc( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmprod; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json b/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json new file mode 100644 index 000000000000..748cdc058df8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/incr/mprod", + "version": "0.0.0", + "description": "Compute a moving product 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", + "product", + "prod", + "incremental", + "accumulator", + "moving prod", + "moving product", + "sliding window", + "sliding", + "window", + "moving", + "nan", + "ignore" + ] +} From 5b86ec216ca7cb2f1c15b3f2f8218152340e3e05 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 16:47:55 +0530 Subject: [PATCH 02/11] docs: add README.md --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 --- --- .../@stdlib/stats/incr/nanmprod/README.md | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/README.md diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md new file mode 100644 index 000000000000..a53917ad9580 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md @@ -0,0 +1,217 @@ + + +# incrnanmprod + +> Compute a moving product incrementally, ignoring `NaN` values. + +
+ +For a window of size `W`, the moving product is defined as + + + +```math +\prod_{i=0}^{W-1} x_i +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmprod = require( '@stdlib/stats/incr/nanmprod' ); +``` + +#### incrnanmprod( window ) + +Returns an accumulator `function` which incrementally computes a moving product. The `window` parameter defines the number of values over which to compute the moving product. + +```javascript +var accumulator = incrnanmprod( 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated product. If not provided an input value `x` or provided a `NaN` value, the accumulator function returns the current product. + +```javascript +var accumulator = incrnanmprod( 3 ); + +var p = accumulator(); +// returns null + +// Fill the window... +p = accumulator( 2.0 ); // [2.0] +// returns 2.0 + +p = accumulator( 1.0 ); // [2.0, 1.0] +// returns 2.0 + +p = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns 6.0 + +// Window begins sliding... +p = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns -21.0 + +p = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns 105.0 + +p = accumulator(); +// returns 105.0 +``` + +Under certain conditions, overflow may be transient. + +```javascript +// Large values: +var x = 5.0e+300; +var y = 1.0e+300; + +// Tiny value: +var z = 2.0e-302; + +// Initialize an accumulator: +var accumulator = incrnanmprod( 3 ); + +var p = accumulator( x ); +// returns 5.0e+300 + +// Transient overflow: +p = accumulator( y ); +// returns Infinity + +// Recover a finite result: +p = accumulator( z ); +// returns 1.0e+299 +``` + +Similarly, under certain conditions, underflow may be transient. + +```javascript +// Tiny values: +var x = 4.0e-302; +var y = 9.0e-303; + +// Large value: +var z = 2.0e+300; + +// Initialize an accumulator: +var accumulator = incrnanmprod( 3 ); + +var p = accumulator( x ); +// returns 4.0e-302 + +// Transient underflow: +p = accumulator( y ); +// returns 0.0 + +// Recover a non-zero result: +p = accumulator( z ); +// returns 7.2e-304 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **at least** `W-1` future invocations. 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. +- For large accumulation windows or accumulations of either large or small numbers, care should be taken to prevent overflow and underflow. Note, however, that overflow/underflow may be transient, as the accumulator does not use a double-precision floating-point number to store an accumulated product. Instead, the accumulator splits an accumulated product into a normalized **fraction** and **exponent** and updates each component separately. Doing so guards against a loss in precision. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmprod = require( '@stdlib/stats/incr/nanmprod' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmprod( 5 ); + +// For each simulated datum, update the moving product... +for ( i = 0; i < 100; i++ ) { + v = ( randu()*10.0 ) - 5.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + From ac2bd1bd9c15b9f6703385e2bffe70456e8179a4 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 16:50:33 +0530 Subject: [PATCH 03/11] feat: add benchmark --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - 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 --- --- .../incr/nanmprod/benchmark/benchmark.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js new file mode 100644 index 000000000000..9a10064b6807 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var incrnanmprod = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmprod( (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( format( '%s::accumulator', pkg ), function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmprod( 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(); +}); From 5b9af207c4fd8263c8d4dcd64af530df159ae9ab Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 16:57:14 +0530 Subject: [PATCH 04/11] docs: add ts declarations --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: passed - task: lint_license_headers status: passed --- --- .../stats/incr/nanmprod/docs/types/index.d.ts | 77 +++++++++++++++++++ .../stats/incr/nanmprod/docs/types/test.ts | 66 ++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts new file mode 100644 index 000000000000..51c568b02914 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 product; otherwise, returns the current product. +* +* ## Notes +* +* - If provided `NaN`, returns the current product; other values which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* - For long running accumulations or accumulations of large numbers, care should be taken to prevent overflow. Note, however, that overflow/underflow may be transient, as the accumulator does not use a double-precision floating-point number to store an accumulated product. Instead, the accumulator splits an accumulated product into a normalized fraction and exponent and updates each component separately. Doing so guards against a loss in precision. +* +* @param x - value +* @returns product +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving product. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving product. +* - 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 = incrnanmprod( 3 ); +* +* var p = accumulator(); +* // returns null +* +* p = accumulator( 2.0 ); +* // returns 2.0 +* +* p = accumulator( -5.0 ); +* // returns -10.0 +* +* p = accumulator( NaN ); +* // returns -10.0 +* +* p = accumulator( 3.0 ); +* // returns -30.0 +* +* p = accumulator( 5.0 ); +* // returns -75.0 +* +* p = accumulator(); +* // returns -75.0 +*/ +declare function incrnanmprod( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmprod; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts new file mode 100644 index 000000000000..4c1eb1c13e78 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 incrnanmprod = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmprod( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + incrnanmprod( '5' ); // $ExpectError + incrnanmprod( true ); // $ExpectError + incrnanmprod( false ); // $ExpectError + incrnanmprod( null ); // $ExpectError + incrnanmprod( undefined ); // $ExpectError + incrnanmprod( [] ); // $ExpectError + incrnanmprod( {} ); // $ExpectError + incrnanmprod( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmprod(); // $ExpectError + incrnanmprod( 2, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmprod( 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 = incrnanmprod( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} From 5c3331d430414b2ff0f21ac225ecca1083f9420c Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 17:01:07 +0530 Subject: [PATCH 05/11] docs: add examples --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - 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 --- --- .../stats/incr/nanmprod/examples/index.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js new file mode 100644 index 000000000000..7a8cf5d4cccb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanmprod = require( './../lib' ); + +var accumulator; +var p; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmprod( 5 ); + +// For each simulated datum, update the moving product... +console.log( '\nValue\tProduct\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( randu()*10.0 ) - 5.0; + p = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 3 ), p.toFixed( 3 ) ); +} From 7641a7e4ca77cbbaa7d58c8df95c7832c8e0835c Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 17:14:57 +0530 Subject: [PATCH 06/11] test: add tests --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - 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 --- --- .../@stdlib/stats/incr/nanmprod/test/test.js | 437 ++++++++++++++++++ 1 file changed, 437 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js new file mode 100644 index 000000000000..36b689b2c20d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js @@ -0,0 +1,437 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPSILON = require( '@stdlib/constants/float64/eps' ); +var isEven = require( '@stdlib/math/base/assert/is-even' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var normal = require( '@stdlib/random/base/normal' ); +var randu = require( '@stdlib/random/base/randu' ); +var ldexp = require( '@stdlib/math/base/special/ldexp' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var incrnanmprod = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmprod, '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; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + 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() { + incrnanmprod( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanmprod( 3 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving product 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, 3.0, 4.0 ]; + N = data.length; + + acc = incrnanmprod( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 2.0, 6.0, 12.0, 24.0, 24.0, 48.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current product', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 5.0 ]; + acc = incrnanmprod( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc(), 15.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmprod( 3 ); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` the accumulator function returns the current product', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, 3.0, 5.0 ]; + acc = incrnanmprod( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc( NaN ), 15.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a moving product (special series)', function test( t ) { + var acc; + var x; + var i; + + acc = incrnanmprod( 150 ); + x = 2; + + // A series of reciprocals having an even number of terms is equal to unity... + for ( i = 0; i < 150; i++ ) { + if ( isEven( i ) ) { + acc( x ); + } else { + acc( 1.0/x ); + } + } + t.strictEqual( acc(), 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function can return a result which overflows', function test( t ) { + var acc = incrnanmprod( 2 ); + + acc( 5.0e300 ); + acc( 1.0e300 ); + + t.strictEqual( acc(), PINF, 'returns expected value' ); + t.end(); +}); + +tape( 'overflow may be transient', function test( t ) { + var expected; + var delta; + var tol; + var acc; + var x; + var y; + var z; + + expected = ldexp( 0.01, 1000 ); + + acc = incrnanmprod( 3 ); + + x = ldexp( 0.5, 1000 ); // ~5.4e300 + y = ldexp( 0.1, 1000 ); // ~1.1e300 + z = ldexp( 0.2, -1000 ); // ~1.87e-302 + + acc( x ); + acc( y ); + acc( z ); + + delta = abs( expected - acc() ); + tol = EPSILON * abs( expected ); + + t.strictEqual( delta <= tol, true, 'within tolerance. Expected: '+expected+'. Actual: '+acc()+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); + +tape( 'the accumulator function can return a result which underflows', function test( t ) { + var acc = incrnanmprod( 2 ); + + acc( 4.0e-302 ); + acc( 9.0e-303 ); + + t.strictEqual( acc(), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'underflow may be transient', function test( t ) { + var expected; + var delta; + var tol; + var acc; + var x; + var y; + var z; + + expected = ldexp( 0.01, -1000 ); + + acc = incrnanmprod( 3 ); + + x = ldexp( 0.5, -1000 ); // ~4.67e-302 + y = ldexp( 0.1, -1000 ); // ~9.33e-303 + z = ldexp( 0.2, 1000 ); // ~2.14e300 + + acc( x ); + acc( y ); + + t.strictEqual( acc(), 0.0, 'returns 0 due to underflow' ); + + acc( z ); + + delta = abs( acc() - expected ); + tol = EPSILON * abs( expected ); + + t.strictEqual( delta <= tol, true, 'within tolerance. Expected: '+expected+'. Actual: '+acc()+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); + +tape( 'if provided values of normal magnitude (i.e., far away from the extremes), the accumulator function returns results matching naive multiplication', function test( t ) { + var randn; + var prod; + var acc; + var r; + var i; + + acc = incrnanmprod( 1000 ); + + randn = normal.factory( 50.0, 10.0, { + 'seed': 1234 + }); + + prod = 1.0; + for ( i = 0; i < 1000; i++ ) { + r = randn(); + acc( r ); + prod *= r; + } + t.strictEqual( acc(), prod, 'equals native multiplication' ); + t.end(); +}); + +tape( 'if provided `+infinity`, the accumulator function returns `+-infinity` (unless provided zero)', function test( t ) { + var acc; + var x; + var i; + + acc = incrnanmprod( 3 ); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( PINF ); + t.strictEqual( acc(), PINF, 'returns expected value' ); + + acc( 3.0 ); + t.strictEqual( acc(), PINF, 'returns expected value' ); + + acc( -4.0 ); + t.strictEqual( acc(), NINF, 'returns expected value' ); + + for ( i = 0; i < 100; i++ ) { + x = ( randu()*100.0 ) - 50.0; + if ( x === 0.0 ) { + continue; + } + x = acc( x ); + t.notEqual( x === PINF || x === NINF, true, 'does not return +-infinity' ); + } + t.end(); +}); + +tape( 'if provided `-infinity`, the accumulator function returns `+-infinity` (unless provided zero)', function test( t ) { + var acc; + var x; + var i; + + acc = incrnanmprod( 3 ); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( NINF ); + t.strictEqual( acc(), NINF, 'returns expected value' ); + + acc( 3.0 ); + t.strictEqual( acc(), NINF, 'returns expected value' ); + + acc( -4.0 ); + t.strictEqual( acc(), PINF, 'returns expected value' ); + + for ( i = 0; i < 100; i++ ) { + x = ( randu()*100.0 ) - 50.0; + if ( x === 0.0 ) { + continue; + } + x = acc( x ); + t.notEqual( x === PINF || x === NINF, true, 'does not return +-infinity' ); + } + t.end(); +}); + +tape( 'if provided `+infinity`, the accumulator function returns `NaN` if also provided a `0`', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanmprod( 3 ); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( PINF ); + t.strictEqual( acc(), PINF, 'returns expected value' ); + + acc( 0.0 ); + t.strictEqual( isnan( acc() ), true, 'returns expected value' ); + + acc( 3.0 ); + t.strictEqual( isnan( acc() ), true, 'returns expected value' ); + + acc( 4.0 ); + t.strictEqual( isnan( acc() ), false, 'does not return NaN' ); + + for ( i = 0; i < 10; i++ ) { + p = acc( i+1 ); + t.strictEqual( isnan( p ), false, 'does not return NaN' ); + } + t.end(); +}); + +tape( 'if provided `-infinity`, the accumulator function returns `NaN` if also provided a `0`', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanmprod( 3 ); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( NINF ); + t.strictEqual( acc(), NINF, 'returns expected value' ); + + acc( 0.0 ); + t.strictEqual( isnan( acc() ), true, 'returns expected value' ); + + acc( 3.0 ); + t.strictEqual( isnan( acc() ), true, 'returns expected value' ); + + acc( 4.0 ); + t.strictEqual( isnan( acc() ), false, 'does not return NaN' ); + + for ( i = 0; i < 10; i++ ) { + p = acc( i+1 ); + t.strictEqual( isnan( p ), false, 'does not return NaN' ); + } + t.end(); +}); + +tape( 'if provided `0`, the accumulator function returns `0` (no +-infinity)', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanmprod( 3 ); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( 0.0 ); + t.strictEqual( acc(), 0.0, 'returns expected value' ); + + acc( 3.0 ); + t.strictEqual( acc(), 0.0, 'returns expected value' ); + + acc( 4.0 ); + t.strictEqual( acc(), 0.0, 'returns expected value' ); + + for ( i = 0; i < 10; i++ ) { + p = acc( i+1 ); + t.strictEqual( p > 0.0, true, 'does not return 0.0' ); + } + t.end(); +}); + +tape( 'the accumulator function returns a signed zero', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanmprod( 3 ); + p = acc( -0.0 ); + t.strictEqual( isNegativeZero( p ), true, 'returns expected value' ); + + p = acc( -0.0 ); + t.strictEqual( isPositiveZero( p ), true, 'returns expected value' ); + + for ( i = 0; i < 100; i++ ) { + p = acc( -0.0 ); + t.strictEqual( isNegativeZero( p ), true, 'returns expected value' ); + } + + acc = incrnanmprod( 4 ); + p = acc( -0.0 ); + t.strictEqual( isNegativeZero( p ), true, 'returns expected value' ); + + p = acc( -0.0 ); + t.strictEqual( isPositiveZero( p ), true, 'returns expected value' ); + + p = acc( -0.0 ); + t.strictEqual( isNegativeZero( p ), true, 'returns expected value' ); + + for ( i = 0; i < 100; i++ ) { + p = acc( -0.0 ); + t.strictEqual( isPositiveZero( p ), true, 'returns expected value' ); + } + + t.end(); +}); From 35c6abc5af4483fa885ccd9b0be65494d5970fc0 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 17:18:34 +0530 Subject: [PATCH 07/11] docs: add repl.txt --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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 --- --- .../@stdlib/stats/incr/nanmprod/docs/repl.txt | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt new file mode 100644 index 000000000000..f3bca586371f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt @@ -0,0 +1,55 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + product, ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving product. + + If provided a value or provided a `NaN` value, the accumulator function + returns an updated moving product. If not provided a value, the accumulator + function returns the current moving product. + + 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. + + For accumulations over large windows or accumulations of large numbers, care + should be taken to prevent overflow. Note, however, that overflow/underflow + may be transient, as the accumulator does not use a double-precision + floating-point number to store an accumulated product. Instead, the + accumulator splits an accumulated product into a normalized fraction and + exponent and updates each component separately. Doing so guards against a + loss in precision. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var p = accumulator() + null + > p = accumulator( 2.0 ) + 2.0 + > p = accumulator( -5.0 ) + -10.0 + > p = accumulator( NaN ) + -10.0 + > p = accumulator( 3.0 ) + -30.0 + > p = accumulator( 5.0 ) + -75.0 + > p = accumulator() + -75.0 + + See Also + -------- + From 109d6f9fdac2b62fcc7dfab752c59fd6bae41009 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 17:21:11 +0530 Subject: [PATCH 08/11] fix: update copyright years --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmprod/README.md | 2 +- .../@stdlib/stats/incr/nanmprod/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanmprod/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md index a53917ad9580..8af87cf9bd8e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js index 9a10064b6807..b1554f4c6425 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts index 51c568b02914..2fb0a572772c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts index 4c1eb1c13e78..f572fb82307b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js index 7a8cf5d4cccb..7a8f99414237 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js index c566bb518f7d..14fa59d5dfa3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js index 36b689b2c20d..32b7a2e8045b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2026 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. From a94855d480ee7ba937417258dcd3d0ed47d4ee13 Mon Sep 17 00:00:00 2001 From: Arjan Date: Tue, 28 Jul 2026 17:31:58 +0530 Subject: [PATCH 09/11] fix: update package.json to use correct name --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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/nanmprod/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json b/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json index 748cdc058df8..cc848284aaa0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/stats/incr/mprod", + "name": "@stdlib/stats/incr/nanmprod", "version": "0.0.0", "description": "Compute a moving product incrementally, ignoring NaN values.", "license": "Apache-2.0", From f4634372412ea79b03c5f16b7478e7bc384920bd Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 00:48:37 -0500 Subject: [PATCH 10/11] chore: remove section contents Co-authored-by: Philipp Burckhardt Signed-off-by: Philipp Burckhardt --- .../@stdlib/stats/incr/nanmprod/README.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md index 8af87cf9bd8e..0b5745c6b5e2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md @@ -189,13 +189,6 @@ console.log( accumulator() ); @@ -206,10 +199,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/msum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/msum - -[@stdlib/stats/incr/prod]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/prod - From 94ad0083731bf3c54e2b6dfe4f3ceb780c92ffc3 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 01:35:34 -0500 Subject: [PATCH 11/11] fix: correct NaN docs and align with sibling nan* package conventions - Fix require order and paren spacing in main.js; add NaN step to JSDoc example - Correct wrong NaN behavior descriptions in repl.txt and index.d.ts (NaN returns the current product, not an updated one; no poisoning) - Remove stale mprod NaN-poisoning note from README; point equation URL at this package and add docs/img equation SVG - Inject NaN values in examples and README examples with guarded printing - Add moving-window NaN semantics test and NaN $ExpectType check --- .../@stdlib/stats/incr/nanmprod/README.md | 13 ++++---- .../docs/img/equation_moving_product.svg | 30 +++++++++++++++++++ .../@stdlib/stats/incr/nanmprod/docs/repl.txt | 6 ++-- .../stats/incr/nanmprod/docs/types/index.d.ts | 4 +-- .../stats/incr/nanmprod/docs/types/test.ts | 1 + .../stats/incr/nanmprod/examples/index.js | 5 ++-- .../@stdlib/stats/incr/nanmprod/lib/main.js | 9 ++++-- .../@stdlib/stats/incr/nanmprod/test/test.js | 25 +++++++++++++++- 8 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmprod/docs/img/equation_moving_product.svg diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md index 0b5745c6b5e2..f016a2fcd472 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/README.md @@ -33,7 +33,7 @@ For a window of size `W`, the moving product is defined as ``` @@ -53,7 +53,7 @@ var incrnanmprod = require( '@stdlib/stats/incr/nanmprod' ); #### incrnanmprod( window ) -Returns an accumulator `function` which incrementally computes a moving product. The `window` parameter defines the number of values over which to compute the moving product. +Returns an accumulator `function` which incrementally computes a moving product. The `window` parameter defines the number of values over which to compute the moving product, ignoring `NaN` values. ```javascript var accumulator = incrnanmprod( 3 ); @@ -61,7 +61,7 @@ var accumulator = incrnanmprod( 3 ); #### accumulator( \[x] ) -If provided an input value `x`, the accumulator function returns an updated product. If not provided an input value `x` or provided a `NaN` value, the accumulator function returns the current product. +If provided an input value `x`, the accumulator function returns an updated product. If not provided an input value `x`, the accumulator function returns the current product. ```javascript var accumulator = incrnanmprod( 3 ); @@ -76,6 +76,9 @@ p = accumulator( 2.0 ); // [2.0] p = accumulator( 1.0 ); // [2.0, 1.0] // returns 2.0 +p = accumulator( NaN ); // [2.0, 1.0] +// returns 2.0 + p = accumulator( 3.0 ); // [2.0, 1.0, 3.0] // returns 6.0 @@ -148,7 +151,7 @@ p = accumulator( z ); ## Notes -- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **at least** `W-1` future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- 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. - For large accumulation windows or accumulations of either large or small numbers, care should be taken to prevent overflow and underflow. Note, however, that overflow/underflow may be transient, as the accumulator does not use a double-precision floating-point number to store an accumulated product. Instead, the accumulator splits an accumulated product into a normalized **fraction** and **exponent** and updates each component separately. Doing so guards against a loss in precision. @@ -175,7 +178,7 @@ accumulator = incrnanmprod( 5 ); // For each simulated datum, update the moving product... for ( i = 0; i < 100; i++ ) { - v = ( randu()*10.0 ) - 5.0; + v = ( randu() < 0.1 ) ? NaN : ( randu()*10.0 ) - 5.0; accumulator( v ); } console.log( accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/img/equation_moving_product.svg b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/img/equation_moving_product.svg new file mode 100644 index 000000000000..6805f02488ba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/img/equation_moving_product.svg @@ -0,0 +1,30 @@ + +product Underscript i equals 0 Overscript upper W minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt index f3bca586371f..259cea9162df 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/repl.txt @@ -6,9 +6,9 @@ The `W` parameter defines the number of values over which to compute the moving product. - If provided a value or provided a `NaN` value, the accumulator function - returns an updated moving product. If not provided a value, the accumulator - function returns the current moving product. + If provided a value, the accumulator function returns an updated moving + product. If not provided a value, the accumulator function returns the + current moving product. 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, diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts index 2fb0a572772c..6f15369120eb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/index.d.ts @@ -25,7 +25,7 @@ * * ## Notes * -* - If provided `NaN`, returns the current product; other values which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* - If provided `NaN`, returns the current product. * - For long running accumulations or accumulations of large numbers, care should be taken to prevent overflow. Note, however, that overflow/underflow may be transient, as the accumulator does not use a double-precision floating-point number to store an accumulated product. Instead, the accumulator splits an accumulated product into a normalized fraction and exponent and updates each component separately. Doing so guards against a loss in precision. * * @param x - value @@ -34,7 +34,7 @@ type accumulator = ( x?: number ) => number | null; /** -* Returns an accumulator function which incrementally computes a moving product. +* Returns an accumulator function which incrementally computes a moving product, ignoring `NaN` values. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts index f572fb82307b..fd594b8b4b1c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts @@ -50,6 +50,7 @@ import incrnanmprod = require( './index' ); acc(); // $ExpectType number | null acc( 3.14 ); // $ExpectType number | null + acc( NaN ); // $ExpectType number | null } // The compiler throws an error if the returned accumulator function is provided invalid arguments... diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js index 7a8f99414237..f2aeeaa22b5a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js @@ -19,6 +19,7 @@ 'use strict'; var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanmprod = require( './../lib' ); var accumulator; @@ -32,7 +33,7 @@ accumulator = incrnanmprod( 5 ); // For each simulated datum, update the moving product... console.log( '\nValue\tProduct\n' ); for ( i = 0; i < 100; i++ ) { - v = ( randu()*10.0 ) - 5.0; + v = ( randu() < 0.1 ) ? NaN : ( randu()*10.0 ) - 5.0; p = accumulator( v ); - console.log( '%d\t%d', v.toFixed( 3 ), p.toFixed( 3 ) ); + console.log( '%s\t%s', ( isnan( v ) ) ? 'NaN' : v.toFixed( 3 ), ( p === null ) ? 'null' : p.toFixed( 3 ) ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js index 83d79ddc3d60..9a004d81c3be 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js @@ -20,8 +20,8 @@ // MODULES // -var incrmprod = require( '@stdlib/stats/incr/mprod' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmprod = require( '@stdlib/stats/incr/mprod' ); // MAIN // @@ -45,6 +45,9 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * p = accumulator( -5.0 ); * // returns -10.0 * +* p = accumulator( NaN ); +* // returns -10.0 +* * p = accumulator( 3.0 ); * // returns -30.0 * @@ -59,7 +62,7 @@ function incrnanmprod( W ) { return accumulator; /** - * If provided a value, the accumulator function returns an updated product. If not provided a value or provided `NaN` values, the accumulator function returns the current product. + * If provided a value, the accumulator function returns an updated product. If not provided a value, the accumulator function returns the current product. * * @private * @param {number} [x] - input value @@ -69,7 +72,7 @@ function incrnanmprod( W ) { if ( arguments.length === 0 ) { return acc(); } - if ( isnan(x) ) { + if ( isnan( x ) ) { return acc(); } return acc( x ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js index 32b7a2e8045b..3514a045af7d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmprod/test/test.js @@ -101,6 +101,29 @@ tape( 'the accumulator function computes a moving product incrementally', functi t.end(); }); +tape( 'the accumulator function computes a moving product incrementally, ignoring `NaN` values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, NaN, 4.0, NaN, 5.0 ]; + N = data.length; + + acc = incrnanmprod( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 2.0, 6.0, 6.0, 24.0, 24.0, 60.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + tape( 'if not provided an input value, the accumulator function returns the current product', function test( t ) { var data; var acc; @@ -121,7 +144,7 @@ tape( 'if data has yet to be provided, the accumulator function returns `null`', t.end(); }); -tape( 'if provided `NaN` the accumulator function returns the current product', function test( t ) { +tape( 'if provided `NaN`, the accumulator function returns the current product', function test( t ) { var data; var acc; var i;