Skip to content

Commit 7279e43

Browse files
authored
bench: update random value generation
PR-URL: #6853 Reviewed-by: Athan Reines <[email protected]>
1 parent c1acd4b commit 7279e43

File tree

6 files changed

+181
-193
lines changed

6 files changed

+181
-193
lines changed

lib/node_modules/@stdlib/stats/base/dists/binomial/cdf/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 cdf = require( './../lib' );
@@ -32,26 +31,23 @@ var cdf = 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 x;
3938
var y;
4039
var i;
4140

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

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = cdf( x[ i % len ], n[ i % len ], p[ i % len ] );
50+
y = cdf( x[ i % x.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 mycdf;
69-
var len;
65+
var opts;
7066
var n;
7167
var p;
7268
var x;
7369
var y;
7470
var i;
7571

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

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

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,36 @@ 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 = cdf( NaN, 10, 0.5 );
50-
t.equal( isnan( y ), true, 'returns NaN' );
50+
t.equal( isnan( y ), true, 'returns expected value' );
5151
y = cdf( 0.0, NaN, 0.5 );
52-
t.equal( isnan( y ), true, 'returns NaN' );
52+
t.equal( isnan( y ), true, 'returns expected value' );
5353
y = cdf( 0.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 `x` greater than or equal to `n`, the function returns `1` (provided `n` and `p` are valid)', function test( t ) {
5959
var y = cdf( PINF, 20, 0.5 );
60-
t.equal( y, 1.0, 'returns 1' );
60+
t.equal( y, 1.0, 'returns expected value' );
6161

6262
y = cdf( 200, 20, 0.5 );
63-
t.equal( y, 1.0, 'returns 1' );
63+
t.equal( y, 1.0, 'returns expected value' );
6464

6565
y = cdf( 21, 20, 0.5 );
66-
t.equal( y, 1.0, 'returns 1' );
66+
t.equal( y, 1.0, 'returns expected value' );
6767

6868
t.end();
6969
});
7070

7171
tape( 'if provided a negative number for `x` and a valid `n` and `p`, the function returns `0`', function test( t ) {
7272
var y = cdf( NINF, 20, 0.5 );
73-
t.equal( y, 0.0, 'returns 0' );
73+
t.equal( y, 0.0, 'returns expected value' );
7474

7575
y = cdf( -10.0, 20, 0.5 );
76-
t.equal( y, 0.0, 'returns 0' );
76+
t.equal( y, 0.0, 'returns expected value' );
7777

7878
y = cdf( -1.0, 20, 0.5 );
79-
t.equal( y, 0.0, 'returns 0' );
79+
t.equal( y, 0.0, 'returns expected value' );
8080

8181
t.end();
8282
});
@@ -85,19 +85,19 @@ tape( 'if provided a `n` which is not a nonnegative integer, the function return
8585
var y;
8686

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

9090
y = cdf( 2.0, -2, 0.5 );
91-
t.equal( isnan( y ), true, 'returns NaN' );
91+
t.equal( isnan( y ), true, 'returns expected value' );
9292

9393
y = cdf( 2.0, -1, 0.5 );
94-
t.equal( isnan( y ), true, 'returns NaN' );
94+
t.equal( isnan( y ), true, 'returns expected value' );
9595

9696
y = cdf( 0.0, 2.5, 0.5 );
97-
t.equal( isnan( y ), true, 'returns NaN' );
97+
t.equal( isnan( y ), true, 'returns expected value' );
9898

9999
y = cdf( 0.0, PINF, 0.5 );
100-
t.equal( isnan( y ), true, 'returns NaN' );
100+
t.equal( isnan( y ), true, 'returns expected value' );
101101

102102
t.end();
103103
});
@@ -106,16 +106,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
106106
var y;
107107

108108
y = cdf( 2.0, 20, -1.0 );
109-
t.equal( isnan( y ), true, 'returns NaN' );
109+
t.equal( isnan( y ), true, 'returns expected value' );
110110

111111
y = cdf( 0.0, 20, 1.5 );
112-
t.equal( isnan( y ), true, 'returns NaN' );
112+
t.equal( isnan( y ), true, 'returns expected value' );
113113

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

117117
y = cdf( 2.0, 20, PINF );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

120120
t.end();
121121
});

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

