Skip to content

Commit f025bc3

Browse files
authored
bench: update random value generation
PR-URL: #6954 Reviewed-by: Athan Reines <[email protected]>
1 parent aa768fa commit f025bc3

File tree

21 files changed

+248
-280
lines changed

21 files changed

+248
-280
lines changed

lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/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;
@@ -33,25 +32,22 @@ var logpdf = require( './../lib' );
3332

3433
bench( pkg, function benchmark( b ) {
3534
var gamma;
36-
var len;
35+
var opts;
3736
var x0;
3837
var x;
3938
var y;
4039
var i;
4140

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

5248
b.tic();
5349
for ( i = 0; i < b.iterations; i++ ) {
54-
y = logpdf( x[ i % len ], x0[ i % len ], gamma[ i % len ] );
50+
y = logpdf( x[ i % x.length ], x0[ i % x0.length ], gamma[ i % gamma.length ] );
5551
if ( isnan( y ) ) {
5652
b.fail( 'should not return NaN' );
5753
}
@@ -67,24 +63,24 @@ bench( pkg, function benchmark( b ) {
6763
bench( pkg+':factory', function benchmark( b ) {
6864
var mylogpdf;
6965
var gamma;
70-
var len;
66+
var opts;
7167
var x0;
7268
var x;
7369
var y;
7470
var i;
7571

72+
opts = {
73+
'dtype': 'float64'
74+
};
75+
x = uniform( 100, EPS, 100.0, opts );
76+
7677
x0 = 0.0;
7778
gamma = 1.5;
7879
mylogpdf = logpdf.factory( x0, gamma );
79-
len = 100;
80-
x = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
x[ i ] = uniform( EPS, 100.0 );
83-
}
8480

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

lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/benchmark/benchmark.native.js

Lines changed: 9 additions & 13 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;
@@ -42,25 +41,22 @@ var opts = {
4241

4342
bench( pkg+'::native', opts, function benchmark( b ) {
4443
var gamma;
45-
var len;
44+
var opts;
4645
var x0;
4746
var x;
4847
var y;
4948
var i;
5049

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

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

lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/test/test.factory.js

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

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

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

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

7373
logpdf = factory( NaN, NaN );
7474
y = logpdf( 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 `x0` and `gamma`, the function returns a function whi
8383

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

8888
t.end();
8989
});
@@ -94,7 +94,7 @@ tape( 'if provided a valid `x0` and `gamma`, the function returns a function whi
9494

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

9999
t.end();
100100
});
@@ -105,33 +105,33 @@ tape( 'if provided a nonpositive `gamma`, the created function always returns `N
105105

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

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

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

117117
y = logpdf( 0.0 );
118-
t.equal( isnan( y ), true, 'returns NaN' );
118+
t.equal( isnan( y ), true, 'returns expected value' );
119119

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

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

128128
logpdf = factory( NINF, NINF );
129129
y = logpdf( 2.0 );
130-
t.equal( isnan( y ), true, 'returns NaN' );
130+
t.equal( isnan( y ), true, 'returns expected value' );
131131

132132
logpdf = factory( NaN, NINF );
133133
y = logpdf( 2.0 );
134-
t.equal( isnan( y ), true, 'returns NaN' );
134+
t.equal( isnan( y ), true, 'returns expected value' );
135135

136136
t.end();
137137
});

lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/test/test.logpdf.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,64 +48,64 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', functio
4848
var y;
4949

5050
y = logpdf( NaN, 0.0, 1.0 );
51-
t.equal( isnan( y ), true, 'returns NaN' );
51+
t.equal( isnan( y ), true, 'returns expected value' );
5252

5353
y = logpdf( 0.0, NaN, 1.0 );
54-
t.equal( isnan( y ), true, 'returns NaN' );
54+
t.equal( isnan( y ), true, 'returns expected value' );
5555

5656
y = logpdf( 0.0, 1.0, NaN );
57-
t.equal( isnan( y ), true, 'returns NaN' );
57+
t.equal( isnan( y ), true, 'returns expected value' );
5858

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

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

6565
y = logpdf( NaN, NaN, 1.0 );
66-
t.equal( isnan( y ), true, 'returns NaN' );
66+
t.equal( isnan( y ), true, 'returns expected value' );
6767

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

7171
t.end();
7272
});
7373

7474
tape( 'if provided `+infinity` for `x` and a finite `x0` and `gamma`, the function returns `-Infinity`', function test( t ) {
7575
var y = logpdf( PINF, 0.0, 1.0 );
76-
t.equal( y, NINF, 'returns -Infinity' );
76+
t.equal( y, NINF, 'returns expected value' );
7777
t.end();
7878
});
7979

8080
tape( 'if provided `-infinity` for `x` and a finite `x0` and `gamma`, the function returns `-Infinity`', function test( t ) {
8181
var y = logpdf( NINF, 0.0, 1.0 );
82-
t.equal( y, NINF, 'returns -Infinity' );
82+
t.equal( y, NINF, 'returns expected value' );
8383
t.end();
8484
});
8585

8686
tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', function test( t ) {
8787
var y;
8888

8989
y = logpdf( 2.0, 0.0, 0.0 );
90-
t.equal( isnan( y ), true, 'returns NaN' );
90+
t.equal( isnan( y ), true, 'returns expected value' );
9191

9292
y = logpdf( 2.0, 0.0, -1.0 );
93-
t.equal( isnan( y ), true, 'returns NaN' );
93+
t.equal( isnan( y ), true, 'returns expected value' );
9494

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

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

101101
y = logpdf( 2.0, PINF, NINF );
102-
t.equal( isnan( y ), true, 'returns NaN' );
102+
t.equal( isnan( y ), true, 'returns expected value' );
103103

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

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

110110
t.end();
111111
});

lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/test/test.native.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,64 +57,64 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
5757
var y;
5858

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

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

6565
y = logpdf( 0.0, 1.0, NaN );
66-
t.equal( isnan( y ), true, 'returns NaN' );
66+
t.equal( isnan( y ), true, 'returns expected value' );
6767

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

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

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

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

8080
t.end();
8181
});
8282

8383
tape( 'if provided `+infinity` for `x` and a finite `x0` and `gamma`, the function returns `-Infinity`', opts, function test( t ) {
8484
var y = logpdf( PINF, 0.0, 1.0 );
85-
t.equal( y, NINF, 'returns -Infinity' );
85+
t.equal( y, NINF, 'returns expected value' );
8686
t.end();
8787
});
8888

8989
tape( 'if provided `-infinity` for `x` and a finite `x0` and `gamma`, the function returns `-Infinity`', opts, function test( t ) {
9090
var y = logpdf( NINF, 0.0, 1.0 );
91-
t.equal( y, NINF, 'returns -Infinity' );
91+
t.equal( y, NINF, 'returns expected value' );
9292
t.end();
9393
});
9494

9595
tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', opts, function test( t ) {
9696
var y;
9797

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

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

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

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

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

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

116116
y = logpdf( 2.0, NaN, NINF );
117-
t.equal( isnan( y ), true, 'returns NaN' );
117+
t.equal( isnan( y ), true, 'returns expected value' );
118118

119119
t.end();
120120
});

0 commit comments

Comments
 (0)