Skip to content

Commit 22c4c3e

Browse files
authored
bench: update random value generation
PR-URL: #6857 Reviewed-by: Athan Reines <[email protected]>
1 parent 2336365 commit 22c4c3e

File tree

13 files changed

+241
-261
lines changed

13 files changed

+241
-261
lines changed

lib/node_modules/@stdlib/stats/base/dists/binomial/mgf/benchmark/benchmark.js

Lines changed: 17 additions & 21 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 mgf = require( './../lib' );
@@ -32,26 +31,23 @@ var mgf = require( './../lib' );
3231
// MAIN //
3332

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

42-
len = 100;
43-
t = new Float64Array( len );
44-
n = new Float64Array( len );
45-
p = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
t[ i ] = uniform( 0.0, 5.0 );
48-
n[ i ] = discreteUniform( 1, 100 );
49-
p[ i ] = uniform( 0.0, 1.0 );
50-
}
41+
opts = {
42+
'dtype': 'float64'
43+
};
44+
t = uniform( 100, 0.0, 5.0, opts );
45+
n = discreteUniform( 100, 1, 100, opts );
46+
p = uniform( 100, 0.0, 1.0, opts );
5147

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = mgf( t[ i % len ], n[ i % len ], p[ i % len ] );
50+
y = mgf( t[ i % t.length ], n[ i % n.length ], p[ i % p.length ] );
5551
if ( isnan( y ) ) {
5652
b.fail( 'should not return NaN' );
5753
}
@@ -66,25 +62,25 @@ bench( pkg, function benchmark( b ) {
6662

6763
bench( pkg+':factory', function benchmark( b ) {
6864
var mymgf;
69-
var len;
65+
var opts;
7066
var n;
7167
var p;
7268
var t;
7369
var y;
7470
var i;
7571

72+
opts = {
73+
'dtype': 'float64'
74+
};
75+
t = uniform( 100, 0.0, 5.0, opts );
76+
7677
n = 80;
7778
p = 0.4;
7879
mymgf = mgf.factory( n, p );
79-
len = 100;
80-
t = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
t[ i ] = uniform( 0.0, 5.0 );
83-
}
8480

8581
b.tic();
8682
for ( i = 0; i < b.iterations; i++ ) {
87-
y = mymgf( t[ i % len ] );
83+
y = mymgf( t[ i % t.length ] );
8884
if ( isnan( y ) ) {
8985
b.fail( 'should not return NaN' );
9086
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mgf/test/test.factory.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
5757

5858
mgf = factory( 20, 0.5 );
5959
y = mgf( NaN );
60-
t.equal( isnan( y ), true, 'returns NaN' );
60+
t.equal( isnan( y ), true, 'returns expected value' );
6161

6262
mgf = factory( NaN, 0.5 );
6363
y = mgf( 0.0 );
64-
t.equal( isnan( y ), true, 'returns NaN' );
64+
t.equal( isnan( y ), true, 'returns expected value' );
6565

6666
mgf = factory( 20, NaN );
6767
y = mgf( 0.0 );
68-
t.equal( isnan( y ), true, 'returns NaN' );
68+
t.equal( isnan( y ), true, 'returns expected value' );
6969

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

7474
mgf = factory( NaN, NaN );
7575
y = mgf( NaN );
76-
t.equal( isnan( y ), true, 'returns NaN' );
76+
t.equal( isnan( y ), true, 'returns expected value' );
7777

7878
t.end();
7979
});
@@ -85,22 +85,22 @@ tape( 'if provided an `n` which is not a nonnegative integer, the created functi
8585
mgf = factory( 20.5, 0.5 );
8686

8787
y = mgf( 2.0 );
88-
t.equal( isnan( y ), true, 'returns NaN' );
88+
t.equal( isnan( y ), true, 'returns expected value' );
8989

9090
y = mgf( 0.0 );
91-
t.equal( isnan( y ), true, 'returns NaN' );
91+
t.equal( isnan( y ), true, 'returns expected value' );
9292

9393
mgf = factory( -10, 0.5 );
9494
y = mgf( 2.0 );
95-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
9696

9797
mgf = factory( PINF, 0.5 );
9898
y = mgf( 2.0 );
99-
t.equal( isnan( y ), true, 'returns NaN' );
99+
t.equal( isnan( y ), true, 'returns expected value' );
100100

101101
mgf = factory( NINF, 0.5 );
102102
y = mgf( 2.0 );
103-
t.equal( isnan( y ), true, 'returns NaN' );
103+
t.equal( isnan( y ), true, 'returns expected value' );
104104

105105
t.end();
106106
});
@@ -112,22 +112,22 @@ tape( 'if provided a success probability `p` outside `[0,1]`, the created functi
112112
mgf = factory( 20, 1.5 );
113113

114114
y = mgf( 2.0 );
115-
t.equal( isnan( y ), true, 'returns NaN' );
115+
t.equal( isnan( y ), true, 'returns expected value' );
116116

117117
y = mgf( 0.0 );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

120120
mgf = factory( 20, -0.5 );
121121
y = mgf( 2.0 );
122-
t.equal( isnan( y ), true, 'returns NaN' );
122+
t.equal( isnan( y ), true, 'returns expected value' );
123123

124124
mgf = factory( 20, PINF );
125125
y = mgf( 2.0 );
126-
t.equal( isnan( y ), true, 'returns NaN' );
126+
t.equal( isnan( y ), true, 'returns expected value' );
127127

128128
mgf = factory( 20, NINF );
129129
y = mgf( 2.0 );
130-
t.equal( isnan( y ), true, 'returns NaN' );
130+
t.equal( isnan( y ), true, 'returns expected value' );
131131

132132
t.end();
133133
});

lib/node_modules/@stdlib/stats/base/dists/binomial/mgf/test/test.mgf.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ tape( 'main export is a function', function test( t ) {
4747

4848
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4949
var y = mgf( NaN, 10, 0.5 );
50-
t.equal( isnan( y ), true, 'returns NaN' );
50+
t.equal( isnan( y ), true, 'returns expected value' );
5151
y = mgf( 4.0, NaN, 0.5 );
52-
t.equal( isnan( y ), true, 'returns NaN' );
52+
t.equal( isnan( y ), true, 'returns expected value' );
5353
y = mgf( 4.0, 10, NaN );
54-
t.equal( isnan( y ), true, 'returns NaN' );
54+
t.equal( isnan( y ), true, 'returns expected value' );
5555
t.end();
5656
});
5757

5858
tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', function test( t ) {
5959
var y;
6060

6161
y = mgf( 2.0, 1.5, 0.5 );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
6363

6464
y = mgf( 2.0, -2, 0.5 );
65-
t.equal( isnan( y ), true, 'returns NaN' );
65+
t.equal( isnan( y ), true, 'returns expected value' );
6666

6767
y = mgf( 2.0, -1, 0.5 );
68-
t.equal( isnan( y ), true, 'returns NaN' );
68+
t.equal( isnan( y ), true, 'returns expected value' );
6969

7070
y = mgf( 0.0, 2.5, 0.5 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
71+
t.equal( isnan( y ), true, 'returns expected value' );
7272

7373
y = mgf( 0.0, PINF, 0.5 );
74-
t.equal( isnan( y ), true, 'returns NaN' );
74+
t.equal( isnan( y ), true, 'returns expected value' );
7575

7676
t.end();
7777
});
@@ -80,16 +80,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
8080
var y;
8181

