Skip to content

Commit 876d319

Browse files
authored
bench: update random value generation
PR-URL: #7009 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 0ab37c0 commit 876d319

File tree

17 files changed

+228
-246
lines changed

17 files changed

+228
-246
lines changed

lib/node_modules/@stdlib/stats/base/dists/chi/cdf/benchmark/benchmark.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var Float64Array = require( '@stdlib/array/float64' );
25-
var uniform = require( '@stdlib/random/base/uniform' );
26-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pkg = require( './../package.json' ).name;
2928
var cdf = require( './../lib' );
@@ -32,23 +31,21 @@ var cdf = require( './../lib' );
3231
// MAIN //
3332

3433
bench( pkg, function benchmark( b ) {
35-
var len;
34+
var opts;
3635
var k;
3736
var x;
3837
var y;
3938
var i;
4039

41-
len = 100;
42-
x = new Float64Array( len );
43-
k = new Float64Array( len );
44-
for ( i = 0; i < len; i++ ) {
45-
x[ i ] = uniform( 0.0, 100.0 );
46-
k[ i ] = discreteUniform( 1, 100 );
47-
}
40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
x = uniform( 100, 0.0, 100.0, opts );
44+
k = discreteUniform( 100, 1, 100, opts );
4845

4946
b.tic();
5047
for ( i = 0; i < b.iterations; i++ ) {
51-
y = cdf( x[ i % len ], k[ i % len ] );
48+
y = cdf( x[ i % x.length ], k[ i % k.length ] );
5249
if ( isnan( y ) ) {
5350
b.fail( 'should not return NaN' );
5451
}
@@ -63,23 +60,23 @@ bench( pkg, function benchmark( b ) {
6360

6461
bench( pkg+':factory', function benchmark( b ) {
6562
var mycdf;
66-
var len;
63+
var opts;
6764
var k;
6865
var x;
6966
var y;
7067
var i;
7168

69+
opts = {
70+
'dtype': 'float64'
71+
};
72+
x = uniform( 100, 0.0, 100.0, opts );
73+
7274
k = 10.0;
7375
mycdf = cdf.factory( k );
74-
len = 100;
75-
x = new Float64Array( len );
76-
for ( i = 0; i < len; i++ ) {
77-
x[ i ] = uniform( 0.0, 100.0 );
78-
}
7976

8077
b.tic();
8178
for ( i = 0; i < b.iterations; i++ ) {
82-
y = mycdf( x[ i % len ] );
79+
y = mycdf( x[ i % x.length ] );
8380
if ( isnan( y ) ) {
8481
b.fail( 'should not return NaN' );
8582
}

lib/node_modules/@stdlib/stats/base/dists/chi/cdf/test/test.cdf.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,35 @@ tape( 'main export is a function', function test( t ) {
4444

4545
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4646
var y = cdf( NaN, 1.0 );
47-
t.equal( isnan( y ), true, 'returns NaN' );
47+
t.equal( isnan( y ), true, 'returns expected value' );
4848
y = cdf( 0.0, NaN );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
t.end();
5151
});
5252

5353
tape( 'if provided `+infinity` for `x` and a finite `k`, the function returns `1`', function test( t ) {
5454
var y = cdf( PINF, 1.0 );
55-
t.equal( y, 1.0, 'returns 1' );
55+
t.equal( y, 1.0, 'returns expected value' );
5656
t.end();
5757
});
5858

5959
tape( 'if provided `-infinity` for `x` and a finite `k`, the function returns `0`', function test( t ) {
6060
var y = cdf( NINF, 1.0 );
61-
t.equal( y, 0.0, 'returns 0' );
61+
t.equal( y, 0.0, 'returns expected value' );
6262
t.end();
6363
});
6464

6565
tape( 'if provided a negative `k`, the function always returns `NaN`', function test( t ) {
6666
var y;
6767

6868
y = cdf( 2.0, -1.0 );
69-
t.equal( isnan( y ), true, 'returns NaN' );
69+
t.equal( isnan( y ), true, 'returns expected value' );
7070

7171
y = cdf( 0.0, -1.0 );
72-
t.equal( isnan( y ), true, 'returns NaN' );
72+
t.equal( isnan( y ), true, 'returns expected value' );
7373

7474
y = cdf( 2.0, NINF );
75-
t.equal( isnan( y ), true, 'returns NaN' );
75+
t.equal( isnan( y ), true, 'returns expected value' );
7676

7777
t.end();
7878
});
@@ -81,22 +81,22 @@ tape( 'if provided a `k` equal to `0`, the function evaluates a degenerate distr
8181
var y;
8282

8383
y = cdf( PINF, 0.0 );
84-
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
84+
t.equal( y, 1.0, 'returns expected value' );
8585

8686
y = cdf( 2.5, 0.0 );
87-
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
87+
t.equal( y, 1.0, 'returns expected value' );
8888

8989
y = cdf( 0.0, 0.0 );
90-
t.equal( y, 1.0, 'returns 1 for x equal to 0' );
90+
t.equal( y, 1.0, 'returns expected value' );
9191

9292
y = cdf( -2.0, 0.0 );
93-
t.equal( y, 0.0, 'returns 0 for x smaller than 0' );
93+
t.equal( y, 0.0, 'returns expected value' );
9494

9595
y = cdf( NINF, 0.0 );
96-
t.equal( y, 0.0, 'returns 0 for x smaller than 0' );
96+
t.equal( y, 0.0, 'returns expected value' );
9797

9898
y = cdf( NaN, 0.0 );
99-
t.equal( isnan( y ), true, 'returns NaN' );
99+
t.equal( isnan( y ), true, 'returns expected value' );
100100

101101
t.end();
102102
});

lib/node_modules/@stdlib/stats/base/dists/chi/cdf/test/test.factory.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
5454

5555
cdf = factory( 1.0 );
5656
y = cdf( NaN );
57-
t.equal( isnan( y ), true, 'returns NaN' );
57+
t.equal( isnan( y ), true, 'returns expected value' );
5858

5959
cdf = factory( NaN );
6060
y = cdf( 0.0 );
61-
t.equal( isnan( y ), true, 'returns NaN' );
61+
t.equal( isnan( y ), true, 'returns expected value' );
6262

6363
t.end();
6464
});
@@ -69,7 +69,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `
6969

7070
cdf = factory( 1.0 );
7171
y = cdf( PINF );
72-
t.equal( y, 1.0, 'returns 1' );
72+
t.equal( y, 1.0, 'returns expected value' );
7373

7474
t.end();
7575
});
@@ -80,7 +80,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `
8080

8181
cdf = factory( 0.0, 1.0 );
8282
y = cdf( NINF );
83-
t.equal( y, 0.0, 'returns 0' );
83+
t.equal( y, 0.0, 'returns expected value' );
8484

8585
t.end();
8686
});
@@ -92,10 +92,10 @@ tape( 'if provided a negative `k`, the created function always returns `NaN`', f
9292
cdf = factory( -1.0 );
9393

9494
y = cdf( 2.0 );
95-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
9696

9797
y = cdf( 0.0 );
98-
t.equal( isnan( y ), true, 'returns NaN' );
98+
t.equal( isnan( y ), true, 'returns expected value' );
9999

100100
t.end();
101101
});
@@ -107,22 +107,22 @@ tape( 'if `k` equals `0`, the created function evaluates a degenerate distributi
107107
cdf = factory( 0.0 );
108108

109109
y = cdf( PINF );
110-
t.equal( y, 1.0, 'returns 1 for x greater than one' );
110+
t.equal( y, 1.0, 'returns expected value' );
111111

112112
y = cdf( 3.0 );
113-
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
113+
t.equal( y, 1.0, 'returns expected value' );
114114

115115
y = cdf( 0.0 );
116-
t.equal( y, 1.0, 'returns 1 for x equal to 0' );
116+
t.equal( y, 1.0, 'returns expected value' );
117117

118118
y = cdf( -0.5 );
119-
t.equal( y, 0.0, 'returns 0 for x smaller than one' );
119+
t.equal( y, 0.0, 'returns expected value' );
120120

121121
y = cdf( NINF );
122-
t.equal( y, 0.0, 'returns 0 for x smaller than one' );
122+
t.equal( y, 0.0, 'returns expected value' );
123123

124124
y = cdf( NaN );
125-
t.equal( isnan( y ), true, 'returns NaN' );
125+
t.equal( isnan( y ), true, 'returns expected value' );
126126

127127
t.end();
128128
});

0 commit comments

Comments
 (0)