Skip to content

Commit e23cfe3

Browse files
committed
bench: refactor random number generation in stats/base/dists/negative-binomial
1 parent fafb4ff commit e23cfe3

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/cdf/benchmark/benchmark.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bench( pkg, function benchmark( b ) {
4747
for ( i = 0; i < len; i++ ) {
4848
x[ i ] = uniform( 0.0, 100.0 );
4949
r[ i ] = discreteUniform( 1, 100 );
50-
p[ i ] = uniform( EPS, 1.0);
50+
p[ i ] = uniform( EPS, 1.0 );
5151
}
5252

5353
b.tic();
@@ -96,4 +96,4 @@ bench( pkg+':factory', function benchmark( b ) {
9696
}
9797
b.pass( 'benchmark finished' );
9898
b.end();
99-
});
99+
});

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/ctor/benchmark/benchmark.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ bench( pkg+':kurtosis', function benchmark( b ) {
193193
len = 100;
194194
x = new Float64Array( len );
195195
for ( i = 0; i < len; i++ ) {
196-
x[ i ] = discreteUniform( 1.0, 100.0 );
196+
x[ i ] = discreteUniform( 1, 100 );
197197
}
198198

199199
b.tic();
@@ -227,7 +227,7 @@ bench( pkg+':mean', function benchmark( b ) {
227227
len = 100;
228228
x = new Float64Array( len );
229229
for ( i = 0; i < len; i++ ) {
230-
x[ i ] = discreteUniform( 1.0, 100.0 );
230+
x[ i ] = discreteUniform( 1, 100 );
231231
}
232232

233233
b.tic();
@@ -261,7 +261,7 @@ bench( pkg+':mode', function benchmark( b ) {
261261
len = 100;
262262
x = new Float64Array( len );
263263
for ( i = 0; i < len; i++ ) {
264-
x[ i ] = discreteUniform( 1.0, 100.0 );
264+
x[ i ] = discreteUniform( 1, 100 );
265265
}
266266

267267
b.tic();
@@ -295,12 +295,12 @@ bench( pkg+':skewness', function benchmark( b ) {
295295
len = 100;
296296
x = new Float64Array( len );
297297
for ( i = 0; i < len; i++ ) {
298-
x[ i ] = discreteUniform( 1.0, 100.0 );
298+
x[ i ] = discreteUniform( 1, 100 );
299299
}
300300

301301
b.tic();
302302
for ( i = 0; i < b.iterations; i++ ) {
303-
dist.r = x[i % len];
303+
dist.r = x[ i % len ];
304304
y = dist.skewness;
305305
if ( isnan( y ) ) {
306306
b.fail( 'should not return NaN' );
@@ -329,12 +329,12 @@ bench( pkg+':stdev', function benchmark( b ) {
329329
len = 100;
330330
x = new Float64Array( len );
331331
for ( i = 0; i < len; i++ ) {
332-
x[ i ] = discreteUniform( 1.0, 100.0 );
332+
x[ i ] = discreteUniform( 1, 100 );
333333
}
334334

335335
b.tic();
336336
for ( i = 0; i < b.iterations; i++ ) {
337-
dist.r = x[i % len];
337+
dist.r = x[ i % len ];
338338
y = dist.stdev;
339339
if ( isnan( y ) ) {
340340
b.fail( 'should not return NaN' );
@@ -363,12 +363,12 @@ bench( pkg+':variance', function benchmark( b ) {
363363
len = 100;
364364
x = new Float64Array( len );
365365
for ( i = 0; i < len; i++ ) {
366-
x[ i ] = discreteUniform( 1.0, 100.0 );
366+
x[ i ] = discreteUniform( 1, 100 );
367367
}
368368

369369
b.tic();
370370
for ( i = 0; i < b.iterations; i++ ) {
371-
dist.r = x[ i % len];
371+
dist.r = x[ i % len ];
372372
y = dist.variance;
373373
if ( isnan( y ) ) {
374374
b.fail( 'should not return NaN' );
@@ -402,7 +402,7 @@ bench( pkg+':cdf', function benchmark( b ) {
402402

403403
b.tic();
404404
for ( i = 0; i < b.iterations; i++ ) {
405-
y = dist.cdf( x[i % len] );
405+
y = dist.cdf( x[ i % len ] );
406406
if ( isnan( y ) ) {
407407
b.fail( 'should not return NaN' );
408408
}
@@ -430,12 +430,12 @@ bench( pkg+':logpmf', function benchmark( b ) {
430430
len = 100;
431431
x = new Float64Array( len );
432432
for ( i = 0; i < len; i++ ) {
433-
x[ i ] = discreteUniform( 0.0, r );
433+
x[ i ] = discreteUniform( 0, r );
434434
}
435435

436436
b.tic();
437437
for ( i = 0; i < b.iterations; i++ ) {
438-
y = dist.logpmf( x[i % len] );
438+
y = dist.logpmf( x[ i % len ] );
439439
if ( isnan( y ) ) {
440440
b.fail( 'should not return NaN' );
441441
}
@@ -463,12 +463,12 @@ bench( pkg+':pmf', function benchmark( b ) {
463463
len = 100;
464464
x = new Float64Array( len );
465465
for ( i = 0; i < len; i++ ) {
466-
x[ i ] = discreteUniform( 0.0, r );
466+
x[ i ] = discreteUniform( 0, r );
467467
}
468468

469469
b.tic();
470470
for ( i = 0; i < b.iterations; i++ ) {
471-
y = dist.pmf( x[i % len] );
471+
y = dist.pmf( x[ i % len ] );
472472
if ( isnan( y ) ) {
473473
b.fail( 'should not return NaN' );
474474
}
@@ -501,7 +501,7 @@ bench( pkg+':quantile', function benchmark( b ) {
501501

502502
b.tic();
503503
for ( i = 0; i < b.iterations; i++ ) {
504-
y = dist.quantile( x[i % len] );
504+
y = dist.quantile( x[ i % len ] );
505505
if ( isnan( y ) ) {
506506
b.fail( 'should not return NaN' );
507507
}

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/logpmf/benchmark/benchmark.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bench( pkg+':factory', function benchmark( b ) {
8080
len = 100;
8181
x = new Float64Array( len );
8282
for ( i = 0; i < len; i++ ) {
83-
x[ i ] = uniform( 0, 80 );
83+
x[ i ] = uniform( 0.0, 80.0 );
8484
}
8585

8686
b.tic();
@@ -96,4 +96,4 @@ bench( pkg+':factory', function benchmark( b ) {
9696
}
9797
b.pass( 'benchmark finished' );
9898
b.end();
99-
});
99+
});

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/mgf/benchmark/benchmark.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ bench( pkg, function benchmark( b ) {
4848

4949
for ( i = 0; i < len; i++ ) {
5050
p[ i ] = uniform( EPS, 1.0 );
51-
}
52-
53-
for ( i = 0; i < len; i++ ) {
5451
t[ i ] = uniform( 0.0, 1.0 ) * -ln( p[i] );
5552
r[ i ] = discreteUniform( 1, 100 );
5653
}
@@ -85,7 +82,7 @@ bench( pkg+':factory', function benchmark( b ) {
8582
len = 100;
8683
t = new Float64Array( len );
8784
for ( i = 0; i < len; i++ ) {
88-
t[i] = uniform(0.0, 1.0) * -ln(p);
85+
t[ i ] = uniform( 0.0, -ln( p ) );
8986
}
9087

9188
b.tic();

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/pmf/benchmark/benchmark.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bench( pkg, function benchmark( b ) {
5252

5353
b.tic();
5454
for ( i = 0; i < b.iterations; i++ ) {
55-
y = pmf( x[i % len], r[i % len], p[i % len] );
55+
y = pmf( x[ i % len ], r[ i % len ], p[ i % len ] );
5656
if ( isnan( y ) ) {
5757
b.fail( 'should not return NaN' );
5858
}

0 commit comments

Comments
 (0)