Skip to content

Commit 2f1bc9e

Browse files
authored
bench: update random value generation
PR-URL: #7093 Reviewed-by: Athan Reines <[email protected]>
1 parent 2ad245f commit 2f1bc9e

28 files changed

+433
-478
lines changed

lib/node_modules/@stdlib/stats/base/dists/cosine/cdf/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;
@@ -32,26 +31,23 @@ var cdf = require( './../lib' );
3231
// MAIN //
3332

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

42-
len = 100;
43-
x = new Float64Array( len );
44-
mu = new Float64Array( len );
45-
s = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
x[ i ] = uniform( -50.0, 50.0 );
48-
mu[ i ] = uniform( -10.0, 10.0 );
49-
s[ i ] = uniform( EPS, 5.0 );
50-
}
41+
opts = {
42+
'dtype': 'float64'
43+
};
44+
x = uniform( 100, -50.0, 50.0, opts );
45+
mu = uniform( 100, -10.0, 10.0, opts );
46+
s = uniform( 100, EPS, 5.0, opts );
5147

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = cdf( x[ i % len ], mu[ i % len ], s[ i % len ] );
50+
y = cdf( x[ i % x.length ], mu[ i % mu.length ], s[ i % s.length ] );
5551
if ( isnan( y ) ) {
5652
b.fail( 'should not return NaN' );
5753
}
@@ -66,25 +62,25 @@ bench( pkg, function benchmark( b ) {
6662

6763
bench( pkg+':factory', function benchmark( b ) {
6864
var mycdf;
69-
var len;
65+
var opts;
7066
var mu;
7167
var s;
7268
var x;
7369
var y;
7470
var i;
7571

72+
opts = {
73+
'dtype': 'float64'
74+
};
75+
x = uniform( 100, 0.0, 50.0, opts );
76+
7677
mu = 10.0;
7778
s = 4.0;
7879
mycdf = cdf.factory( mu, s );
79-
len = 100;
80-
x = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
x[ i ] = uniform( 0.0, 50.0 );
83-
}
8480

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

lib/node_modules/@stdlib/stats/base/dists/cosine/cdf/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 Float64Array = require( '@stdlib/array/float64' );
26-
var uniform = require( '@stdlib/random/base/uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2726
var EPS = require( '@stdlib/constants/float64/eps' );
2827
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -41,26 +40,23 @@ var opts = {
4140
// MAIN //
4241

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

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

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

lib/node_modules/@stdlib/stats/base/dists/cosine/cdf/test/test.cdf.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,46 @@ 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 = cdf( NaN, 0.0, 1.0 );
49-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
5050
y = cdf( 0.0, NaN, 1.0 );
51-
t.equal( isnan( y ), true, 'returns NaN' );
51+
t.equal( isnan( y ), true, 'returns expected value' );
5252
y = cdf( 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 `+infinity` for `x` and a finite `mu` and `s`, the function returns `1`', function test( t ) {
5858
var y = cdf( PINF, 0.0, 1.0 );
59-
t.equal( y, 1.0, 'returns 1' );
59+
t.equal( y, 1.0, 'returns expected value' );
6060
t.end();
6161
});
6262

6363
tape( 'if provided `-infinity` for `x` and a finite `mu` and `s`, the function returns `0`', function test( t ) {
6464
var y = cdf( NINF, 0.0, 1.0 );
65-
t.equal( y, 0.0, 'returns 0' );
65+
t.equal( y, 0.0, 'returns expected value' );
6666
t.end();
6767
});
6868

6969
tape( 'if provided a negative `s`, the function returns `NaN`', function test( t ) {
7070
var y;
7171

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

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

7878
y = cdf( 2.0, 1.0, NINF );
79-
t.equal( isnan( y ), true, 'returns NaN' );
79+
t.equal( isnan( y ), true, 'returns expected value' );
8080

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

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

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

9090
t.end();
9191
});
@@ -94,13 +94,13 @@ tape( 'if provided `s` equals `0`, the function evaluates a degenerate distribut
9494
var y;
9595

9696
y = cdf( 2.0, 2.0, 0.0 );
97-
t.equal( y, 1.0, 'returns 1 for x equal to mu' );
97+
t.equal( y, 1.0, 'returns expected value' );
9898

9999
y = cdf( 3.0, 2.0, 0.0 );
100-
t.equal( y, 1.0, 'returns 1 for x greater than mu' );
100+
t.equal( y, 1.0, 'returns expected value' );
101101

102102
y = cdf( 1.0, 2.0, 0.0 );
103-
t.equal( y, 0.0, 'returns 0 for x smaller than mu' );
103+
t.equal( y, 0.0, 'returns expected value' );
104104

105105
t.end();
106106
});

lib/node_modules/@stdlib/stats/base/dists/cosine/cdf/test/test.factory.js

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

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

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

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

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

7777
t.end();
7878
});
@@ -83,7 +83,7 @@ tape( 'if provided a valid `mu` and `s`, the function returns a function which r
8383

8484
cdf = factory( 0.0, 1.0 );
8585
y = cdf( PINF );
86-
t.equal( y, 1.0, 'returns 1' );
86+
t.equal( y, 1.0, 'returns expected value' );
8787

8888
t.end();
8989
});
@@ -94,7 +94,7 @@ tape( 'if provided a valid `mu` and `s`, the function returns a function which r
9494

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

9999
t.end();
100100
});
@@ -106,26 +106,26 @@ tape( 'if provided a negative `s`, the created function always returns `NaN`', f
106106
cdf = factory( 0.0, -1.0 );
107107

108108
y = cdf( 2.0 );
109-
t.equal( isnan( y ), true, 'returns NaN' );
109+
t.equal( isnan( y ), true, 'returns expected value' );
110110

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

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

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

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

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

130130
t.end();
131131
});
@@ -137,13 +137,13 @@ tape( 'if `s` equals `0`, the created function evaluates a degenerate distributi
137137
cdf = factory( 2.0, 0.0 );
138138

139139
y = cdf( 2.0, 2.0, 0.0 );
140-
t.equal( y, 1.0, 'returns 1 for x equal to mu' );
140+
t.equal( y, 1.0, 'returns expected value' );
141141

142142
y = cdf( 3.0, 2.0, 0.0 );
143-
t.equal( y, 1.0, 'returns 1 for x greater than mu' );
143+
t.equal( y, 1.0, 'returns expected value' );
144144

145145
y = cdf( 1.0, 2.0, 0.0 );
146-
t.equal( y, 0.0, 'returns 0 for x smaller than mu' );
146+
t.equal( y, 0.0, 'returns expected value' );
147147

148148
t.end();
149149
});

