From f3d4e018cf051f04eae9758b3fd7d617acf35ee9 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Sat, 8 Mar 2025 15:02:41 +0530 Subject: [PATCH 01/13] edit --- .../@stdlib/stats/base/dists/uniform/mgf/src/main.c | 2 +- .../@stdlib/stats/base/dists/uniform/mgf/test/test.native.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c index 49105477756c..4feab3bb73be 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c @@ -46,5 +46,5 @@ double stdlib_base_dists_uniform_mgf( const double t, const double a, const doub return 1.0; } // Case: t not equal to zero - return ( stdlib_base_exp( t * b ) - stdlib_base_exp( t * a ) ) / ( t * ( b - a ) ); + return stdlib_base_exp( v ) * ( stdlib_base_sinh ( u ) / u ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js index bc312890bdf3..868d3aae948d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js @@ -81,7 +81,7 @@ tape( 'if provided `a >= b`, the function returns `NaN`', opts, function test( t t.end(); }); -tape( 'if provided valid parameters, the function returns `1` for `t = 0`', function test( t ) { +tape( 'if provided valid parameters, the function returns `1` for `t = 0`', opts, function test( t ) { var y; y = mgf( 0.0, 2.0, 4.0 ); From ddced1cd3eb3a9a64ec05119e719344ecff0bbaf Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Sat, 8 Mar 2025 15:10:15 +0530 Subject: [PATCH 02/13] edit --- .../@stdlib/stats/base/dists/uniform/mgf/src/main.c | 2 +- .../@stdlib/stats/base/dists/uniform/mgf/test/test.native.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c index 4feab3bb73be..49105477756c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c @@ -46,5 +46,5 @@ double stdlib_base_dists_uniform_mgf( const double t, const double a, const doub return 1.0; } // Case: t not equal to zero - return stdlib_base_exp( v ) * ( stdlib_base_sinh ( u ) / u ); + return ( stdlib_base_exp( t * b ) - stdlib_base_exp( t * a ) ) / ( t * ( b - a ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js index 868d3aae948d..bc312890bdf3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js @@ -81,7 +81,7 @@ tape( 'if provided `a >= b`, the function returns `NaN`', opts, function test( t t.end(); }); -tape( 'if provided valid parameters, the function returns `1` for `t = 0`', opts, function test( t ) { +tape( 'if provided valid parameters, the function returns `1` for `t = 0`', function test( t ) { var y; y = mgf( 0.0, 2.0, 4.0 ); From 006aa0e2dd99107eb44655a0306e2aa76faec41f Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 18:38:13 +0530 Subject: [PATCH 03/13] added nanprod --- .../@stdlib/stats/incr/nanprod/README.md | 212 ++++++++++++ .../stats/incr/nanprod/benchmark/benchmark.js | 69 ++++ .../@stdlib/stats/incr/nanprod/docs/repl.txt | 38 ++ .../stats/incr/nanprod/docs/types/index.d.ts | 67 ++++ .../stats/incr/nanprod/docs/types/test.ts | 61 ++++ .../stats/incr/nanprod/examples/index.js | 40 +++ .../@stdlib/stats/incr/nanprod/lib/index.js | 54 +++ .../@stdlib/stats/incr/nanprod/lib/main.js | 81 +++++ .../@stdlib/stats/incr/nanprod/package.json | 65 ++++ .../@stdlib/stats/incr/nanprod/test/test.js | 327 ++++++++++++++++++ 10 files changed, 1014 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/README.md b/lib/node_modules/@stdlib/stats/incr/nanprod/README.md new file mode 100644 index 000000000000..4c36094fdc6c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/README.md @@ -0,0 +1,212 @@ + + +# incrnanprod + +> Compute a product incrementally, ignoring the `NaN` values. + +
+ +The product is defined as + + + +```math +p = \prod_{i=0}^{n-1} x_i +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanprod = require( '@stdlib/stats/incr/nanprod' ); +``` + +#### incrnanprod() + +Returns an accumulator `function` which incrementally computes a product, ignoring `NaN` values. + +```javascript +var accumulator = incrnanprod(); +``` + +#### accumulator( \[x] ) + +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 = incrnanprod(); + +var prod = accumulator( 2.0 ); +// returns 2.0 + +prod = accumulator( NaN ); +// returns 2.0 + +prod = accumulator( 1.0 ); +// returns 2.0 + +prod = accumulator( 3.0 ); +// returns 6.0 + +prod = accumulator(); +// returns 6.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 = incrnanprod(); + +var prod = accumulator( x ); +// returns 5.0e+300 + +// Transient overflow: +prod = accumulator( y ); +// returns Infinity + +// Recover a finite result: +prod = 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 = incrnanprod(); + +var prod = accumulator( x ); +// returns 4.0e-302 + +// Transient underflow: +prod = accumulator( y ); +// returns 0.0 + +// Recover a non-zero result: +prod = accumulator( z ); +// returns 7.2e-304 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- For long running accumulations or accumulations of 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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanprod = require( '@stdlib/stats/incr/nanprod' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanprod(); + +// For each simulated value, update the product... +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanprod/benchmark/benchmark.js new file mode 100644 index 000000000000..df59160b6d53 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanprod = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanprod(); + 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 = incrnanprod(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()*10.0 ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/repl.txt new file mode 100644 index 000000000000..4094ae4e0b7b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a + product, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated product. If + not provided a value, the accumulator function 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. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var v = accumulator() + null + > v = accumulator( 2.0 ) + 2.0 + > v = accumulator( NaN ) + 2.0 + > v = accumulator( -5.0 ) + -10.0 + > v = accumulator() + -10.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts new file mode 100644 index 000000000000..521858b79077 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts @@ -0,0 +1,67 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, returns an updated product; otherwise, returns the current product. +* +* ## Notes +* +* - If provided `NaN` or a value 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 product, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrprod(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( 3.0 ); +* // returns 6.0 +* +* v = accumulator( 4.0 ); +* // returns 24.0 +* +* v = accumulator(); +* // returns 24.0 +*/ +declare function incrnanprod(): accumulator; + + +// EXPORTS // + +export = incrnanprod; diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/test.ts new file mode 100644 index 000000000000..cdcf930f33f4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanprod = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanprod(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanprod( '5' ); // $ExpectError + incrnanprod( 5 ); // $ExpectError + incrnanprod( true ); // $ExpectError + incrnanprod( false ); // $ExpectError + incrnanprod( null ); // $ExpectError + incrnanprod( undefined ); // $ExpectError + incrnanprod( [] ); // $ExpectError + incrnanprod( {} ); // $ExpectError + incrnanprod( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanprod(); + + 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 = incrnanprod(); + + 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/nanprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js new file mode 100644 index 000000000000..de8bb216b1e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanprod = require( './../lib' ); + +var accumulator; +var prod; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanprod(); + +// For each simulated value, update the product... +console.log( '\nValue\tProduct\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + prod = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), ( prod === null ) ? NaN : prod.toFixed( 4 ) ); +} +console.log( '\nFinal product: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/index.js new file mode 100644 index 000000000000..b4f77629b6b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a product incrementally, while ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanprod +* +* @example +* var incrnanprod = require( '@stdlib/stats/incr/nanprod' ); +* +* var accumulator = incrnanprod(); +* +* var prod = accumulator(); +* // returns null +* +* prod = accumulator( 2.0 ); +* // returns 2.0 +* +* prod = accumulator( NaN ); +* // returns 2.0 +* +* prod = accumulator( -5.0 ); +* // returns -10.0 +* +* prod = accumulator(); +* // returns -10.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js new file mode 100644 index 000000000000..260df3f9056e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -0,0 +1,81 @@ +/** +* @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 incrprod = require( '@stdlib/stats/incr/prod' ); + +/** +* Returns an accumulator function which incrementally computes a product, while ignoring `NaN` values. +* +* ## Method +* +* To avoid overflow/underflow, we store the fractional and exponent parts of intermediate results separately. By keeping a normalized fraction, we prevent underflow/overflow of the fraction. Underflow of the exponent is impossible, as IEEE 754 floating-point exponents are integer values. Overflow of the exponent is possible, but highly unlikely. In the worst case, an intermediate exponent is greater than the minimum safe integer, and adding the exponent of an incoming value does not change the intermediate result. While incorrect, such behavior does not lead to exponent overflow. +* +* While intermediate results are largely immune to overflow and not subject to underflow, this does not mean that returned results will never be zero or infinite. In fact, zero (underflow) and infinite (overflow) results may be transient (i.e., infinity followed by a finite number). +* +* ## References +* +* - Ueberhuber, Christoph W. 1997. _Numerical Computation 1: Methods, Software, and Analysis_. Springer-Verlag Berlin Heidelberg. doi:[10.1007/978-3-642-59118-1](https://doi.org/10.1007/978-3-642-59118-1). +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrprod(); +* +* var prod = accumulator(); +* // returns null +* +* prod = accumulator( 2.0 ); +* // returns 2.0 +* +* prod = accumulator( NaN ); +* // returns 2.0 +* +* prod = accumulator( -5.0 ); +* // returns -10.0 +* +* prod = accumulator(); +* // returns -10.0 +*/ +function incrnanprod() { + var prod = incrprod(); + return accumulator; + + /** + * 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] - new value + * @returns {(number|null)} product or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return prod(); + } + return prod( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanprod; diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/package.json b/lib/node_modules/@stdlib/stats/incr/nanprod/package.json new file mode 100644 index 000000000000..cf24d996a5e0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/incr/nanprod", + "version": "0.0.0", + "description": "Compute a 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.git", + "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", + "multiplication", + "mult", + "product", + "prod", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js new file mode 100644 index 000000000000..a508dbaa97df --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js @@ -0,0 +1,327 @@ +/** +* @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 PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPSILON = require( '@stdlib/constants/float64/eps' ); +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 isnan = require( '@stdlib/assert/is-nan' ); +var isEven = require( '@stdlib/math/base/assert/is-even' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var incrnanprod = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanprod, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanprod(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulator value is `null`', function test( t ) { + var acc = incrnanprod(); + t.strictEqual( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a product', function test( t ) { + var expected; + var actual; + var data; + var prod; + var acc; + var N; + var d; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, 4.0 ]; + N = data.length; + + expected = []; + actual = []; + + acc = incrnanprod(); + + prod = 1.0; + for ( i = 0; i < N; i++ ) { + d = data[ i ]; + if( !isnan( d ) ){ + prod *= d; + } + expected[ i ] = prod; + actual[ i ] = acc( d ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + 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, NaN, 3.0, 1.0 ]; + + acc = incrnanprod(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc(), 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a product (special series)', function test( t ) { + var acc; + var x; + var i; + + acc = incrnanprod(); + 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 ); + } + if( i % 10 == 0 ){ + acc( NaN ); + } + } + 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 = incrnanprod(); + + acc( 5.0e300 ); + acc( NaN ); + acc( 1.0e300 ); + + t.strictEqual( acc(), PINF, 'returns infinity' ); + 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 = incrnanprod(); + + 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( NaN ); + 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 = incrnanprod(); + + acc( 4.0e-302 ); + acc( NaN ); + acc( 9.0e-303 ); + + t.strictEqual( acc(), 0.0, 'returns 0' ); + 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 = incrnanprod(); + + 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( NaN ); + 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 `+infinity`, the accumulator function always returns `NaN` if also provided a `0`', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanprod(); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( PINF ); + t.strictEqual( acc(), PINF, 'returns +infinity' ); + + acc( NaN ); + t.strictEqual( acc(), PINF, 'ignores NaN and retains +infinity' ); + + acc( 0.0 ); + t.strictEqual( isnan( acc() ), true, 'returns NaN' ); + + for ( i = 0; i < 1000; i++ ) { + p = acc( i + 1 ); + t.strictEqual( isnan( p ), true, 'returns NaN' ); + } + t.end(); +}); + +tape( 'if provided `-infinity`, the accumulator function always returns `NaN` if also provided a `0`', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanprod(); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( NINF ); + t.strictEqual( acc(), NINF, 'returns -infinity' ); + + acc( NaN ); + t.strictEqual( acc(), NINF, 'ignores NaN and retains -infinity' ); + + acc( 0.0 ); + t.strictEqual( isnan( acc() ), true, 'returns NaN' ); + + for ( i = 0; i < 1000; i++ ) { + p = acc( i+1 ); + t.strictEqual( isnan( p ), true, 'returns NaN' ); + } + t.end(); +}); + +tape( 'if provided `0`, the accumulator function always returns `0` (no +-infinity)', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanprod(); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( NaN ); + t.strictEqual( acc(), 5.0, 'ignores NaN and retains product' ); + + acc( 0.0 ); + t.strictEqual( acc(), 0.0, 'returns 0.0' ); + + for ( i = 0; i < 1000; i++ ) { + p = acc( i+1 ); + t.strictEqual( p, 0.0, 'returns 0.0' ); + } + t.end(); +}); + +tape( 'the accumulator function returns a signed zero', function test( t ) { + var acc; + var p; + var i; + + acc = incrnanprod(); + acc( -0.0 ); + for ( i = 0; i < 100; i++ ) { + acc( NaN ); + p = acc( -0.0 ); + if ( isEven( i ) ) { + t.strictEqual( isPositiveZero( p ), true, 'returns +0' ); + } else { + t.strictEqual( isNegativeZero( p ), true, 'returns -0' ); + } + } + 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 = incrnanprod(); + + randn = normal.factory( 50.0, 10.0, { + 'seed': 1234 + }); + + prod = 1.0; + for ( i = 0; i < 1000; i++ ) { + r = randn(); + if( isnan( r ) ){ + continue; + } + acc( r ); + prod *= r; + } + t.strictEqual( acc(), prod, 'equals native multiplication' ); + t.end(); +}); From 8e21970df3e1d3b46c4df18fa79e9a332156015e Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 18:59:44 +0530 Subject: [PATCH 04/13] lint --- .../@stdlib/stats/incr/nanprod/test/test.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js index a508dbaa97df..e183d1a4af8e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js @@ -75,12 +75,12 @@ tape( 'the accumulator function incrementally computes a product', function test prod = 1.0; for ( i = 0; i < N; i++ ) { d = data[ i ]; - if( !isnan( d ) ){ - prod *= d; - } + if( !isnan( d ) ){ + prod *= d; + } expected[ i ] = prod; actual[ i ] = acc( d ); - } + } t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); @@ -115,9 +115,9 @@ tape( 'the accumulator function incrementally computes a product (special series } else { acc( 1.0/x ); } - if( i % 10 == 0 ){ - acc( NaN ); - } + if( i % 10 == 0 ){ + acc( NaN ); + } } t.strictEqual( acc(), 1.0, 'returns expected value' ); t.end(); @@ -152,7 +152,7 @@ tape( 'overflow may be transient', function test( t ) { z = ldexp( 0.2, -1000 ); // ~1.87e-302 acc( x ); - acc( NaN ); + acc( NaN ); acc( y ); acc( z ); @@ -167,7 +167,7 @@ tape( 'the accumulator function can return a result which underflows', function var acc = incrnanprod(); acc( 4.0e-302 ); - acc( NaN ); + acc( NaN ); acc( 9.0e-303 ); t.strictEqual( acc(), 0.0, 'returns 0' ); @@ -192,7 +192,7 @@ tape( 'underflow may be transient', function test( t ) { z = ldexp( 0.2, 1000 ); // ~2.14e300 acc( x ); - acc( NaN ); + acc( NaN ); acc( y ); t.strictEqual( acc(), 0.0, 'returns 0 due to underflow' ); @@ -219,8 +219,8 @@ tape( 'if provided `+infinity`, the accumulator function always returns `NaN` if acc( PINF ); t.strictEqual( acc(), PINF, 'returns +infinity' ); - acc( NaN ); - t.strictEqual( acc(), PINF, 'ignores NaN and retains +infinity' ); + acc( NaN ); + t.strictEqual( acc(), PINF, 'ignores NaN and retains +infinity' ); acc( 0.0 ); t.strictEqual( isnan( acc() ), true, 'returns NaN' ); @@ -245,8 +245,8 @@ tape( 'if provided `-infinity`, the accumulator function always returns `NaN` if acc( NINF ); t.strictEqual( acc(), NINF, 'returns -infinity' ); - acc( NaN ); - t.strictEqual( acc(), NINF, 'ignores NaN and retains -infinity' ); + acc( NaN ); + t.strictEqual( acc(), NINF, 'ignores NaN and retains -infinity' ); acc( 0.0 ); t.strictEqual( isnan( acc() ), true, 'returns NaN' ); @@ -268,8 +268,8 @@ tape( 'if provided `0`, the accumulator function always returns `0` (no +-infini t.strictEqual( acc(), 5.0, 'returns expected value' ); - acc( NaN ); - t.strictEqual( acc(), 5.0, 'ignores NaN and retains product' ); + acc( NaN ); + t.strictEqual( acc(), 5.0, 'ignores NaN and retains product' ); acc( 0.0 ); t.strictEqual( acc(), 0.0, 'returns 0.0' ); @@ -289,7 +289,7 @@ tape( 'the accumulator function returns a signed zero', function test( t ) { acc = incrnanprod(); acc( -0.0 ); for ( i = 0; i < 100; i++ ) { - acc( NaN ); + acc( NaN ); p = acc( -0.0 ); if ( isEven( i ) ) { t.strictEqual( isPositiveZero( p ), true, 'returns +0' ); @@ -316,9 +316,9 @@ tape( 'if provided values of normal magnitude (i.e., far away from the extremes) prod = 1.0; for ( i = 0; i < 1000; i++ ) { r = randn(); - if( isnan( r ) ){ - continue; - } + if( isnan( r ) ){ + continue; + } acc( r ); prod *= r; } From b760e76b15fe23e6977bd81e8824c6257a38dff2 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:07:21 +0530 Subject: [PATCH 05/13] check --- lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js | 6 +++--- lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js index 260df3f9056e..3d3ce7fce2fd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -48,13 +48,13 @@ var incrprod = require( '@stdlib/stats/incr/prod' ); * // returns 2.0 * * prod = accumulator( NaN ); -* // returns 2.0 +* // returns NaN * * prod = accumulator( -5.0 ); -* // returns -10.0 +* // returns NaN * * prod = accumulator(); -* // returns -10.0 +* // returns NaN */ function incrnanprod() { var prod = incrprod(); diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js index e183d1a4af8e..cacbb6e6773f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js @@ -79,7 +79,7 @@ tape( 'the accumulator function incrementally computes a product', function test prod *= d; } expected[ i ] = prod; - actual[ i ] = acc( d ); + actual[ i ] = acc( d ); } t.deepEqual( actual, expected, 'returns expected value' ); t.end(); @@ -127,7 +127,7 @@ tape( 'the accumulator function can return a result which overflows', function t var acc = incrnanprod(); acc( 5.0e300 ); - acc( NaN ); + acc( NaN ); acc( 1.0e300 ); t.strictEqual( acc(), PINF, 'returns infinity' ); From 36d8b5f8a61e6785abfe7446ba932380cf5521a9 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:13:22 +0530 Subject: [PATCH 06/13] lint --- .../@stdlib/stats/incr/nanprod/package.json | 126 +++++++++--------- .../@stdlib/stats/incr/nanprod/test/test.js | 7 +- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/package.json b/lib/node_modules/@stdlib/stats/incr/nanprod/package.json index cf24d996a5e0..11a9b71e8a52 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/package.json @@ -1,65 +1,65 @@ { - "name": "@stdlib/stats/incr/nanprod", - "version": "0.0.0", - "description": "Compute a 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.git", - "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", - "multiplication", - "mult", - "product", - "prod", - "incremental", - "accumulator" - ] + "name": "@stdlib/stats/incr/nanprod", + "version": "0.0.0", + "description": "Compute a product incrementally while ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib.git", + "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", + "multiplication", + "mult", + "product", + "prod", + "incremental", + "accumulator" + ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js index cacbb6e6773f..ebc11118ef91 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js @@ -25,7 +25,6 @@ var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var EPSILON = require( '@stdlib/constants/float64/eps' ); 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 isnan = require( '@stdlib/assert/is-nan' ); @@ -75,7 +74,7 @@ tape( 'the accumulator function incrementally computes a product', function test prod = 1.0; for ( i = 0; i < N; i++ ) { d = data[ i ]; - if( !isnan( d ) ){ + if ( !isnan( d ) ) { prod *= d; } expected[ i ] = prod; @@ -115,7 +114,7 @@ tape( 'the accumulator function incrementally computes a product (special series } else { acc( 1.0/x ); } - if( i % 10 == 0 ){ + if ( i % 10 === 0 ){ acc( NaN ); } } @@ -316,7 +315,7 @@ tape( 'if provided values of normal magnitude (i.e., far away from the extremes) prod = 1.0; for ( i = 0; i < 1000; i++ ) { r = randn(); - if( isnan( r ) ){ + if ( isnan( r ) ){ continue; } acc( r ); From e6c599358f1ca7d5951f34e7c1927dbaa8e4404d Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:18:30 +0530 Subject: [PATCH 07/13] spaces --- lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js index ebc11118ef91..4c463da6b145 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/test/test.js @@ -114,7 +114,7 @@ tape( 'the accumulator function incrementally computes a product (special series } else { acc( 1.0/x ); } - if ( i % 10 === 0 ){ + if ( i % 10 === 0 ) { acc( NaN ); } } @@ -315,7 +315,7 @@ tape( 'if provided values of normal magnitude (i.e., far away from the extremes) prod = 1.0; for ( i = 0; i < 1000; i++ ) { r = randn(); - if ( isnan( r ) ){ + if ( isnan( r ) ) { continue; } acc( r ); From d291cdee7350751a9b0ea0823490be8c908f3443 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:27:32 +0530 Subject: [PATCH 08/13] check --- .../@stdlib/stats/incr/nanprod/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js index de8bb216b1e4..1638c9760a20 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js @@ -33,7 +33,7 @@ accumulator = incrnanprod(); // For each simulated value, update the product... console.log( '\nValue\tProduct\n' ); for ( i = 0; i < 100; i++ ) { - v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + v = ( bernoulli( 0.2 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); prod = accumulator( v ); console.log( '%d\t%d', v.toFixed( 4 ), ( prod === null ) ? NaN : prod.toFixed( 4 ) ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js index 3d3ce7fce2fd..260df3f9056e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -48,13 +48,13 @@ var incrprod = require( '@stdlib/stats/incr/prod' ); * // returns 2.0 * * prod = accumulator( NaN ); -* // returns NaN +* // returns 2.0 * * prod = accumulator( -5.0 ); -* // returns NaN +* // returns -10.0 * * prod = accumulator(); -* // returns NaN +* // returns -10.0 */ function incrnanprod() { var prod = incrprod(); From 3f89e0236152fa34b10d39628f3382d6ef6a1115 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:35:11 +0530 Subject: [PATCH 09/13] exanmpe --- .../@stdlib/stats/incr/nanprod/examples/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js index 1638c9760a20..fca40ab4c781 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js @@ -18,8 +18,7 @@ 'use strict'; -var uniform = require( '@stdlib/random/base/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); var incrnanprod = require( './../lib' ); var accumulator; @@ -33,7 +32,11 @@ accumulator = incrnanprod(); // For each simulated value, update the product... console.log( '\nValue\tProduct\n' ); for ( i = 0; i < 100; i++ ) { - v = ( bernoulli( 0.2 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } prod = accumulator( v ); console.log( '%d\t%d', v.toFixed( 4 ), ( prod === null ) ? NaN : prod.toFixed( 4 ) ); } From f076764992be598b0efd41faec7b707fe461e2c0 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:40:25 +0530 Subject: [PATCH 10/13] exanmpe --- .../@stdlib/stats/incr/nanprod/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanprod/examples/index.js | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts index 521858b79077..485eb63497e8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/docs/types/index.d.ts @@ -39,7 +39,7 @@ type accumulator = ( x?: number ) => number | null; * @returns accumulator function * * @example -* var accumulator = incrprod(); +* var accumulator = incrnanprod(); * * var v = accumulator(); * // returns null diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js index fca40ab4c781..de8bb216b1e4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/examples/index.js @@ -18,7 +18,8 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var incrnanprod = require( './../lib' ); var accumulator; @@ -32,11 +33,7 @@ accumulator = incrnanprod(); // For each simulated value, update the product... console.log( '\nValue\tProduct\n' ); for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { - v = NaN; - } else { - v = randu() * 100.0; - } + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); prod = accumulator( v ); console.log( '%d\t%d', v.toFixed( 4 ), ( prod === null ) ? NaN : prod.toFixed( 4 ) ); } From a612a0c8229b1f9acdb65fc18a47812a0706a251 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:50:18 +0530 Subject: [PATCH 11/13] check --- .../@stdlib/stats/incr/nanprod/lib/main.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js index 260df3f9056e..e6abe939193c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -57,8 +57,7 @@ var incrprod = require( '@stdlib/stats/incr/prod' ); * // returns -10.0 */ function incrnanprod() { - var prod = incrprod(); - return accumulator; + var acc = incrprod(); /** * If provided a value, the accumulator function returns an updated product. If not provided a value, the accumulator function returns the current product. @@ -67,12 +66,15 @@ function incrnanprod() { * @param {number} [x] - new value * @returns {(number|null)} product or null */ - function accumulator( x ) { - if ( arguments.length === 0 || isnan( x ) ) { - return prod(); + return function accumulator( x ) { + if ( arguments.length === 0 ) { + return acc(); } - return prod( x ); - } + if ( !isnan( x ) ) { + return acc( x ); + } + return acc(); + }; } From 39ddc11e5cc43faace0e9616c5aefa644eb3178d Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 19:55:15 +0530 Subject: [PATCH 12/13] check --- .../@stdlib/stats/incr/nanprod/lib/main.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js index e6abe939193c..260df3f9056e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -57,7 +57,8 @@ var incrprod = require( '@stdlib/stats/incr/prod' ); * // returns -10.0 */ function incrnanprod() { - var acc = incrprod(); + var prod = incrprod(); + return accumulator; /** * If provided a value, the accumulator function returns an updated product. If not provided a value, the accumulator function returns the current product. @@ -66,15 +67,12 @@ function incrnanprod() { * @param {number} [x] - new value * @returns {(number|null)} product or null */ - return function accumulator( x ) { - if ( arguments.length === 0 ) { - return acc(); + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return prod(); } - if ( !isnan( x ) ) { - return acc( x ); - } - return acc(); - }; + return prod( x ); + } } From 179f318cf4461203ff8410774171c02a81de0ace Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 13 Mar 2025 20:11:08 +0530 Subject: [PATCH 13/13] done --- lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js index 260df3f9056e..2dadeb2d6e49 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanprod/lib/main.js @@ -39,7 +39,7 @@ var incrprod = require( '@stdlib/stats/incr/prod' ); * @returns {Function} accumulator function * * @example -* var accumulator = incrprod(); +* var accumulator = incrnanprod(); * * var prod = accumulator(); * // returns null