Skip to content

Commit 3353337

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

File tree

8 files changed

+200
-213
lines changed

8 files changed

+200
-213
lines changed

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var Float64Array = require( '@stdlib/array/float64' );
25-
var uniform = require( '@stdlib/random/base/uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2625
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var EPS = require( '@stdlib/constants/float64/eps' );
2827
var pkg = require( './../package.json' ).name;
@@ -34,24 +33,21 @@ var cdf = require( './../lib' );
3433
bench( pkg, function benchmark( b ) {
3534
var alpha;
3635
var beta;
37-
var len;
36+
var opts;
3837
var x;
3938
var y;
4039
var i;
4140

42-
len = 100;
43-
x = new Float64Array( len );
44-
alpha = new Float64Array( len );
45-
beta = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
x[ i ] = uniform( EPS, 2.0 );
48-
alpha[ i ] = uniform( EPS, 100.0 );
49-
beta[ i ] = uniform( EPS, 100.0 );
50-
}
41+
opts = {
42+
'dtype': 'float64'
43+
};
44+
alpha = uniform( 100, EPS, 100.0, opts );
45+
beta = uniform( 100, EPS, 100.0, opts );
46+
x = uniform( 100, EPS, 2.0, opts );
5147

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = cdf( x[i % len], alpha[i % len], beta[i % len] );
50+
y = cdf( x[ i % x.length ], alpha[ i % alpha.length ], beta[ i % beta.length ] );
5551
if ( isnan( y ) ) {
5652
b.fail( 'should not return NaN' );
5753
}
@@ -68,23 +64,23 @@ bench( pkg+':factory', function benchmark( b ) {
6864
var mycdf;
6965
var alpha;
7066
var beta;
71-
var len;
67+
var opts;
7268
var x;
7369
var y;
7470
var i;
7571

72+
opts = {
73+
'dtype': 'float64'
74+
};
75+
x = uniform( 100, EPS, 2.0, opts );
76+
7677
alpha = 100.56789;
7778
beta = 55.54321;
7879
mycdf = cdf.factory( alpha, beta );
79-
len = 100;
80-
x = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
x[ i ] = uniform( EPS, 2.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/betaprime/cdf/test/test.cdf.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,59 +46,59 @@ tape( 'main export is a function', function test( t ) {
4646

4747
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4848
var y = cdf( NaN, 1.0, 1.0 );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
y = cdf( 0.0, NaN, 1.0 );
51-
t.equal( isnan( y ), true, 'returns NaN' );
51+
t.equal( isnan( y ), true, 'returns expected value' );
5252
y = cdf( 0.0, 1.0, NaN );
53-
t.equal( isnan( y ), true, 'returns NaN' );
53+
t.equal( isnan( y ), true, 'returns expected value' );
5454
t.end();
5555
});
5656

5757
tape( 'if provided a number less than or equal to zero for `x` and a finite `alpha` and `beta`, the function returns `0`', function test( t ) {
5858
var y = cdf( NINF, 0.5, 1.0 );
59-
t.equal( y, 0.0, 'returns 0' );
59+
t.equal( y, 0.0, 'returns expected value' );
6060

6161
y = cdf( -100.0, 0.5, 1.0 );
62-
t.equal( y, 0.0, 'returns 0' );
62+
t.equal( y, 0.0, 'returns expected value' );
6363

6464
y = cdf( -1.0, 0.5, 1.0 );
65-
t.equal( y, 0.0, 'returns 0' );
65+
t.equal( y, 0.0, 'returns expected value' );
6666

6767
y = cdf( 0.0, 0.5, 1.0 );
68-
t.equal( y, 0.0, 'returns 0' );
68+
t.equal( y, 0.0, 'returns expected value' );
6969

7070
t.end();
7171
});
7272

7373
tape( 'if provided `+Infinity` for `x` and a finite `alpha` and `beta`, the function returns `1`', function test( t ) {
7474
var y = cdf( PINF, 0.5, 1.0 );
75-
t.equal( y, 1.0, 'returns 1' );
75+
t.equal( y, 1.0, 'returns expected value' );
7676
t.end();
7777
});
7878

7979
tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function test( t ) {
8080
var y;
8181

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

8585
y = cdf( 2.0, -1.0, 2.0 );
86-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
8787

8888
y = cdf( 0.0, -1.0, 2.0 );
89-
t.equal( isnan( y ), true, 'returns NaN' );
89+
t.equal( isnan( y ), true, 'returns expected value' );
9090

9191
y = cdf( 2.0, NINF, 1.0 );
92-
t.equal( isnan( y ), true, 'returns NaN' );
92+
t.equal( isnan( y ), true, 'returns expected value' );
9393

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

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

100100
y = cdf( 2.0, NINF, NaN );
101-
t.equal( isnan( y ), true, 'returns NaN' );
101+
t.equal( isnan( y ), true, 'returns expected value' );
102102

103103
t.end();
104104
});
@@ -107,25 +107,25 @@ tape( 'if provided a nonpositive `beta`, the function returns `NaN`', function t
107107
var y;
108108

109109
y = cdf( 2.0, 2.0, 0.0 );
110-
t.equal( isnan( y ), true, 'returns NaN' );
110+
t.equal( isnan( y ), true, 'returns expected value' );
111111

112112
y = cdf( 2.0, 2.0, -1.0 );
113-
t.equal( isnan( y ), true, 'returns NaN' );
113+
t.equal( isnan( y ), true, 'returns expected value' );
114114

115115
y = cdf( 0.0, 2.0, -1/0 );
116-
t.equal( isnan( y ), true, 'returns NaN' );
116+
t.equal( isnan( y ), true, 'returns expected value' );
117117

118118
y = cdf( 2.0, 1.0, NINF );
119-
t.equal( isnan( y ), true, 'returns NaN' );
119+
t.equal( isnan( y ), true, 'returns expected value' );
120120

121121
y = cdf( 2.0, PINF, NINF );
122-
t.equal( isnan( y ), true, 'returns NaN' );
122+
t.equal( isnan( y ), true, 'returns expected value' );
123123

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

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

130130
t.end();
131131
});

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

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

5757
cdf = factory( 1.0, 1.0 );
5858
y = cdf( NaN );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060

6161
cdf = factory( NaN, 1.0 );
6262
y = cdf( 0.0 );
63-
t.equal( isnan( y ), true, 'returns NaN' );
63+
t.equal( isnan( y ), true, 'returns expected value' );
6464

6565
cdf = factory( 1.0, NaN );
6666
y = cdf( 0.0 );
67-
t.equal( isnan( y ), true, 'returns NaN' );
67+
t.equal( isnan( y ), true, 'returns expected value' );
6868

6969
cdf = factory( NaN, NaN );
7070
y = cdf( 0.0 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
71+
t.equal( isnan( y ), true, 'returns expected value' );
7272

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

7777
t.end();
7878
});
@@ -83,19 +83,19 @@ tape( 'if provided a finite `alpha` and `beta`, the function returns a function
8383

8484
cdf = factory( 0.5, 1.0 );
8585
y = cdf( NINF );
86-
t.equal( y, 0.0, 'returns 0' );
86+
t.equal( y, 0.0, 'returns expected value' );
8787

8888
y = cdf( -100.0 );
89-
t.equal( y, 0.0, 'returns 0' );
89+
t.equal( y, 0.0, 'returns expected value' );
9090

9191
y = cdf( -10.0 );
92-
t.equal( y, 0.0, 'returns 0' );
92+
t.equal( y, 0.0, 'returns expected value' );
9393

9494
y = cdf( -1.0 );
95-
t.equal( y, 0.0, 'returns 0' );
95+
t.equal( y, 0.0, 'returns expected value' );
9696

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

100100
t.end();
101101
});
@@ -106,7 +106,7 @@ tape( 'if provided a finite `alpha` and `beta`, the function returns a function
106106

107107
cdf = factory( 0.5, 1.0 );
108108
y = cdf( PINF );
109-
t.equal( y, 1.0, 'returns 1' );
109+
t.equal( y, 1.0, 'returns expected value' );
110110

111111
t.end();
112112
});
@@ -118,31 +118,31 @@ tape( 'if provided a nonpositive `beta`, the created function always returns `Na
118118
cdf = factory( 1.0, 0.0 );
119119

120120
y = cdf( 2.0 );
121-
t.equal( isnan( y ), true, 'returns NaN' );
121+
t.equal( isnan( y ), true, 'returns expected value' );
122122

123123
cdf = factory( 1.0, -1.0 );
124124

125125
y = cdf( 2.0 );
126-
t.equal( isnan( y ), true, 'returns NaN' );
126+
t.equal( isnan( y ), true, 'returns expected value' );
127127

128128
y = cdf( 0.0 );
129-
t.equal( isnan( y ), true, 'returns NaN' );
129+
t.equal( isnan( y ), true, 'returns expected value' );
130130

131131
cdf = factory( 1.0, NINF );
132132
y = cdf( 2.0 );
133-
t.equal( isnan( y ), true, 'returns NaN' );
133+
t.equal( isnan( y ), true, 'returns expected value' );
134134

135135
cdf = factory( PINF, NINF );
136136
y = cdf( 2.0 );
137-
t.equal( isnan( y ), true, 'returns NaN' );
137+
t.equal( isnan( y ), true, 'returns expected value' );
138138

139139
cdf = factory( NINF, NINF );
140140
y = cdf( 2.0 );
141-
t.equal( isnan( y ), true, 'returns NaN' );
141+
t.equal( isnan( y ), true, 'returns expected value' );
142142

143143
cdf = factory( NaN, NINF );
144144
y = cdf( 2.0 );
145-
t.equal( isnan( y ), true, 'returns NaN' );
145+
t.equal( isnan( y ), true, 'returns expected value' );
146146

147147
t.end();
148148
});
@@ -154,31 +154,31 @@ tape( 'if provided a nonpositive `alpha`, the created function always returns `N
154154
cdf = factory( 0.0, 0.5 );
155155

156156
y = cdf( 2.0 );
157-
t.equal( isnan( y ), true, 'returns NaN' );
157+
t.equal( isnan( y ), true, 'returns expected value' );
158158

159159
cdf = factory( -1.0, 0.5 );
160160

161161
y = cdf( 2.0 );
162-
t.equal( isnan( y ), true, 'returns NaN' );
162+
t.equal( isnan( y ), true, 'returns expected value' );
163163

164164
y = cdf( 0.0 );
165-
t.equal( isnan( y ), true, 'returns NaN' );
165+
t.equal( isnan( y ), true, 'returns expected value' );
166166

167167
cdf = factory( NINF, 1.0 );
168168
y = cdf( 2.0 );
169-
t.equal( isnan( y ), true, 'returns NaN' );
169+
t.equal( isnan( y ), true, 'returns expected value' );
170170

171171
cdf = factory( NINF, PINF );
172172
y = cdf( 2.0 );
173-
t.equal( isnan( y ), true, 'returns NaN' );
173+
t.equal( isnan( y ), true, 'returns expected value' );
174174

175175
cdf = factory( NINF, NINF );
176176
y = cdf( 2.0 );
177-
t.equal( isnan( y ), true, 'returns NaN' );
177+
t.equal( isnan( y ), true, 'returns expected value' );
178178

179179
cdf = factory( NINF, NaN );
180180
y = cdf( 2.0 );
181-
t.equal( isnan( y ), true, 'returns NaN' );
181+
t.equal( isnan( y ), true, 'returns expected value' );
182182

183183
t.end();
184184
});

0 commit comments

Comments
 (0)