Skip to content

Commit 58636bd

Browse files
authored
bench: update random value generation
PR-URL: #6813 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 3c4a571 commit 58636bd

File tree

15 files changed

+175
-197
lines changed

15 files changed

+175
-197
lines changed

lib/node_modules/@stdlib/stats/base/dists/beta/quantile/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 quantile = require( './../lib' );
3433
bench( pkg, function benchmark( b ) {
3534
var alpha;
3635
var beta;
37-
var len;
36+
var opts;
3837
var p;
3938
var y;
4039
var i;
4140

42-
len = 100;
43-
p = new Float64Array( len );
44-
alpha = new Float64Array( len );
45-
beta = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
p[ i ] = uniform( 0.0, 1.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+
p = uniform( 100, 0.0, 1.0, opts );
5147

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = quantile( p[ i % len ], alpha[ i % len ], beta[ i % len ] );
50+
y = quantile( p[ i % p.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 myQuantile;
6965
var alpha;
7066
var beta;
71-
var len;
67+
var opts;
7268
var p;
7369
var y;
7470
var i;
7571

72+
opts = {
73+
'dtype': 'float64'
74+
};
75+
p = uniform( 100, 0.0, 1.0, opts );
76+
7677
alpha = 100.56789;
7778
beta = 55.54321;
7879
myQuantile = quantile.factory( alpha, beta );
79-
len = 100;
80-
p = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
p[ i ] = uniform( 0.0, 1.0 );
83-
}
8480

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

lib/node_modules/@stdlib/stats/base/dists/beta/quantile/test/test.factory.js

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

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

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

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

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

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

8484
quantile = factory( 1.0, 1.0 );
8585
y = quantile( -0.1 );
86-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
8787

8888
y = quantile( 1.1 );
89-
t.equal( isnan( y ), true, 'returns NaN' );
89+
t.equal( isnan( y ), true, 'returns expected value' );
9090

9191
t.end();
9292
});
@@ -98,26 +98,26 @@ tape( 'if provided a nonpositive `beta`, the created function always returns `Na
9898
quantile = factory( 0.0, -1.0 );
9999

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

103103
y = quantile( 0.0 );
104-
t.equal( isnan( y ), true, 'returns NaN' );
104+
t.equal( isnan( y ), true, 'returns expected value' );
105105

106106
quantile = factory( 0.0, NINF );
107107
y = quantile( 2.0 );
108-
t.equal( isnan( y ), true, 'returns NaN' );
108+
t.equal( isnan( y ), true, 'returns expected value' );
109109

110110
quantile = factory( PINF, NINF );
111111
y = quantile( 2.0 );
112-
t.equal( isnan( y ), true, 'returns NaN' );
112+
t.equal( isnan( y ), true, 'returns expected value' );
113113

114114
quantile = factory( NINF, NINF );
115115
y = quantile( 2.0 );
116-
t.equal( isnan( y ), true, 'returns NaN' );
116+
t.equal( isnan( y ), true, 'returns expected value' );
117117

118118
quantile = factory( NaN, NINF );
119119
y = quantile( 2.0 );
120-
t.equal( isnan( y ), true, 'returns NaN' );
120+
t.equal( isnan( y ), true, 'returns expected value' );
121121

122122
t.end();
123123
});
@@ -129,31 +129,31 @@ tape( 'if provided a nonpositive `alpha`, the created function always returns `N
129129
quantile = factory( 0.0, 0.5 );
130130

131131
y = quantile( 0.5 );
132-
t.equal( isnan( y ), true, 'returns NaN' );
132+
t.equal( isnan( y ), true, 'returns expected value' );
133133

134134
quantile = factory( -1.0, 0.5 );
135135

136136
y = quantile( 0.5 );
137-
t.equal( isnan( y ), true, 'returns NaN' );
137+
t.equal( isnan( y ), true, 'returns expected value' );
138138

139139
y = quantile( 0.5 );
140-
t.equal( isnan( y ), true, 'returns NaN' );
140+
t.equal( isnan( y ), true, 'returns expected value' );
141141

142142
quantile = factory( NINF, 1.0 );
143143
y = quantile( 0.5 );
144-
t.equal( isnan( y ), true, 'returns NaN' );
144+
t.equal( isnan( y ), true, 'returns expected value' );
145145

146146
quantile = factory( NINF, PINF );
147147
y = quantile( 0.5 );
148-
t.equal( isnan( y ), true, 'returns NaN' );
148+
t.equal( isnan( y ), true, 'returns expected value' );
149149

150150
quantile = factory( NINF, NINF );
151151
y = quantile( 0.5 );
152-
t.equal( isnan( y ), true, 'returns NaN' );
152+
t.equal( isnan( y ), true, 'returns expected value' );
153153

154154
quantile = factory( NINF, NaN );
155155
y = quantile( 0.5 );
156-
t.equal( isnan( y ), true, 'returns NaN' );
156+
t.equal( isnan( y ), true, 'returns expected value' );
157157

158158
t.end();
159159
});

