Skip to content

Commit d87dd71

Browse files
authored
bench: update random value generation
PR-URL: #6812 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 9f4b944 commit d87dd71

File tree

14 files changed

+220
-242
lines changed

14 files changed

+220
-242
lines changed

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

+8-11
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 median = 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 = median( alpha[ i % len ], beta[ i % len ] );
48+
y = median( 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/median/test/test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ tape( 'main export is a function', function test( t ) {
4444

4545
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4646
var v = median( NaN, 0.5 );
47-
t.equal( isnan( v ), true, 'returns NaN' );
47+
t.equal( isnan( v ), true, 'returns expected value' );
4848

4949
v = median( 10.0, NaN );
50-
t.equal( isnan( v ), true, 'returns NaN' );
50+
t.equal( isnan( v ), true, 'returns expected value' );
5151

5252
t.end();
5353
});
@@ -56,19 +56,19 @@ tape( 'if provided `alpha <= 0`, the function returns `NaN`', function test( t )
5656
var y;
5757

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

6161
y = median( NINF, 1.0 );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
6363

6464
y = median( NINF, PINF );
65-
t.equal( isnan( y ), true, 'returns NaN' );
65+
t.equal( isnan( y ), true, 'returns expected value' );
6666

6767
y = median( NINF, NINF );
68-
t.equal( isnan( y ), true, 'returns NaN' );
68+
t.equal( isnan( y ), true, 'returns expected value' );
6969

7070
y = median( NINF, NaN );
71-
t.equal( isnan( y ), true, 'returns NaN' );
71+
t.equal( isnan( y ), true, 'returns expected value' );
7272

7373
t.end();
7474
});
@@ -77,19 +77,19 @@ tape( 'if provided `beta <= 0`, the function returns `NaN`', function test( t )
7777
var y;
7878

7979
y = median( 2.0, -1.0 );
80-
t.equal( isnan( y ), true, 'returns NaN' );
80+
t.equal( isnan( y ), true, 'returns expected value' );
8181

8282
y = median( 1.0, NINF );
83-
t.equal( isnan( y ), true, 'returns NaN' );
83+
t.equal( isnan( y ), true, 'returns expected value' );
8484

8585
y = median( PINF, NINF );
86-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
8787

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

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

9494
t.end();
9595
});

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

+16-20
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 mgf = require( './../lib' );
3433
bench( pkg, function benchmark( b ) {
3534
var alpha;
3635
var beta;
37-
var len;
36+
var opts;
3837
var t;
3938
var y;
4039
var i;
4140

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

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

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

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

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
4949

5050
mgf = factory( 1.0, 1.0 );
5151
y = mgf( NaN );
52-
t.equal( isnan( y ), true, 'returns NaN' );
52+
t.equal( isnan( y ), true, 'returns expected value' );
5353

5454
mgf = factory( NaN, 1.0 );
5555
y = mgf( 0.0 );
56-
t.equal( isnan( y ), true, 'returns NaN' );
56+
t.equal( isnan( y ), true, 'returns expected value' );
5757

5858
mgf = factory( 1.0, NaN );
5959
y = mgf( 0.0 );
60-
t.equal( isnan( y ), true, 'returns NaN' );
60+
t.equal( isnan( y ), true, 'returns expected value' );
6161

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

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

7070
t.end();
7171
});
@@ -77,31 +77,31 @@ tape( 'if provided a nonpositive `beta`, the created function always returns `Na
7777
mgf = factory( 1.0, 0.0 );
7878

7979
y = mgf( 2.0 );
80-
t.equal( isnan( y ), true, 'returns NaN' );
80+
t.equal( isnan( y ), true, 'returns expected value' );
8181

8282
mgf = factory( 1.0, -1.0 );
8383

8484
y = mgf( 2.0 );
85-
t.equal( isnan( y ), true, 'returns NaN' );
85+
t.equal( isnan( y ), true, 'returns expected value' );
8686

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

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

9494
mgf = factory( PINF, NINF );
9595
y = mgf( 2.0 );
96-
t.equal( isnan( y ), true, 'returns NaN' );
96+
t.equal( isnan( y ), true, 'returns expected value' );
9797

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

102102
mgf = factory( NaN, NINF );
103103
y = mgf( 2.0 );
104-
t.equal( isnan( y ), true, 'returns NaN' );
104+
t.equal( isnan( y ), true, 'returns expected value' );
105105

106106
t.end();
107107
});
@@ -113,31 +113,31 @@ tape( 'if provided a nonpositive `alpha`, the created function always returns `N
113113
mgf = factory( 0.0, 0.5 );
114114

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

118118
mgf = factory( -1.0, 0.5 );
119119

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

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

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

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

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

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

142142
t.end();
143143
});
@@ -153,7 +153,7 @@ tape( 'the created function evaluates the mgf', function test( t ) {
153153
for ( i = 0; i < 100; i++ ) {
154154
x = randu();
155155
y = mgf( x );
156-
t.strictEqual( !isnan( y ) && isNumber( y ), true, 'returns a number' );
156+
t.strictEqual( !isnan( y ) && isNumber( y ), true, 'returns expected value' );
157157
}
158158
t.end();
159159
});

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,37 @@ tape( 'main export is a function', function test( t ) {
4040

4141
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4242
var y = mgf( NaN, 0.0, 1.0 );
43-
t.equal( isnan( y ), true, 'returns NaN' );
43+
t.equal( isnan( y ), true, 'returns expected value' );
4444
y = mgf( 0.0, NaN, 1.0 );
45-
t.equal( isnan( y ), true, 'returns NaN' );
45+
t.equal( isnan( y ), true, 'returns expected value' );
4646
y = mgf( 0.0, 1.0, NaN );
47-
t.equal( isnan( y ), true, 'returns NaN' );
47+
t.equal( isnan( y ), true, 'returns expected value' );
4848
t.end();
4949
});
5050