8282
y = mgf( 2.0, 20, -1.0 );
83-
t.equal( isnan( y ), true, 'returns NaN' );
83+
t.equal( isnan( y ), true, 'returns expected value' );
8484

8585
y = mgf( 0.0, 20, 1.5 );
86-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
8787

8888
y = mgf( 2.0, 20, NINF );
89-
t.equal( isnan( y ), true, 'returns NaN' );
89+
t.equal( isnan( y ), true, 'returns expected value' );
9090

9191
y = mgf( 2.0, 20, PINF );
92-
t.equal( isnan( y ), true, 'returns NaN' );
92+
t.equal( isnan( y ), true, 'returns expected value' );
9393

9494
t.end();
9595
});

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/benchmark.js

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

2323
var bench = require( '@stdlib/bench' );
24-
var Int32Array = require( '@stdlib/array/int32' );
25-
var Float64Array = require( '@stdlib/array/float64' );
26-
var uniform = require( '@stdlib/random/base/uniform' );
27-
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' );
2826
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2927
var pkg = require( './../package.json' ).name;
3028
var mode = require( './../lib' );
@@ -33,23 +31,21 @@ var mode = require( './../lib' );
3331
// MAIN //
3432

3533
bench( pkg, function benchmark( b ) {
36-
var len;
3734
var n;
3835
var p;
3936
var y;
4037
var i;
4138

42-
len = 100;
43-
n = new Int32Array( len );
44-
p = new Float64Array( len );
45-
for ( i = 0; i < len; i++ ) {
46-
n[ i ] = discreteUniform( 1, 100 );
47-
p[ i ] = uniform( 0.0, 1.0 );
48-
}
39+
n = discreteUniform( 100, 1, 100, {
40+
'dtype': 'int32'
41+
});
42+
p = uniform( 100, 0.0, 1.0, {
43+
'dtype': 'float64'
44+
});
4945

5046
b.tic();
5147
for ( i = 0; i < b.iterations; i++ ) {
52-
y = mode( n[ i % len ], p[ i % len ] );
48+
y = mode( n[ i % n.length ], p[ i % p.length ] );
5349
if ( isnan( y ) ) {
5450
b.fail( 'should not return NaN' );
5551
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/benchmark.native.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var Int32Array = require( '@stdlib/array/int32' );
26-
var Float64Array = require( '@stdlib/array/float64' );
2725
var tryRequire = require( '@stdlib/utils/try-require' );
28-
var uniform = require( '@stdlib/random/base/uniform' );
29-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
3028
var isnan = require( '@stdlib/math/base/assert/is-nan' );
3129
var pkg = require( './../package.json' ).name;
3230

@@ -42,23 +40,21 @@ var opts = {
4240
// MAIN //
4341

4442
bench( pkg+'::native', opts, function benchmark( b ) {
45-
var len;
4643
var n;
4744
var p;
4845
var y;
4946
var i;
5047

51-
len = 100;
52-
n = new Int32Array( len );
53-
p = new Float64Array( len );
54-
for ( i = 0; i < len; i++ ) {
55-
n[ i ] = discreteUniform( 1, 100 );
56-
p[ i ] = uniform( 0.0, 1.0 );
57-
}
48+
n = discreteUniform( 100, 1, 100, {
49+
'dtype': 'int32'
50+
});
51+
p = uniform( 100, 0.0, 1.0, {
52+
'dtype': 'float64'
53+
});
5854

5955
b.tic();
6056
for ( i = 0; i < b.iterations; i++ ) {
61-
y = mode( n[ i % len ], p[ i % len ] );
57+
y = mode( n[ i % n.length ], p[ i % p.length ] );
6258
if ( isnan( y ) ) {
6359
b.fail( 'should not return NaN' );
6460
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/test/test.js

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

4040
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4141
var v = mode( NaN, 0.5 );
42-
t.equal( isnan( v ), true, 'returns NaN' );
42+
t.equal( isnan( v ), true, 'returns expected value' );
4343

4444
v = mode( 10, NaN );
45-
t.equal( isnan( v ), true, 'returns NaN' );
45+
t.equal( isnan( v ), true, 'returns expected value' );
4646

4747
v = mode( NaN, NaN );
48-
t.equal( isnan( v ), true, 'returns NaN' );
48+
t.equal( isnan( v ), true, 'returns expected value' );
4949

5050
t.end();
5151
});
@@ -54,19 +54,19 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur
5454
var v;
5555

5656
v = mode( 1.5, 0.5 );
57-
t.equal( isnan( v ), true, 'returns NaN' );
57+
t.equal( isnan( v ), true, 'returns expected value' );
5858

5959
v = mode( -2, 0.5 );
60-
t.equal( isnan( v ), true, 'returns NaN' );
60+
t.equal( isnan( v ), true, 'returns expected value' );
6161

6262
v = mode( -1, 0.5 );
63-
t.equal( isnan( v ), true, 'returns NaN' );
63+
t.equal( isnan( v ), true, 'returns expected value' );
6464

6565
v = mode( 2.5, 0.5 );
66-
t.equal( isnan( v ), true, 'returns NaN' );
66+
t.equal( isnan( v ), true, 'returns expected value' );
6767

6868
v = mode( PINF, 0.5 );
69-
t.equal( isnan( v ), true, 'returns NaN' );
69+
t.equal( isnan( v ), true, 'returns expected value' );
7070

7171
t.end();
7272
});
@@ -75,16 +75,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
7575
var v;
7676

7777
v = mode( 20, -1.0 );
78-
t.equal( isnan( v ), true, 'returns NaN' );
78+
t.equal( isnan( v ), true, 'returns expected value' );
7979

8080
v = mode( 20, 1.5 );
81-
t.equal( isnan( v ), true, 'returns NaN' );
81+
t.equal( isnan( v ), true, 'returns expected value' );
8282

8383
v = mode( 20, NINF );
84-
t.equal( isnan( v ), true, 'returns NaN' );
84+
t.equal( isnan( v ), true, 'returns expected value' );
8585

8686
v = mode( 20, PINF );
87-
t.equal( isnan( v ), true, 'returns NaN' );
87+
t.equal( isnan( v ), true, 'returns expected value' );
8888

8989
t.end();
9090
});

0 commit comments

Comments
 (0)