Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: refactor random number generation in stats/base/dists/arcsine #4744

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/array/uniform' );
var randu = require( '@stdlib/random/base/randu' );
var uniformArray = require( '@stdlib/random/array/uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );
Expand All @@ -44,9 +44,9 @@ bench( pkg, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu() * 20.0 ) - 10.0;
min[ i ] = ( randu() * 20.0 ) - 20.0;
max[ i ] = min[ i ] + ( randu() * 40.0 );
x[ i ] = uniform( -10.0, 10.0 );
min[ i ] = uniform( -20.0, 0.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 40.0 );
}

b.tic();
Expand Down Expand Up @@ -75,7 +75,7 @@ bench( pkg+':factory', function benchmark( b ) {
min = -1.5;
max = 1.5;
mycdf = cdf.factory( min, max );
x = uniform( 100, -2.0, 2.0 );
x = uniformArray( 100, -2.0, 2.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand Down Expand Up @@ -52,9 +52,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu() * 20.0 ) - 10.0;
min[ i ] = ( randu() * 20.0 ) - 20.0;
max[ i ] = min[ i ] + ( randu() * 40.0 );
x[ i ] = uniform( -10.0, 10.0 );
min[ i ] = uniform( -20.0, 0.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 40.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
Expand All @@ -38,8 +39,8 @@ bench( pkg+'::instantiation', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
a = ( randu() * 10.0 ) + EPS;
b = ( randu() * 10.0 ) + a + EPS;
a = uniform( EPS, 10.0 );
b = uniform( a + EPS, a + 10.0 + EPS );
dist = new Arcsine( a, b );
if ( !( dist instanceof Arcsine ) ) {
bm.fail( 'should return a distribution instance' );
Expand Down Expand Up @@ -92,7 +93,7 @@ bench( pkg+'::set:a', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
y = ( 100.0*randu() ) + EPS;
y = uniform( EPS, 100.0 + EPS );
dist.a = y;
if ( dist.a !== y ) {
bm.fail( 'should return set value' );
Expand Down Expand Up @@ -145,7 +146,7 @@ bench( pkg+'::set:b', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
y = ( 100.0*randu() ) + a + EPS;
y = uniform( a + EPS, a + 100.0 + EPS );
dist.b = y;
if ( dist.b !== y ) {
bm.fail( 'should return set value' );
Expand All @@ -172,7 +173,7 @@ bench( pkg+':entropy', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.entropy;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -199,7 +200,7 @@ bench( pkg+':kurtosis', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.kurtosis;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -226,7 +227,7 @@ bench( pkg+':mean', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.mean;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -253,7 +254,7 @@ bench( pkg+':median', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.median;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -280,7 +281,7 @@ bench( pkg+':mode', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + 1.0 + EPS;
dist.a = uniform( 1.0 + EPS, 101.0 + EPS );
y = dist.mode;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -307,7 +308,7 @@ bench( pkg+':skewness', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.skewness;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -334,7 +335,7 @@ bench( pkg+':stdev', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.stdev;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand All @@ -361,7 +362,7 @@ bench( pkg+':variance', function benchmark( bm ) {

bm.tic();
for ( i = 0; i < bm.iterations; i++ ) {
dist.a = ( 100.0*randu() ) + EPS;
dist.a = uniform( EPS, 100.0 + EPS );
y = dist.variance;
if ( isnan( y ) ) {
bm.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var entropy = require( './../lib' );
Expand All @@ -41,8 +41,8 @@ bench( pkg, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = randu() * 20.0;
max[ i ] = ( randu() * 20.0 ) + min[ i ];
min[ i ] = uniform( 0.0, 20.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 20.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;

Expand All @@ -50,8 +50,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = randu() * 20.0;
max[ i ] = ( randu() * 20.0 ) + min[ i ];
min[ i ] = uniform( 0.0, 20.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 20.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var kurtosis = require( './../lib' );
Expand All @@ -41,8 +41,8 @@ bench( pkg, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = randu() * 20.0;
max[ i ] = ( randu() * 20.0 ) + min[ i ];
min[ i ] = uniform( 0.0, 20.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 20.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;

Expand All @@ -50,8 +50,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = randu() * 20.0;
max[ i ] = ( randu() * 20.0 ) + min[ i ];
min[ i ] = uniform( 0.0, 20.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 20.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var logcdf = require( './../lib' );
Expand All @@ -38,9 +38,9 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 20.0 ) - 10.0;
min = ( randu() * 20.0 ) - 20.0;
max = min + ( randu() * 40.0 );
x = uniform( -10.0, 10.0 );
min = uniform( -20.0, 0.0 );
max = uniform( min, min + 40.0 );
y = logcdf( x, min, max );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down Expand Up @@ -68,7 +68,7 @@ bench( pkg+':factory', function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*2.0 ) - 2.0;
x = uniform( -2.0, 0.0 );
y = mylogcdf( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var logpdf = require( './../lib' );
Expand All @@ -38,9 +38,9 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 20.0 ) - 10.0;
min = ( randu() * 20.0 ) - 20.0;
max = min + ( randu() * 40.0 );
x = uniform( -10.0, 10.0 );
min = uniform( -20.0, 0.0 );
max = uniform( min, min + 40.0 );
y = logpdf( x, min, max );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down Expand Up @@ -68,7 +68,7 @@ bench( pkg+':factory', function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*2.0 ) - 2.0;
x = uniform( -2.0, 0.0 );
y = mylogpdf( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand Down Expand Up @@ -52,9 +52,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu() * 20.0 ) - 10.0;
min[ i ] = ( randu() * 20.0 ) - 20.0;
max[ i ] = min[ i ] + ( randu() * 40.0 );
x[ i ] = uniform( -10.0, 10.0 );
min[ i ] = uniform( -20.0, 0.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 40.0 );
}

b.tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var mean = require( './../lib' );
Expand All @@ -37,8 +37,8 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
min = ( randu()*10.0 );
max = ( randu()*10.0 ) + min;
min = uniform( 0.0, 10.0 );
max = uniform( min, min + 10.0 );
y = mean( min, max );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var median = require( './../lib' );
Expand All @@ -37,8 +37,8 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
min = ( randu()*10.0 );
max = ( randu()*10.0 ) + min;
min = uniform( 0.0, 10.0 );
max = uniform( min, min + 10.0 );
y = median( min, max );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var mode = require( './../lib' );
Expand All @@ -37,8 +37,8 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
min = ( randu()*10.0 );
max = ( randu()*10.0 ) + min;
min = uniform( 0.0, 10.0 );
max = uniform( min, min + 10.0 );
y = mode( min, max );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Loading
Loading