Skip to content

Commit fc5789b

Browse files
committed
fix: apply code suggestions
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: passed - task: lint_license_headers status: passed ---
1 parent 715168d commit fc5789b

5 files changed

Lines changed: 9 additions & 17 deletions

File tree

lib/node_modules/@stdlib/stats/incr/nanmprod/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ p = accumulator( NaN ); // [2.0] (NaN ignored)
7979
p = accumulator( 3.0 ); // [2.0, 3.0]
8080
// returns 6.0
8181

82-
// Window begins sliding...
8382
p = accumulator( 5.0 ); // [2.0, 3.0, 5.0]
8483
// returns 30.0
8584

8685
p = accumulator( NaN ); // [2.0, 3.0, 5.0] (NaN ignored)
8786
// returns 30.0
8887

88+
// Window begins sliding...
8989
p = accumulator( 7.0 ); // [3.0, 5.0, 7.0]
9090
// returns 105.0
9191

@@ -167,7 +167,8 @@ p = accumulator( z );
167167
<!-- eslint no-undef: "error" -->
168168

169169
```javascript
170-
var randu = require( '@stdlib/random/base/randu' );
170+
var uniform = require( '@stdlib/random/base/uniform' );
171+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
171172
var incrnanmprod = require( '@stdlib/stats/incr/nanmprod' );
172173

173174
// Initialize an accumulator:
@@ -176,7 +177,7 @@ var accumulator = incrnanmprod( 5 );
176177
// For each simulated datum, update the moving product...
177178
var i;
178179
for ( i = 0; i < 100; i++ ) {
179-
accumulator( ( randu()*10.0 ) - 5.0 );
180+
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -30.0, 30.0 ) );
180181
}
181182
console.log( accumulator() );
182183
```

lib/node_modules/@stdlib/stats/incr/nanmprod/benchmark/benchmark.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var format = require( '@stdlib/string/format' );
2625
var pkg = require( './../package.json' ).name;
2726
var incrnanmprod = require( './../lib' );
@@ -56,7 +55,7 @@ bench( format( '%s::accumulator', pkg ), function benchmark( b ) {
5655

5756
b.tic();
5857
for ( i = 0; i < b.iterations; i++ ) {
59-
v = acc( randu() );
58+
v = acc( (i%5) ? i : NaN );
6059
if ( v !== v ) {
6160
b.fail( 'should not return NaN' );
6261
}

lib/node_modules/@stdlib/stats/incr/nanmprod/docs/types/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import incrnanmprod = require( './index' );
5050

5151
acc(); // $ExpectType number | null
5252
acc( 3.14 ); // $ExpectType number | null
53+
acc( NaN ); // $ExpectType number | null
5354
}
5455

5556
// The compiler throws an error if the returned accumulator function is provided invalid arguments...

lib/node_modules/@stdlib/stats/incr/nanmprod/examples/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/base/uniform' );
22+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
2223
var incrnanmprod = require( './../lib' );
2324

2425
var accumulator;
@@ -32,7 +33,7 @@ accumulator = incrnanmprod( 5 );
3233
// For each simulated datum, update the moving product...
3334
console.log( '\nValue\tProduct\n' );
3435
for ( i = 0; i < 100; i++ ) {
35-
v = ( randu()*10.0 ) - 5.0;
36+
v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -30.0, 30.0 );
3637
p = accumulator( v );
3738
console.log( '%d\t%d', v.toFixed( 3 ), p.toFixed( 3 ) );
3839
}

lib/node_modules/@stdlib/stats/incr/nanmprod/lib/main.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ var incrmprod = require( '@stdlib/stats/incr/mprod' );
2929
/**
3030
* Returns an accumulator function which incrementally computes a moving product, ignoring `NaN` values.
3131
*
32-
* ## Method
33-
*
34-
* 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.
35-
*
36-
* 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).
37-
*
38-
* ## References
39-
*
40-
* - 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).
41-
*
4232
* @param {PositiveInteger} W - window size
4333
* @returns {Function} accumulator function
4434
*

0 commit comments

Comments
 (0)