5151
tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function test( t ) {
5252
var y;
5353

5454
y = mgf( 2.0, 0.0, 2.0 );
55-
t.equal( isnan( y ), true, 'returns NaN' );
55+
t.equal( isnan( y ), true, 'returns expected value' );
5656

5757
y = mgf( 2.0, -1.0, 2.0 );
58-
t.equal( isnan( y ), true, 'returns NaN' );
58+
t.equal( isnan( y ), true, 'returns expected value' );
5959

6060
y = mgf( 0.0, -1.0, 2.0 );
61-
t.equal( isnan( y ), true, 'returns NaN' );
61+
t.equal( isnan( y ), true, 'returns expected value' );
6262

6363
y = mgf( 2.0, NINF, 1.0 );
64-
t.equal( isnan( y ), true, 'returns NaN' );
64+
t.equal( isnan( y ), true, 'returns expected value' );
6565

6666
y = mgf( 2.0, NINF, PINF );
67-
t.equal( isnan( y ), true, 'returns NaN' );
67+
t.equal( isnan( y ), true, 'returns expected value' );
6868

6969
y = mgf( 2.0, NINF, NINF );
70-
t.equal( isnan( y ), true, 'returns NaN' );
70+
t.equal( isnan( y ), true, 'returns expected value' );
7171

7272
y = mgf( 2.0, NINF, NaN );
73-
t.equal( isnan( y ), true, 'returns NaN' );
73+
t.equal( isnan( y ), true, 'returns expected value' );
7474

7575
t.end();
7676
});
@@ -79,25 +79,25 @@ tape( 'if provided a nonpositive `beta`, the function returns `NaN`', function t
7979
var y;
8080

8181
y = mgf( 2.0, 2.0, 0.0 );
82-
t.equal( isnan( y ), true, 'returns NaN' );
82+
t.equal( isnan( y ), true, 'returns expected value' );
8383

8484
y = mgf( 2.0, 2.0, -1.0 );
85-
t.equal( isnan( y ), true, 'returns NaN' );
85+
t.equal( isnan( y ), true, 'returns expected value' );
8686

8787
y = mgf( 0.0, 2.0, -1/0 );
88-
t.equal( isnan( y ), true, 'returns NaN' );
88+
t.equal( isnan( y ), true, 'returns expected value' );
8989

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

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

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

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

102102
t.end();
103103
});

0 commit comments

Comments
 (0)