lib/node_modules/@stdlib/stats/base/dists/beta/quantile/test/test.quantile.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,45 @@ 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 = quantile( NaN, 0.0, 1.0 );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
y = quantile( 0.0, NaN, 1.0 );
51-
t.equal( isnan( y ), true, 'returns NaN' );
51+
t.equal( isnan( y ), true, 'returns expected value' );
5252
y = quantile( 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 outside `[0,1]` for `p` and a valid `alpha` and `beta`, the function returns `NaN`', function test( t ) {
5858
var y = quantile( 1.1, 1.0, 1.0 );
59-
t.equal( isnan( y ), true, 'returns true' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060
y = quantile( -0.1, 1.0, 1.0 );
61-
t.equal( isnan( y ), true, 'returns true' );
61+
t.equal( isnan( y ), true, 'returns expected value' );
6262
t.end();
6363
});
6464

6565
tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function test( t ) {
6666
var y;
6767

6868
y = quantile( 0.5, 0.0, 2.0 );
69-
t.equal( isnan( y ), true, 'returns NaN' );
69+
t.equal( isnan( y ), true, 'returns expected value' );
7070

7171
y = quantile( 0.5, -1.0, 2.0 );
72-
t.equal( isnan( y ), true, 'returns NaN' );
72+
t.equal( isnan( y ), true, 'returns expected value' );
7373

7474
y = quantile( 0.5, -1.0, 2.0 );
75-
t.equal( isnan( y ), true, 'returns NaN' );
75+
t.equal( isnan( y ), true, 'returns expected value' );
7676

7777
y = quantile( 0.5, NINF, 1.0 );
78-
t.equal( isnan( y ), true, 'returns NaN' );
78+
t.equal( isnan( y ), true, 'returns expected value' );
7979

8080
y = quantile( 0.5, NINF, PINF );
81-
t.equal( isnan( y ), true, 'returns NaN' );
81+
t.equal( isnan( y ), true, 'returns expected value' );
8282

8383
y = quantile( 0.5, NINF, NINF );
84-
t.equal( isnan( y ), true, 'returns NaN' );
84+
t.equal( isnan( y ), true, 'returns expected value' );
8585

8686
y = quantile( 0.5, NINF, NaN );
87-
t.equal( isnan( y ), true, 'returns NaN' );
87+
t.equal( isnan( y ), true, 'returns expected value' );
8888

8989
t.end();
9090
});
@@ -93,25 +93,25 @@ tape( 'if provided a nonpositive `beta`, the function returns `NaN`', function t
9393
var y;
9494

9595
y = quantile( 0.5, 2.0, 0.0 );
96-
t.equal( isnan( y ), true, 'returns NaN' );
96+
t.equal( isnan( y ), true, 'returns expected value' );
9797

9898
y = quantile( 0.5, 2.0, -1.0 );
99-
t.equal( isnan( y ), true, 'returns NaN' );
99+
t.equal( isnan( y ), true, 'returns expected value' );
100100

101101
y = quantile( 0.5, 2.0, -1.0 );
102-
t.equal( isnan( y ), true, 'returns NaN' );
102+
t.equal( isnan( y ), true, 'returns expected value' );
103103

104104
y = quantile( 0.5, 1.0, NINF );
105-
t.equal( isnan( y ), true, 'returns NaN' );
105+
t.equal( isnan( y ), true, 'returns expected value' );
106106

107107
y = quantile( 0.5, PINF, NINF );
108-
t.equal( isnan( y ), true, 'returns NaN' );
108+
t.equal( isnan( y ), true, 'returns expected value' );
109109

110110
y = quantile( 0.5, NINF, NINF );
111-
t.equal( isnan( y ), true, 'returns NaN' );
111+
t.equal( isnan( y ), true, 'returns expected value' );
112112

113113
y = quantile( 0.5, NaN, NINF );
114-
t.equal( isnan( y ), true, 'returns NaN' );
114+
t.equal( isnan( y ), true, 'returns expected value' );
115115

116116
t.end();
117117
});

