Skip to content

Commit f91104f

Browse files
committed
fix(stats): update benchmarks
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_license_headers status: passed ---
1 parent 594c5af commit f91104f

File tree

6 files changed

+51
-106
lines changed

6 files changed

+51
-106
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,22 @@ bench( pkg+'::accumulator,known_means', function benchmark( b ) {
9292

9393
bench( pkg+'::accumulator,with_nan', function benchmark( b ) {
9494
var acc;
95-
var v;
9695
var i;
9796
acc = incrnanmpcorr( 5 );
9897

9998
b.tic();
10099
for ( i = 0; i < b.iterations; i++ ) {
101100
if ( randu() < 0.2 ) {
102101
if ( randu() < 0.5 ) {
103-
v = acc( NaN, randu() );
102+
acc( NaN, randu() );
104103
} else {
105-
v = acc( randu(), NaN );
104+
acc( randu(), NaN );
106105
}
107106
} else {
108-
v = acc( randu(), randu() );
109-
}
110-
// Ensure that even with occasional NaN inputs the accumulator does not return NaN:
111-
if ( v !== v ) {
112-
b.fail( 'should not return NaN' );
107+
acc( randu(), randu() );
113108
}
114109
}
115110
b.toc();
116-
if ( v !== v ) {
117-
b.fail( 'should not return NaN' );
118-
}
119111
b.pass( 'benchmark finished' );
120112
b.end();
121113
});

lib/node_modules/@stdlib/stats/incr/nanmpcorr/docs/repl.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
> r = accumulator( 2.0, 1.0 )
3939
0.0
4040
> r = accumulator( -2.0, NaN )
41-
0.0
41+
NaN
4242
> r = accumulator( -5.0, 3.14 )
43-
~-1.0
43+
NaN
4444
> r = accumulator( NaN, 2.71 )
45-
~-1.0
45+
NaN
4646
> r = accumulator( 3.0, -1.0 )
47-
~-0.925
47+
NaN
4848
> r = accumulator( 5.0, -9.5 )
49-
~-0.863
49+
NaN
5050
> r = accumulator()
51-
~-0.863
51+
NaN
5252

5353
See Also
5454
--------

lib/node_modules/@stdlib/stats/incr/nanmpcorr/docs/types/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
type accumulator = ( x?: number, y?: number ) => number | null;
3535

3636
/**
37-
* Returns an accumulator function which incrementally computes an updated moving sample correlation coefficient, ignoring `NaN` values.
37+
* Returns an accumulator function which incrementally computes an updated moving sample correlation coefficient.
3838
*
3939
* ## Notes
4040
*
@@ -53,7 +53,7 @@ type accumulator = ( x?: number, y?: number ) => number | null;
5353
declare function incrnanmpcorr( W: number, meanx: number, meany: number ): accumulator;
5454

5555
/**
56-
* Returns an accumulator function which incrementally computes an updated moving sample correlation coefficient, ignoring `NaN` values.
56+
* Returns an accumulator function which incrementally computes an updated moving sample correlation coefficient.
5757
*
5858
* ## Notes
5959
*
@@ -74,22 +74,22 @@ declare function incrnanmpcorr( W: number, meanx: number, meany: number ): accum
7474
* // returns 0.0
7575
*
7676
* r = accumulator( -2.0, NaN );
77-
* // returns 0.0
77+
* // returns NaN
7878
*
7979
* r = accumulator( -5.0, 3.14 );
80-
* // returns ~-1.0
80+
* // returns NaN
8181
*
8282
* r = accumulator( NaN, 2.71 );
83-
* // returns ~-1.0
83+
* // returns NaN
8484
*
8585
* r = accumulator( 3.0, -1.0 );
86-
* // returns ~-0.925
86+
* // returns NaN
8787
*
8888
* r = accumulator( 5.0, -9.5 );
89-
* // returns ~-0.863
89+
* // returns NaN
9090
*
9191
* r = accumulator();
92-
* // returns ~-0.863
92+
* // returns NaN
9393
*/
9494
declare function incrnanmpcorr( W: number ): accumulator;
9595

lib/node_modules/@stdlib/stats/incr/nanmpcorr/lib/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Compute a moving sample Pearson product-moment correlation coefficient incrementally, ignoring `NaN` values..
22+
* Compute a moving sample Pearson product-moment correlation coefficient incrementally.
2323
*
2424
* @module @stdlib/stats/incr/nanmpcorr
2525
*
@@ -35,22 +35,22 @@
3535
* // returns 0.0
3636
*
3737
* r = accumulator( -2.0, NaN );
38-
* // returns 0.0
38+
* // returns NaN
3939
*
4040
* r = accumulator( -5.0, 3.14 );
41-
* // returns ~-1.0
41+
* // returns NaN
4242
*
4343
* r = accumulator( NaN, 2.71 );
44-
* // returns ~-1.0
44+
* // returns NaN
4545
*
4646
* r = accumulator( 3.0, -1.0 );
47-
* // returns ~-0.925
47+
* // returns NaN
4848
*
4949
* r = accumulator( 5.0, -9.5 );
50-
* // returns ~-0.863
50+
* // returns NaN
5151
*
5252
* r = accumulator();
53-
* // returns ~-0.863
53+
* // returns NaN
5454
*/
5555

5656
// MODULES //

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222

2323
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
2424
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var format = require( '@stdlib/string/format' );
2726
var incrmpcorr = require( '@stdlib/stats/incr/mpcorr' );
2827

2928

3029
// MAIN //
3130

3231
/**
33-
* Returns an accumulator function which incrementally computes a moving sample Pearson product-moment correlation coefficient, ignoring `NaN` values..
32+
* Returns an accumulator function which incrementally computes a moving sample Pearson product-moment correlation coefficient.
3433
*
3534
* @param {PositiveInteger} W - window size
3635
* @param {number} [meanx] - mean value
@@ -50,22 +49,22 @@ var incrmpcorr = require( '@stdlib/stats/incr/mpcorr' );
5049
* // returns 0.0
5150
*
5251
* r = accumulator( -2.0, NaN );
53-
* // returns 0.0
52+
* // returns NaN
5453
*
5554
* r = accumulator( -5.0, 3.14 );
56-
* // returns ~-1.0
55+
* // returns NaN
5756
*
5857
* r = accumulator( NaN, 2.71 );
59-
* // returns ~-1.0
58+
* // returns NaN
6059
*
6160
* r = accumulator( 3.0, -1.0 );
62-
* // returns ~-0.925
61+
* // returns NaN
6362
*
6463
* r = accumulator( 5.0, -9.5 );
65-
* // returns ~-0.863
64+
* // returns NaN
6665
*
6766
* r = accumulator();
68-
* // returns ~-0.863
67+
* // returns NaN
6968
*
7069
* @example
7170
* var accumulator = incrnanmpcorr( 3, -2.0, 10.0 );
@@ -99,9 +98,6 @@ function incrnanmpcorr( W, meanx, meany ) {
9998
if ( arguments.length === 0 ) {
10099
return mpcorr();
101100
}
102-
if ( isnan( x ) || isnan( y ) ) {
103-
return mpcorr();
104-
}
105101
return mpcorr( x, y );
106102
}
107103
}

lib/node_modules/@stdlib/stats/incr/nanmpcorr/test/test.js

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2018 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ var pow = require( '@stdlib/math/base/special/pow' );
2727
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2828
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2929
var EPS = require( '@stdlib/constants/float64/eps' );
30-
var floor = require( '@stdlib/math/base/special/floor' );
3130
var incrnanmpcorr = require( './../lib' );
3231

3332

@@ -168,39 +167,25 @@ function pcorr( arr, mx, my, bool ) {
168167
* @returns {ArrayArray} sample datasets
169168
*/
170169
function datasets( N, M, seed ) {
171-
var nanProb;
172-
var choice;
173170
var data;
174171
var rand;
175172
var tmp;
176173
var i;
177174
var j;
178-
var x;
179-
var y;
180175

181-
nanProb = 0.2;
182176
rand = randu.factory({
183177
'seed': seed || ( randu()*pow( 2.0, 31 ) )|0
184178
});
185179

180+
// Generate datasets consisting of (x,y) pairs of varying value ranges...
186181
data = [];
187182
for ( i = 0; i < N; i++ ) {
188183
tmp = [];
189184
for ( j = 0; j < M; j++ ) {
190-
x = rand() * pow( 10.0, i );
191-
y = rand() * pow( 10.0, i );
192-
if ( rand() < nanProb ) {
193-
choice = floor( rand() * 3 );
194-
if ( choice === 0 ) {
195-
x = NaN;
196-
} else if ( choice === 1 ) {
197-
y = NaN;
198-
} else {
199-
x = NaN;
200-
y = NaN;
201-
}
202-
}
203-
tmp.push( [ x, y ] );
185+
tmp.push([
186+
rand() * pow( 10.0, i ),
187+
rand() * pow( 10.0, i )
188+
]);
204189
}
205190
data.push( tmp );
206191
}
@@ -371,20 +356,12 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment
371356
for ( j = 0; j < M; j++ ) {
372357
actual = acc( d[j][0], d[j][1] );
373358
if ( j < W ) {
374-
arr = d.slice( 0, j+1 ).filter( function removeNan( pair ) {
375-
return !( isnan( pair[0] ) || isnan( pair[1] ) );
376-
});
377-
} else {
378-
arr = d.slice( j-W+1, j+1 ).filter( function removeNan( pair ) {
379-
return !( isnan( pair[0] ) || isnan( pair[1] ) );
380-
});
381-
}
382-
if ( arr.length === 0 ) {
383-
expected = 0.0;
359+
arr = d.slice( 0, j+1 );
384360
} else {
385-
means = mean( [ 0.0, 0.0 ], arr );
386-
expected = pcorr( arr, means[ 0 ], means[ 1 ], false );
361+
arr = d.slice( j-W+1, j+1 );
387362
}
363+
means = mean( [ 0.0, 0.0 ], arr );
364+
expected = pcorr( arr, means[ 0 ], means[ 1 ], false );
388365
if ( actual === expected ) {
389366
t.equal( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' );
390367
} else {
@@ -428,19 +405,11 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment
428405
for ( j = 0; j < M; j++ ) {
429406
actual = acc( d[j][0], d[j][1] );
430407
if ( j < W ) {
431-
arr = d.slice( 0, j+1 ).filter( function removeNan( pair ) {
432-
return !( isnan( pair[0] ) || isnan( pair[1] ) );
433-
});
434-
} else {
435-
arr = d.slice( j-W+1, j+1 ).filter( function removeNan( pair ) {
436-
return !( isnan( pair[0] ) || isnan( pair[1] ) );
437-
});
438-
}
439-
if ( arr.length === 0 ) {
440-
expected = 0.0;
408+
arr = d.slice( 0, j+1 );
441409
} else {
442-
expected = pcorr( arr, means[ 0 ], means[ 1 ], true );
410+
arr = d.slice( j-W+1, j+1 );
443411
}
412+
expected = pcorr( arr, means[ 0 ], means[ 1 ], true );
444413
if ( actual === expected ) {
445414
t.equal( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' );
446415
} else {
@@ -469,7 +438,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr
469438
data = [
470439
[ 2.0, 1.0 ],
471440
[ -5.0, 3.14 ],
472-
[ NaN, -1.0 ],
441+
[ 3.0, -1.0 ],
473442
[ 5.0, -9.5 ]
474443
];
475444
N = data.length;
@@ -484,16 +453,10 @@ tape( 'if not provided an input value, the accumulator function returns the curr
484453
if ( i < W-1 ) {
485454
d = data.slice( 0, i+1 );
486455
} else {
487-
d = data.slice( i-W+1, i+1 ).filter( function removeNan( pair ) {
488-
return !( isnan(pair[0]) || isnan(pair[1]) );
489-
});
490-
}
491-
if ( d.length === 0 ) {
492-
expected = 0.0;
493-
} else {
494-
means = mean( [ 0.0, 0.0 ], d );
495-
expected = pcorr( d, means[ 0 ], means[ 1 ], false );
456+
d = data.slice( i-W+1, i+1 );
496457
}
458+
means = mean( [ 0.0, 0.0 ], d );
459+
expected = pcorr( d, means[ 0 ], means[ 1 ], false );
497460
if ( actual === expected ) {
498461
t.equal( actual, expected, 'returns expected value. window: '+i+'.' );
499462
} else {
@@ -521,7 +484,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr
521484
data = [
522485
[ 2.0, 1.0 ],
523486
[ -5.0, 3.14 ],
524-
[ 3.0, NaN ],
487+
[ 3.0, -1.0 ],
525488
[ 5.0, -9.5 ]
526489
];
527490
N = data.length;
@@ -537,15 +500,9 @@ tape( 'if not provided an input value, the accumulator function returns the curr
537500
if ( i < W-1 ) {
538501
d = data.slice( 0, i+1 );
539502
} else {
540-
d = data.slice( i-W+1, i+1 ).filter( function removeNan( pair ) {
541-
return !( isnan(pair[0]) || isnan(pair[1]) );
542-
});
543-
}
544-
if ( d.length === 0 ) {
545-
expected = 0.0;
546-
} else {
547-
expected = pcorr( d, means[ 0 ], means[ 1 ], true );
503+
d = data.slice( i-W+1, i+1 );
548504
}
505+
expected = pcorr( d, means[ 0 ], means[ 1 ], true );
549506
if ( actual === expected ) {
550507
t.equal( actual, expected, 'returns expected value. window: '+i+'.' );
551508
} else {

0 commit comments

Comments
 (0)