lib/node_modules/@stdlib/stats/base/dists/cosine/cdf/test/test.native.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,46 @@ 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 = cdf( NaN, 0.0, 1.0 );
58-
t.equal( isnan( y ), true, 'returns NaN' );
58+
t.equal( isnan( y ), true, 'returns expected value' );
5959
y = cdf( 0.0, NaN, 1.0 );
60-
t.equal( isnan( y ), true, 'returns NaN' );
60+
t.equal( isnan( y ), true, 'returns expected value' );
6161
y = cdf( 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 `+infinity` for `x` and a finite `mu` and `s`, the function returns `1`', opts, function test( t ) {
6767
var y = cdf( PINF, 0.0, 1.0 );
68-
t.equal( y, 1.0, 'returns 1' );
68+
t.equal( y, 1.0, 'returns expected value' );
6969
t.end();
7070
});
7171

7272
tape( 'if provided `-infinity` for `x` and a finite `mu` and `s`, the function returns `0`', opts, function test( t ) {
7373
var y = cdf( NINF, 0.0, 1.0 );
74-
t.equal( y, 0.0, 'returns 0' );
74+
t.equal( y, 0.0, 'returns expected value' );
7575
t.end();
7676
});
7777

7878
tape( 'if provided a negative `s`, the function returns `NaN`', opts, function test( t ) {
7979
var y;
8080

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

8484
y = cdf( 0.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 = cdf( 2.0, 1.0, NINF );
88-
t.equal( isnan( y ), true, 'returns NaN' );
88+
t.equal( isnan( y ), true, 'returns expected value' );
8989

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

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

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

9999
t.end();
100100
});
@@ -103,13 +103,13 @@ tape( 'if provided `s` equals `0`, the function evaluates a degenerate distribut
103103
var y;
104104

105105
y = cdf( 2.0, 2.0, 0.0 );
106-
t.equal( y, 1.0, 'returns 1 for x equal to mu' );
106+
t.equal( y, 1.0, 'returns expected value' );
107107

108108
y = cdf( 3.0, 2.0, 0.0 );
109-
t.equal( y, 1.0, 'returns 1 for x greater than mu' );
109+
t.equal( y, 1.0, 'returns expected value' );
110110

111111
y = cdf( 1.0, 2.0, 0.0 );
112-
t.equal( y, 0.0, 'returns 0 for x smaller than mu' );
112+
t.equal( y, 0.0, 'returns expected value' );
113113

114114
t.end();
115115
});

0 commit comments

Comments
 (0)