lib/node_modules/@stdlib/stats/base/dists/beta/skewness/benchmark/benchmark.js

Lines changed: 8 additions & 11 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,21 +33,19 @@ var skewness = require( './../lib' );
3433
bench( pkg, function benchmark( b ) {
3534
var alpha;
3635
var beta;
37-
var len;
36+
var opts;
3837
var y;
3938
var i;
4039

41-
len = 100;
42-
alpha = new Float64Array( len );
43-
beta = new Float64Array( len );
44-
for ( i = 0; i < len; i++ ) {
45-
alpha[ i ] = uniform( EPS, 10.0 );
46-
beta[ i ] = uniform( EPS, 10.0 );
47-
}
40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
alpha = uniform( 100, EPS, 10.0, opts );
44+
beta = uniform( 100, EPS, 10.0, opts );
4845

4946
b.tic();
5047
for ( i = 0; i < b.iterations; i++ ) {
51-
y = skewness( alpha[ i % len ], beta[ i % len ] );
48+
y = skewness( alpha[ i % alpha.length ], beta[ i % beta.length ] );
5249
if ( isnan( y ) ) {
5350
b.fail( 'should not return NaN' );
5451
}

lib/node_modules/@stdlib/stats/base/dists/beta/skewness/benchmark/benchmark.native.js

Lines changed: 8 additions & 11 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 Float64Array = require( '@stdlib/array/float64' );
26-
var uniform = require( '@stdlib/random/base/uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var EPS = require( '@stdlib/constants/float64/eps' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -43,21 +42,19 @@ var opts = {
4342
bench( pkg+'::native', opts, function benchmark( b ) {
4443
var alpha;
4544
var beta;
46-
var len;
45+
var opts;
4746
var y;
4847
var i;
4948

50-
len = 100;
51-
alpha = new Float64Array( len );
52-
beta = new Float64Array( len );
53-
for ( i = 0; i < len; i++ ) {
54-
alpha[ i ] = uniform( EPS, 10.0 );
55-
beta[ i ] = uniform( EPS, 10.0 );
56-
}
49+
opts = {
50+
'dtype': 'float64'
51+
};
52+
alpha = uniform( 100, EPS, 10.0, opts );
53+
beta = uniform( 100, EPS, 10.0, opts );
5754

5855
b.tic();
5956
for ( i = 0; i < b.iterations; i++ ) {
60-
y = skewness( alpha[ i % len ], beta[ i % len ] );
57+
y = skewness( alpha[ i % alpha.length ], beta[ i % beta.length ] );
6158
if ( isnan( y ) ) {
6259
b.fail( 'should not return NaN' );
6360
}

0 commit comments

Comments
 (0)