Skip to content

Commit abcc371

Browse files
committed
bench: update random value generation
1 parent 7147d82 commit abcc371

File tree

8 files changed

+203
-243
lines changed

8 files changed

+203
-243
lines changed

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

Lines changed: 14 additions & 23 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,19 @@ var cdf = require( './../lib' );
3231
// MAIN //
3332

3433
bench( pkg, function benchmark( b ) {
35-
var alpha;
36-
var beta;
37-
var len;
38-
var x;
3934
var y;
4035
var i;
4136

42-
len = 100;
43-
alpha = new Float64Array( len );
44-
beta = new Float64Array( len );
45-
x = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
x[ i ] = uniform( EPS, 2.0 );
48-
alpha[ i ] = uniform( EPS, 100.0 );
49-
beta[ i ] = uniform( EPS, 100.0 );
50-
}
37+
var opts = {
38+
'dtype': 'float64'
39+
};
40+
var alpha = uniform( 100, EPS, 100.0, opts );
41+
var beta = uniform( 100, EPS, 100.0, opts );
42+
var x = uniform( 100, EPS, 2.0, opts )
5143

5244
b.tic();
5345
for ( i = 0; i < b.iterations; i++ ) {
54-
y = cdf( x[ i % len ], alpha[ i % len ], beta[ i % len ] );
46+
y = cdf( x[ i % x.length ], alpha[ i % alpha.length ], beta[ i % beta.length ] );
5547
if ( isnan( y ) ) {
5648
b.fail( 'should not return NaN' );
5749
}
@@ -68,23 +60,22 @@ bench( pkg+':factory', function benchmark( b ) {
6860
var mycdf;
6961
var alpha;
7062
var beta;
71-
var len;
7263
var x;
7364
var y;
7465
var i;
7566

67+
var opts = {
68+
'dtype': 'float64'
69+
};
70+
var x = uniform( 100, EPS, 2.0, opts );
71+
7672
alpha = 100.56789;
7773
beta = 55.54321;
7874
mycdf = cdf.factory( alpha, beta );
79-
len = 100;
80-
x = new Float64Array( len );
81-
for ( i = 0; i < len; i++ ) {
82-
x[ i ] = uniform( EPS, 2.0 );
83-
}
8475

8576
b.tic();
8677
for ( i = 0; i < b.iterations; i++ ) {
87-
y = mycdf( x[ i % len ] );
78+
y = mycdf( x[ i % x.length ] );
8879
if ( isnan( y ) ) {
8980
b.fail( 'should not return NaN' );
9081
}

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,42 @@ 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 a number greater than or equal to one for `x` and a finite `alpha` and `beta`, the function returns `1`', function test( t ) {
5858
var y = cdf( PINF, 0.5, 1.0 );
59-
t.equal( y, 1.0, 'returns 1' );
59+
t.equal( y, 1.0, 'returns expected value' );
6060

6161
y = cdf( 100.0, 0.5, 1.0 );
62-
t.equal( y, 1.0, 'returns 1' );
62+
t.equal( y, 1.0, 'returns expected value' );
6363

6464
y = cdf( 10.0, 0.5, 1.0 );
65-
t.equal( y, 1.0, 'returns 1' );
65+
t.equal( y, 1.0, 'returns expected value' );
6666

6767
y = cdf( 1.0, 0.5, 1.0 );
68-
t.equal( y, 1.0, 'returns 1' );
68+
t.equal( y, 1.0, 'returns expected value' );
6969

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

7373
tape( 'if provided a number less than or equal to zero for `x` and a finite `alpha` and `beta`, the function returns `0`', function test( t ) {
7474
var y = cdf( NINF, 0.5, 1.0 );
75-
t.equal( y, 0.0, 'returns 0' );
75+
t.equal( y, 0.0, 'returns expected value' );
7676

7777
y = cdf( -100.0, 0.5, 1.0 );
78-
t.equal( y, 0.0, 'returns 0' );
78+
t.equal( y, 0.0, 'returns expected value' );
7979

8080
y = cdf( -1.0, 0.5, 1.0 );
81-
t.equal( y, 0.0, 'returns 0' );
81+
t.equal( y, 0.0, 'returns expected value' );
8282

8383
y = cdf( 0.0, 0.5, 1.0 );
84-
t.equal( y, 0.0, 'returns 0' );
84+
t.equal( y, 0.0, 'returns expected value' );
8585

8686
t.end();
8787
});
@@ -90,25 +90,25 @@ tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function
9090
var y;
9191

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

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

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

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

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

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

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

113113
t.end();
114114
});
@@ -117,25 +117,25 @@ tape( 'if provided a nonpositive `beta`, the function returns `NaN`', function t
117117
var y;
118118

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

122122
y = cdf( 2.0, 2.0, -1.0 );
123-
t.equal( isnan( y ), true, 'returns NaN' );
123+
t.equal( isnan( y ), true, 'returns expected value' );
124124

125125
y = cdf( 0.0, 2.0, -1/0 );
126-
t.equal( isnan( y ), true, 'returns NaN' );
126+
t.equal( isnan( y ), true, 'returns expected value' );
127127

128128
y = cdf( 2.0, 1.0, NINF );
129-
t.equal( isnan( y ), true, 'returns NaN' );
129+
t.equal( isnan( y ), true, 'returns expected value' );
130130

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

134134
y = cdf( 2.0, NINF, NINF );
135-
t.equal( isnan( y ), true, 'returns NaN' );
135+
t.equal( isnan( y ), true, 'returns expected value' );
136136

137137
y = cdf( 2.0, NaN, NINF );
138-
t.equal( isnan( y ), true, 'returns NaN' );
138+
t.equal( isnan( y ), true, 'returns expected value' );
139139

140140
t.end();
141141
});

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

Lines changed: 28 additions & 28 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( 1.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,16 +83,16 @@ tape( 'if provided a finite `alpha` and `beta`, the function returns a function
8383

8484
cdf = factory( 0.5, 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
y = cdf( 100.0 );
89-
t.equal( y, 1.0, 'returns 1' );
89+
t.equal( y, 1.0, 'returns expected value' );
9090

9191
y = cdf( 10.0 );
92-
t.equal( y, 1.0, 'returns 1' );
92+
t.equal( y, 1.0, 'returns expected value' );
9393

9494
y = cdf( 1.0 );
95-
t.equal( y, 1.0, 'returns 1' );
95+
t.equal( y, 1.0, 'returns expected value' );
9696

9797
t.end();
9898
});
@@ -103,19 +103,19 @@ tape( 'if provided a finite `alpha` and `beta`, the function returns a function
103103

104104
cdf = factory( 0.5, 1.0 );
105105
y = cdf( NINF );
106-
t.equal( y, 0.0, 'returns 0' );
106+
t.equal( y, 0.0, 'returns expected value' );
107107

108108
y = cdf( -100.0 );
109-
t.equal( y, 0.0, 'returns 0' );
109+
t.equal( y, 0.0, 'returns expected value' );
110110

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

114114
y = cdf( -1.0 );
115-
t.equal( y, 0.0, 'returns 0' );
115+
t.equal( y, 0.0, 'returns expected value' );
116116

117117
y = cdf( 0.0 );
118-
t.equal( y, 0.0, 'returns 0' );
118+
t.equal( y, 0.0, 'returns expected value' );
119119

120120
t.end();
121121
});
@@ -127,31 +127,31 @@ tape( 'if provided a nonpositive `beta`, the created function always returns `Na
127127
cdf = factory( 1.0, 0.0 );
128128

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

132132
cdf = factory( 1.0, -1.0 );
133133

134134
y = cdf( 2.0 );
135-
t.equal( isnan( y ), true, 'returns NaN' );
135+
t.equal( isnan( y ), true, 'returns expected value' );
136136

137137
y = cdf( 0.0 );
138-
t.equal( isnan( y ), true, 'returns NaN' );
138+
t.equal( isnan( y ), true, 'returns expected value' );
139139

140140
cdf = factory( 1.0, NINF );
141141
y = cdf( 2.0 );
142-
t.equal( isnan( y ), true, 'returns NaN' );
142+
t.equal( isnan( y ), true, 'returns expected value' );
143143

144144
cdf = factory( PINF, NINF );
145145
y = cdf( 2.0 );
146-
t.equal( isnan( y ), true, 'returns NaN' );
146+
t.equal( isnan( y ), true, 'returns expected value' );
147147

148148
cdf = factory( NINF, NINF );
149149
y = cdf( 2.0 );
150-
t.equal( isnan( y ), true, 'returns NaN' );
150+
t.equal( isnan( y ), true, 'returns expected value' );
151151

152152
cdf = factory( NaN, NINF );
153153
y = cdf( 2.0 );
154-
t.equal( isnan( y ), true, 'returns NaN' );
154+
t.equal( isnan( y ), true, 'returns expected value' );
155155

156156
t.end();
157157
});
@@ -163,31 +163,31 @@ tape( 'if provided a nonpositive `alpha`, the created function always returns `N
163163
cdf = factory( 0.0, 0.5 );
164164

165165
y = cdf( 2.0 );
166-
t.equal( isnan( y ), true, 'returns NaN' );
166+
t.equal( isnan( y ), true, 'returns expected value' );
167167

168168
cdf = factory( -1.0, 0.5 );
169169

170170
y = cdf( 2.0 );
171-
t.equal( isnan( y ), true, 'returns NaN' );
171+
t.equal( isnan( y ), true, 'returns expected value' );
172172

173173
y = cdf( 0.0 );
174-
t.equal( isnan( y ), true, 'returns NaN' );
174+
t.equal( isnan( y ), true, 'returns expected value' );
175175

176176
cdf = factory( NINF, 1.0 );
177177
y = cdf( 2.0 );
178-
t.equal( isnan( y ), true, 'returns NaN' );
178+
t.equal( isnan( y ), true, 'returns expected value' );
179179

180180
cdf = factory( NINF, PINF );
181181
y = cdf( 2.0 );
182-
t.equal( isnan( y ), true, 'returns NaN' );
182+
t.equal( isnan( y ), true, 'returns expected value' );
183183

184184
cdf = factory( NINF, NINF );
185185
y = cdf( 2.0 );
186-
t.equal( isnan( y ), true, 'returns NaN' );
186+
t.equal( isnan( y ), true, 'returns expected value' );
187187

188188
cdf = factory( NINF, NaN );
189189
y = cdf( 2.0 );
190-
t.equal( isnan( y ), true, 'returns NaN' );
190+
t.equal( isnan( y ), true, 'returns expected value' );
191191

192192
t.end();
193193
});

0 commit comments

Comments
 (0)