Lines changed: 22 additions & 22 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
cdf = factory( 20, 0.5 );
5959
y = cdf( NaN );
60-
t.equal( isnan( y ), true, 'returns NaN' );
60+
t.equal( isnan( y ), true, 'returns expected value' );
6161

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

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

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

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

7878
t.end();
7979
});
@@ -84,13 +84,13 @@ tape( 'if provided a valid `n` and `p`, the function returns a function which re
8484

8585
cdf = factory( 20, 0.5 );
8686
y = cdf( PINF );
87-
t.equal( y, 1.0, 'returns 1' );
87+
t.equal( y, 1.0, 'returns expected value' );
8888

8989
y = cdf( 200.0 );
90-
t.equal( y, 1.0, 'returns 1' );
90+
t.equal( y, 1.0, 'returns expected value' );
9191

9292
y = cdf( 20.0 );
93-
t.equal( y, 1.0, 'returns 1' );
93+
t.equal( y, 1.0, 'returns expected value' );
9494

9595
t.end();
9696
});
@@ -101,16 +101,16 @@ tape( 'if provided a valid `n` and `p`, the function returns a function which re
101101

102102
cdf = factory( 20, 0.5 );
103103
y = cdf( NINF );
104-
t.equal( y, 0.0, 'returns 0' );
104+
t.equal( y, 0.0, 'returns expected value' );
105105

106106
y = cdf( -10.0 );
107-
t.equal( y, 0.0, 'returns 0' );
107+
t.equal( y, 0.0, 'returns expected value' );
108108

109109
y = cdf( -1.0 );
110-
t.equal( y, 0.0, 'returns 0' );
110+
t.equal( y, 0.0, 'returns expected value' );
111111

112112
y = cdf( -0.5 );
113-
t.equal( y, 0.0, 'returns 0' );
113+
t.equal( y, 0.0, 'returns expected value' );
114114

115115
t.end();
116116
});
@@ -122,22 +122,22 @@ tape( 'if provided a `n` which is not a nonnegative integer, the created functio
122122
cdf = factory( 20.5, 0.5 );
123123

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

127127
y = cdf( 0.0 );
128-
t.equal( isnan( y ), true, 'returns NaN' );
128+
t.equal( isnan( y ), true, 'returns expected value' );
129129

130130
cdf = factory( -10, 0.5 );
131131
y = cdf( 2.0 );
132-
t.equal( isnan( y ), true, 'returns NaN' );
132+
t.equal( isnan( y ), true, 'returns expected value' );
133133

134134
cdf = factory( PINF, 0.5 );
135135
y = cdf( 2.0 );
136-
t.equal( isnan( y ), true, 'returns NaN' );
136+
t.equal( isnan( y ), true, 'returns expected value' );
137137

138138
cdf = factory( NINF, 0.5 );
139139
y = cdf( 2.0 );
140-
t.equal( isnan( y ), true, 'returns NaN' );
140+
t.equal( isnan( y ), true, 'returns expected value' );
141141

142142
t.end();
143143
});
@@ -149,22 +149,22 @@ tape( 'if provided a success probability `p` outside `[0,1]`, the created functi
149149
cdf = factory( 20, 1.5 );
150150

151151
y = cdf( 2.0 );
152-
t.equal( isnan( y ), true, 'returns NaN' );
152+
t.equal( isnan( y ), true, 'returns expected value' );
153153

154154
y = cdf( 0.0 );
155-
t.equal( isnan( y ), true, 'returns NaN' );
155+
t.equal( isnan( y ), true, 'returns expected value' );
156156

157157
cdf = factory( 20, -0.5 );
158158
y = cdf( 2.0 );
159-
t.equal( isnan( y ), true, 'returns NaN' );
159+
t.equal( isnan( y ), true, 'returns expected value' );
160160

161161
cdf = factory( 20, PINF );
162162
y = cdf( 2.0 );
163-
t.equal( isnan( y ), true, 'returns NaN' );
163+
t.equal( isnan( y ), true, 'returns expected value' );
164164

165165
cdf = factory( 20, NINF );
166166
y = cdf( 2.0 );
167-
t.equal( isnan( y ), true, 'returns NaN' );
167+
t.equal( isnan( y ), true, 'returns expected value' );
168168

169169
t.end();
170170
});

0 commit comments

Comments
 (0)