Skip to content

Commit 5301df6

Browse files
authored
bench: update random value generation
PR-URL: #6841 Reviewed-by: Athan Reines <[email protected]>
1 parent e8dea99 commit 5301df6

File tree

16 files changed

+229
-254
lines changed

16 files changed

+229
-254
lines changed

lib/node_modules/@stdlib/stats/base/dists/betaprime/logcdf/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 logcdf = 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 = logcdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] );
50+
y = logcdf( 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 mylogcdf;
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
mylogcdf = logcdf.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 = mylogcdf( x[ i % len ] );
83+
y = mylogcdf( x[ i % x.length ] );
8884
if ( isnan( y ) ) {
8985
b.fail( 'should not return NaN' );
9086
}

lib/node_modules/@stdlib/stats/base/dists/betaprime/logcdf/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
logcdf = factory( 1.0, 1.0 );
5858
y = logcdf( NaN );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060

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

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

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

7373
logcdf = factory( NaN, NaN );
7474
y = logcdf( 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
logcdf = factory( 0.5, 1.0 );
8585
y = logcdf( NINF );
86-
t.equal( y, NINF, 'returns -infinity' );
86+
t.equal( y, NINF, 'returns expected value' );
8787

8888
y = logcdf( -100.0 );
89-
t.equal( y, NINF, 'returns -infinity' );
89+
t.equal( y, NINF, 'returns expected value' );
9090

9191
y = logcdf( -10.0 );
92-
t.equal( y, NINF, 'returns -infinity' );
92+
t.equal( y, NINF, 'returns expected value' );
9393

9494
y = logcdf( -1.0 );
95-
t.equal( y, NINF, 'returns -infinity' );
95+
t.equal( y, NINF, 'returns expected value' );
9696

9797
y = logcdf( 0.0 );
98-
t.equal( y, NINF, 'returns -infinity' );
98+
t.equal( y, NINF, '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
logcdf = factory( 0.5, 1.0 );
108108
y = logcdf( PINF );
109-
t.equal( y, 0.0, 'returns 0' );
109+
t.equal( y, 0.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
logcdf = factory( 1.0, 0.0 );
119119

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

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

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

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

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

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

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

143143
logcdf = factory( NaN, NINF );
144144
y = logcdf( 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
logcdf = factory( 0.0, 0.5 );
155155

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

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

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

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

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

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

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

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

183183
t.end();
184184
});

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ 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 = logcdf( NaN, 1.0, 1.0 );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
y = logcdf( 0.0, NaN, 1.0 );
51-
t.equal( isnan( y ), true, 'returns NaN' );
51+
t.equal( isnan( y ), true, 'returns expected value' );
5252
y = logcdf( 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 `-infinity`', function test( t ) {
5858
var y = logcdf( NINF, 0.5, 1.0 );
59-
t.equal( y, NINF, 'returns -infinity' );
59+
t.equal( y, NINF, 'returns expected value' );
6060

6161
y = logcdf( -100.0, 0.5, 1.0 );
62-
t.equal( y, NINF, 'returns -infinity' );
62+
t.equal( y, NINF, 'returns expected value' );
6363

6464
y = logcdf( -1.0, 0.5, 1.0 );
65-
t.equal( y, NINF, 'returns -infinity' );
65+
t.equal( y, NINF, 'returns expected value' );
6666

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

7070
t.end();
7171
});
@@ -80,25 +80,25 @@ tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function
8080
var y;
8181

8282
y = logcdf( 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 = logcdf( 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 = logcdf( 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 = logcdf( 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 = logcdf( 2.0, NINF, PINF );
95-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
9696

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

100100
y = logcdf( 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 = logcdf( 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 = logcdf( 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 = logcdf( 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 = logcdf( 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 = logcdf( 2.0, PINF, NINF );
122-
t.equal( isnan( y ), true, 'returns NaN' );
122+
t.equal( isnan( y ), true, 'returns expected value' );
123123

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

127127
y = logcdf( 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/logpdf/benchmark/benchmark.js

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

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' );
25-
var Float64Array = require( '@stdlib/array/float64' );
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 logpdf = 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-
alpha = new Float64Array( len );
44-
beta = new Float64Array( len );
45-
x = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
alpha[ i ] = uniform( EPS, 100.0 );
48-
beta[ i ] = uniform( EPS, 100.0 );
49-
x[ i ] = uniform( EPS, 2.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 = logpdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] );
50+
y = logpdf( 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,24 +64,23 @@ bench( pkg+':factory', function benchmark( b ) {
6864
var mylogpdf;
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
mylogpdf = logpdf.factory( alpha, beta );
7980

80-
len = 100;
81-
x = new Float64Array( len );
82-
for ( i = 0; i < len; i++ ) {
83-
x[ i ] = uniform( EPS, 2.0 );
84-
}
85-
8681
b.tic();
8782
for ( i = 0; i < b.iterations; i++ ) {
88-
y = mylogpdf( x[ i % len ] );
83+
y = mylogpdf( x[ i % x.length ] );
8984
if ( isnan( y ) ) {
9085
b.fail( 'should not return NaN' );
9186
}

0 commit comments

Comments
 (0)