Skip to content

bench: update random value generation #6812

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

Merged
merged 1 commit into from
Apr 26, 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 @@ -21,8 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var uniform = require( '@stdlib/random/array/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 @@ -34,21 +33,19 @@ var median = require( './../lib' );
bench( pkg, function benchmark( b ) {
var alpha;
var beta;
var len;
var opts;
var y;
var i;

len = 100;
alpha = new Float64Array( len );
beta = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
alpha[ i ] = uniform( EPS, 10.0 );
beta[ i ] = uniform( EPS, 10.0 );
}
opts = {
'dtype': 'float64'
};
alpha = uniform( 100, EPS, 10.0, opts );
beta = uniform( 100, EPS, 10.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = median( alpha[ i % len ], beta[ i % len ] );
y = median( alpha[ i % alpha.length ], beta[ i % beta.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
24 changes: 12 additions & 12 deletions lib/node_modules/@stdlib/stats/base/dists/beta/median/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ tape( 'main export is a function', function test( t ) {

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
var v = median( NaN, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = median( 10.0, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -56,19 +56,19 @@ tape( 'if provided `alpha <= 0`, the function returns `NaN`', function test( t )
var y;

y = median( -1.0, 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NINF, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NINF, PINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NINF, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -77,19 +77,19 @@ tape( 'if provided `beta <= 0`, the function returns `NaN`', function test( t )
var y;

y = median( 2.0, -1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( 1.0, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( PINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = median( NaN, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var uniform = require( '@stdlib/random/array/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 @@ -34,24 +33,21 @@
bench( pkg, function benchmark( b ) {
var alpha;
var beta;
var len;
var opts;
var t;
var y;
var i;

len = 100;
t = new Float64Array( len );
alpha = new Float64Array( len );
beta = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
t[ i ] = uniform( 0.0, 20.0 );
alpha[ i ] = uniform( EPS, 100.0 );
beta[ i ] = uniform( EPS, 100.0 );
}
opts = {
'dtype': 'float64'
};
alpha = uniform( 100, EPS, 100.0, opts );
beta = uniform( 100, EPS, 100.0, opts );
t = uniform( 100, 0.0, 20.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = mgf( t[ i % len ], alpha[ i % len ], beta[ i % len ] );
y = mgf( t[ i % t.length ], alpha[ i % alpha.length ], beta[ i % beta.length ] );

Check warning on line 50 in lib/node_modules/@stdlib/stats/base/dists/beta/mgf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 89. Maximum allowed is 80
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -68,23 +64,23 @@
var mymgf;
var alpha;
var beta;
var len;
var opts;
var t;
var y;
var i;

opts = {
'dtype': 'float64'
};
t = uniform( 100, 0.0, 20.0, opts );

alpha = 100.56789;
beta = 55.54321;
mymgf = mgf.factory( alpha, beta );
len = 100;
t = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
t[ i ] = uniform( 0.0, 20.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = mymgf( t[ i % len ] );
y = mymgf( t[ i % t.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@

mgf = factory( 1.0, 1.0 );
y = mgf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, 1.0 );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 1.0, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NaN );
y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NaN );
y = mgf( NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -77,31 +77,31 @@
mgf = factory( 1.0, 0.0 );

y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 1.0, -1.0 );

y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( 1.0, NINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( PINF, NINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, NINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NaN, NINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -113,31 +113,31 @@
mgf = factory( 0.0, 0.5 );

y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( -1.0, 0.5 );

y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, 1.0 );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, PINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, NINF );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

mgf = factory( NINF, NaN );
y = mgf( 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -148,12 +148,12 @@
var x;
var y;

// TODO: Add test fixtures (function is not available in R and Julia)

Check warning on line 151 in lib/node_modules/@stdlib/stats/base/dists/beta/mgf/test/test.factory.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: Add test fixtures (function is not...'
mgf = factory( 2.0, 2.0 );
for ( i = 0; i < 100; i++ ) {
x = randu();
y = mgf( x );
t.strictEqual( !isnan( y ) && isNumber( y ), true, 'returns a number' );
t.strictEqual( !isnan( y ) && isNumber( y ), true, 'returns expected value' );
}
t.end();
});
34 changes: 17 additions & 17 deletions lib/node_modules/@stdlib/stats/base/dists/beta/mgf/test/test.mgf.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
var y = mgf( NaN, 0.0, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = mgf( 0.0, NaN, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = mgf( 0.0, 1.0, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
t.end();
});

tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function test( t ) {
var y;

y = mgf( 2.0, 0.0, 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, -1.0, 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0, -1.0, 2.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NINF, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NINF, PINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NINF, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -79,25 +79,25 @@
var y;

y = mgf( 2.0, 2.0, 0.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, 2.0, -1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 0.0, 2.0, -1/0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, 1.0, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, PINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NINF, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

y = mgf( 2.0, NaN, NINF );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );

t.end();
});
Expand All @@ -109,7 +109,7 @@
var x;
var y;

// TODO: Add test fixtures (function is not available in R and Julia)

Check warning on line 112 in lib/node_modules/@stdlib/stats/base/dists/beta/mgf/test/test.mgf.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: Add test fixtures (function is not...'
for ( i = 0; i < 100; i++ ) {
x = randu();
alpha = ( randu()*20.0 ) + EPS;
Expand Down
Loading