Skip to content

Commit e8dea99

Browse files
authored
bench: update random value generation
PR-URL: #6842 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent a70718c commit e8dea99

File tree

19 files changed

+271
-299
lines changed

19 files changed

+271
-299
lines changed

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

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var uniform = require( '@stdlib/random/base/uniform' );
26-
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var tryRequire = require( '@stdlib/utils/try-require' );
2928
var EPS = require( '@stdlib/constants/float64/eps' );
@@ -43,24 +42,21 @@ var opts = {
4342
bench( pkg+'::native', opts, function benchmark( b ) {
4443
var alpha;
4544
var beta;
46-
var len;
45+
var opts;
4746
var x;
4847
var y;
4948
var i;
5049

51-
len = 100;
52-
x = new Float64Array( len );
53-
alpha = new Float64Array( len );
54-
beta = new Float64Array( len );
55-
for ( i = 0; i < len; i++ ) {
56-
x[ i ] = uniform( EPS, 2.0 );
57-
alpha[ i ] = uniform( EPS, 100.0 );
58-
beta[ i ] = uniform( EPS, 100.0 );
59-
}
50+
opts = {
51+
'dtype': 'float64'
52+
};
53+
alpha = uniform( 100, EPS, 100.0, opts );
54+
beta = uniform( 100, EPS, 100.0, opts );
55+
x = uniform( 100, EPS, 2.0, opts );
6056

6157
b.tic();
6258
for ( i = 0; i < b.iterations; i++ ) {
63-
y = pdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] );
59+
y = pdf( x[ i % x.length ], alpha[ i % alpha.length ], beta[ i % beta.length ] );
6460
if ( isnan( y ) ) {
6561
b.fail( 'should not return NaN' );
6662
}

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

Lines changed: 21 additions & 21 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
pdf = factory( 1.0, 1.0 );
5858
y = pdf( NaN );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060

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

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

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

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

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

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

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

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

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

9797
t.end();
9898
});
@@ -104,26 +104,26 @@ tape( 'if provided `beta <= 0`, the created function always returns `NaN`', func
104104
pdf = factory( 0.0, -1.0 );
105105

106106
y = pdf( 2.0 );
107-
t.equal( isnan( y ), true, 'returns NaN' );
107+
t.equal( isnan( y ), true, 'returns expected value' );
108108

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

112112
pdf = factory( 0.0, NINF );
113113
y = pdf( 2.0 );
114-
t.equal( isnan( y ), true, 'returns NaN' );
114+
t.equal( isnan( y ), true, 'returns expected value' );
115115

116116
pdf = factory( PINF, NINF );
117117
y = pdf( 2.0 );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

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

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

128128
t.end();
129129
});
@@ -135,26 +135,26 @@ tape( 'if provided `alpha <= 0`, the created function always returns `NaN`', fun
135135
pdf = factory( -1.0, 0.5 );
136136

137137
y = pdf( 2.0 );
138-
t.equal( isnan( y ), true, 'returns NaN' );
138+
t.equal( isnan( y ), true, 'returns expected value' );
139139

140140
y = pdf( 0.0 );
141-
t.equal( isnan( y ), true, 'returns NaN' );
141+
t.equal( isnan( y ), true, 'returns expected value' );
142142

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

147147
pdf = factory( NINF, PINF );
148148
y = pdf( 2.0 );
149-
t.equal( isnan( y ), true, 'returns NaN' );
149+
t.equal( isnan( y ), true, 'returns expected value' );
150150

151151
pdf = factory( NINF, NINF );
152152
y = pdf( 2.0 );
153-
t.equal( isnan( y ), true, 'returns NaN' );
153+
t.equal( isnan( y ), true, 'returns expected value' );
154154

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

159159
t.end();
160160
});

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,28 @@ tape( 'main export is a function', opts, function test( t ) {
5555

5656
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
5757
var y = pdf( NaN, 1.0, 1.0 );
58-
t.equal( isnan( y ), true, 'returns NaN' );
58+
t.equal( isnan( y ), true, 'returns expected value' );
5959
y = pdf( 0.0, NaN, 1.0 );
60-
t.equal( isnan( y ), true, 'returns NaN' );
60+
t.equal( isnan( y ), true, 'returns expected value' );
6161
y = pdf( 0.0, 1.0, NaN );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
6363
t.end();
6464
});
6565

6666
tape( 'if provided a nonpositive number for `x` and a valid `alpha` and `beta`, the function returns `0`', opts, function test( t ) {
6767
var y;
6868

6969
y = pdf( NINF, 1.0, 1.0 );
70-
t.equal( y, 0.0, 'returns 0' );
70+
t.equal( y, 0.0, 'returns expected value' );
7171

7272
y = pdf( -100.0, 1.0, 1.0 );
73-
t.equal( y, 0.0, 'returns 0' );
73+
t.equal( y, 0.0, 'returns expected value' );
7474

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

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

8181
t.end();
8282
});
@@ -85,22 +85,22 @@ tape( 'if provided `alpha <= 0`, the function returns `NaN`', opts, function tes
8585
var y;
8686

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

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

9393
y = pdf( 2.0, NINF, 1.0 );
94-
t.equal( isnan( y ), true, 'returns NaN' );
94+
t.equal( isnan( y ), true, 'returns expected value' );
9595

9696
y = pdf( 2.0, NINF, PINF );
97-
t.equal( isnan( y ), true, 'returns NaN' );
97+
t.equal( isnan( y ), true, 'returns expected value' );
9898

9999
y = pdf( 2.0, NINF, NINF );
100-
t.equal( isnan( y ), true, 'returns NaN' );
100+
t.equal( isnan( y ), true, 'returns expected value' );
101101

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

105105
t.end();
106106
});
@@ -109,22 +109,22 @@ tape( 'if provided `beta <= 0`, the function returns `NaN`', opts, function test
109109
var y;
110110

111111
y = pdf( 2.0, 2.0, -1.0 );
112-
t.equal( isnan( y ), true, 'returns NaN' );
112+
t.equal( isnan( y ), true, 'returns expected value' );
113113

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

117117
y = pdf( 2.0, 1.0, NINF );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

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

123123
y = pdf( 2.0, NINF, NINF );
124-
t.equal( isnan( y ), true, 'returns NaN' );
124+
t.equal( isnan( y ), true, 'returns expected value' );
125125

126126
y = pdf( 2.0, NaN, NINF );
127-
t.equal( isnan( y ), true, 'returns NaN' );
127+
t.equal( isnan( y ), true, 'returns expected value' );
128128

129129
t.end();
130130
});

0 commit comments

Comments
 (0)