Skip to content

Commit b51a457

Browse files
authored
bench: update random value generation
PR-URL: #7010 Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Harsh <[email protected]>
1 parent 367fdcd commit b51a457

File tree

20 files changed

+154
-174
lines changed

20 files changed

+154
-174
lines changed

lib/node_modules/@stdlib/stats/base/dists/chi/mode/benchmark/benchmark.js

Lines changed: 7 additions & 9 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 pkg = require( './../package.json' ).name;
2827
var mode = require( './../lib' );
@@ -31,20 +30,19 @@ var mode = require( './../lib' );
3130
// MAIN //
3231

3332
bench( pkg, function benchmark( b ) {
34-
var len;
33+
var opts;
3534
var k;
3635
var y;
3736
var i;
3837

39-
len = 100;
40-
k = new Float64Array( len );
41-
for ( i = 0; i < len; i++ ) {
42-
k[ i ] = uniform( 1.0, 20.0 );
43-
}
38+
opts = {
39+
'dtype': 'float64'
40+
};
41+
k = uniform( 100, 1.0, 20.0, opts );
4442

4543
b.tic();
4644
for ( i = 0; i < b.iterations; i++ ) {
47-
y = mode( k[ i % len ] );
45+
y = mode( k[ i % k.length ] );
4846
if ( isnan( y ) ) {
4947
b.fail( 'should not return NaN' );
5048
}

lib/node_modules/@stdlib/stats/base/dists/chi/mode/benchmark/benchmark.native.js

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var Float64Array = require( '@stdlib/array/float64' );
2625
var EPS = require( '@stdlib/constants/float64/eps' );
27-
var uniform = require( '@stdlib/random/base/uniform' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2827
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029
var pkg = require( './../package.json' ).name;
@@ -41,20 +40,19 @@ var opts = {
4140
// MAIN //
4241

4342
bench( pkg+'::native', opts, function benchmark( b ) {
44-
var len;
43+
var opts;
4544
var k;
4645
var y;
4746
var i;
4847

49-
len = 100;
50-
k = new Float64Array( len );
51-
for ( i = 0; i < len; i++ ) {
52-
k[ i ] = uniform( 1.0 + EPS, 20.0 );
53-
}
48+
opts = {
49+
'dtype': 'float64'
50+
};
51+
k = uniform( 100, 1.0 + EPS, 20.0, opts );
5452

5553
b.tic();
5654
for ( i = 0; i < b.iterations; i++ ) {
57-
y = mode( k[ i % len ] );
55+
y = mode( k[ i % k.length ] );
5856
if ( isnan( y ) ) {
5957
b.fail( 'should not return NaN' );
6058
}

lib/node_modules/@stdlib/stats/base/dists/chi/mode/test/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ tape( 'main export is a function', function test( t ) {
4141

4242
tape( 'if provided `NaN` for `k`, the function returns `NaN`', function test( t ) {
4343
var v = mode( NaN );
44-
t.equal( isnan( v ), true, 'returns NaN' );
44+
t.equal( isnan( v ), true, 'returns expected value' );
4545
t.end();
4646
});
4747

4848
tape( 'if provided a degrees of freedom parameter `k` that is smaller than one, the function returns `NaN`', function test( t ) {
4949
var v;
5050

5151
v = mode( 0.8 );
52-
t.equal( isnan( v ), true, 'returns NaN' );
52+
t.equal( isnan( v ), true, 'returns expected value' );
5353

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

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

6060
v = mode( NINF );
61-
t.equal( isnan( v ), true, 'returns NaN' );
61+
t.equal( isnan( v ), true, 'returns expected value' );
6262

6363
t.end();
6464
});

lib/node_modules/@stdlib/stats/base/dists/chi/mode/test/test.native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ tape( 'main export is a function', opts, function test( t ) {
5050

5151
tape( 'if provided `NaN` for `k`, the function returns `NaN`', opts, function test( t ) {
5252
var v = mode( NaN );
53-
t.equal( isnan( v ), true, 'returns NaN' );
53+
t.equal( isnan( v ), true, 'returns expected value' );
5454
t.end();
5555
});
5656

5757
tape( 'if provided a degrees of freedom parameter `k` that is smaller than one, the function returns `NaN`', opts, function test( t ) {
5858
var v;
5959

6060
v = mode( 0.8 );
61-
t.equal( isnan( v ), true, 'returns NaN' );
61+
t.equal( isnan( v ), true, 'returns expected value' );
6262

6363
v = mode( 0.0 );
64-
t.equal( isnan( v ), true, 'returns NaN' );
64+
t.equal( isnan( v ), true, 'returns expected value' );
6565

6666
v = mode( -1.0 );
67-
t.equal( isnan( v ), true, 'returns NaN' );
67+
t.equal( isnan( v ), true, 'returns expected value' );
6868

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

7272
t.end();
7373
});

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var Float64Array = require( '@stdlib/array/float64' );
25-
var uniform = require( '@stdlib/random/base/uniform' );
26-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pkg = require( './../package.json' ).name;
2928
var pdf = require( './../lib' );
@@ -32,23 +31,21 @@ var pdf = require( './../lib' );
3231
// MAIN //
3332

3433
bench( pkg, function benchmark( b ) {
35-
var len;
34+
var opts;
3635
var k;
3736
var x;
3837
var y;
3938
var i;
4039

41-
len = 100;
42-
x = new Float64Array( len );
43-
k = new Float64Array( len );
44-
for ( i = 0; i < len; i++ ) {
45-
x[ i ] = uniform( 0.0, 100.0 );
46-
k[ i ] = discreteUniform( 1, 100 );
47-
}
40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
x = uniform( 100, 0.0, 100.0, opts );
44+
k = discreteUniform( 100, 1, 100, opts );
4845

4946
b.tic();
5047
for ( i = 0; i < b.iterations; i++ ) {
51-
y = pdf( x[ i % len ], k[ i % len ] );
48+
y = pdf( x[ i % x.length ], k[ i % k.length ] );
5249
if ( isnan( y ) ) {
5350
b.fail( 'should not return NaN' );
5451
}
@@ -63,23 +60,23 @@ bench( pkg, function benchmark( b ) {
6360

6461
bench( pkg+':factory', function benchmark( b ) {
6562
var mypdf;
66-
var len;
63+
var opts;
6764
var k;
6865
var x;
6966
var y;
7067
var i;
7168

69+
opts = {
70+
'dtype': 'float64'
71+
};
72+
x = uniform( 100, 0.0, 100.0, opts );
73+
7274
k = 10.0;
7375
mypdf = pdf.factory( k );
74-
len = 100;
75-
x = new Float64Array( len );
76-
for ( i = 0; i < len; i++ ) {
77-
x[ i ] = uniform( 0.0, 100.0 );
78-
}
7976

8077
b.tic();
8178
for ( i = 0; i < b.iterations; i++ ) {
82-
y = mypdf( x[ i % len ] );
79+
y = mypdf( x[ i % x.length ] );
8380
if ( isnan( y ) ) {
8481
b.fail( 'should not return NaN' );
8582
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
5555

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

6060
pdf = factory( NaN );
6161
y = pdf( 0.0 );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
6363

6464
t.end();
6565
});
@@ -70,7 +70,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `
7070

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

7575
t.end();
7676
});
@@ -81,7 +81,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `
8181

8282
pdf = factory( 1.0 );
8383
y = pdf( NINF );
84-
t.equal( y, 0.0, 'returns 0' );
84+
t.equal( y, 0.0, 'returns expected value' );
8585

8686
t.end();
8787
});
@@ -93,10 +93,10 @@ tape( 'if provided a negative `k`, the created function always returns `NaN`', f
9393
pdf = factory( -1.0 );
9494

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

9898
y = pdf( 0.0 );
99-
t.equal( isnan( y ), true, 'returns NaN' );
99+
t.equal( isnan( y ), true, 'returns expected value' );
100100

101101
t.end();
102102
});
@@ -108,22 +108,22 @@ tape( 'if `k` equals `0`, the created function evaluates a degenerate distributi
108108
pdf = factory( 0.0 );
109109

110110
y = pdf( -2.0 );
111-
t.equal( y, 0.0, 'returns 0' );
111+
t.equal( y, 0.0, 'returns expected value' );
112112

113113
y = pdf( 0.0 );
114-
t.equal( y, PINF, 'returns +infinity for x equal to 0' );
114+
t.equal( y, PINF, 'returns expected value' );
115115

116116
y = pdf( 1.0 );
117-
t.equal( y, 0.0, 'returns 0' );
117+
t.equal( y, 0.0, 'returns expected value' );
118118

119119
y = pdf( PINF );
120-
t.equal( y, 0.0, 'returns 0' );
120+
t.equal( y, 0.0, 'returns expected value' );
121121

122122
y = pdf( NINF );
123-
t.equal( y, 0.0, 'returns 0' );
123+
t.equal( y, 0.0, 'returns expected value' );
124124

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

128128
t.end();
129129
});
@@ -138,7 +138,7 @@ tape( 'the returned function returns `0` for all `x < 0`', function test( t ) {
138138
for ( i = 0; i < 100; i++ ) {
139139
x = -( randu()*100.0 ) - EPS;
140140
y = pdf( x );
141-
t.equal( y, 0.0, 'returns 0 for x='+x );
141+
t.equal( y, 0.0, 'returns expected value' );
142142
}
143143
t.end();
144144
});

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ tape( 'main export is a function', function test( t ) {
4545

4646
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4747
var y = pdf( NaN, 1.0 );
48-
t.equal( isnan( y ), true, 'returns NaN' );
48+
t.equal( isnan( y ), true, 'returns expected value' );
4949
y = pdf( 0.0, NaN );
50-
t.equal( isnan( y ), true, 'returns NaN' );
50+
t.equal( isnan( y ), true, 'returns expected value' );
5151
t.end();
5252
});
5353

5454
tape( 'if provided `+infinity` for `x` and a finite `k`, the function returns `0`', function test( t ) {
5555
var y = pdf( PINF, 1.0 );
56-
t.equal( y, 0.0, 'returns 0' );
56+
t.equal( y, 0.0, 'returns expected value' );
5757
t.end();
5858
});
5959

6060
tape( 'if provided `-infinity` for `x` and a finite `k`, the function returns `0`', function test( t ) {
6161
var y = pdf( NINF, 1.0 );
62-
t.equal( y, 0.0, 'returns 0' );
62+
t.equal( y, 0.0, 'returns expected value' );
6363
t.end();
6464
});
6565

6666
tape( 'if provided a negative `k`, the function always returns `NaN`', function test( t ) {
6767
var y;
6868

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

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

7575
y = pdf( 2.0, NINF );
76-
t.equal( isnan( y ), true, 'returns NaN' );
76+
t.equal( isnan( y ), true, 'returns expected value' );
7777

7878
t.end();
7979
});
@@ -85,19 +85,19 @@ tape( 'if `k` equals `0`, the function evaluates a degenerate distribution cente
8585
t.equal( y, PINF, 'returns +infinity for x equal to 0' );
8686

8787
y = pdf( 1.0, 0.0 );
88-
t.equal( y, 0.0, 'returns 0' );
88+
t.equal( y, 0.0, 'returns expected value' );
8989

9090
y = pdf( -1.5, 0.0 );
91-
t.equal( y, 0.0, 'returns 0' );
91+
t.equal( y, 0.0, 'returns expected value' );
9292

9393
y = pdf( PINF, 0.0 );
94-
t.equal( y, 0.0, 'returns 0' );
94+
t.equal( y, 0.0, 'returns expected value' );
9595

9696
y = pdf( NINF, 0.0 );
97-
t.equal( y, 0.0, 'returns 0' );
97+
t.equal( y, 0.0, 'returns expected value' );
9898

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

102102
t.end();
103103
});
@@ -110,7 +110,7 @@ tape( 'the function returns `0` for all `x < 0`', function test( t ) {
110110
for ( i = 0; i < 100; i++ ) {
111111
x = -( randu()*100.0 ) - EPS;
112112
y = pdf( x, 1.0 );
113-
t.equal( y, 0.0, 'returns 0 for x='+x );
113+
t.equal( y, 0.0, 'returns expected value' );
114114
}
115115
t.end();
116116
});

0 commit comments

Comments
 (0)