Skip to content

bench: update random value generation #6842

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 29, 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 uniform = require( '@stdlib/random/base/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
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 x;
var y;
var i;

len = 100;
x = new Float64Array( len );
alpha = new Float64Array( len );
beta = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 2.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 );
x = uniform( 100, EPS, 2.0, opts );

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

Check warning on line 50 in lib/node_modules/@stdlib/stats/base/dists/betaprime/pdf/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,24 +64,23 @@
var mypdf;
var alpha;
var beta;
var len;
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, EPS, 2.0, opts );

alpha = 100.56789;
beta = 55.54321;
mypdf = pdf.factory( alpha, beta );

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 2.0 );
}

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

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/base/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var EPS = require( '@stdlib/constants/float64/eps' );
Expand All @@ -43,24 +42,21 @@
bench( pkg+'::native', opts, function benchmark( b ) {
var alpha;
var beta;
var len;
var opts;
var x;
var y;
var i;

len = 100;
x = new Float64Array( len );
alpha = new Float64Array( len );
beta = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 2.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 );
x = uniform( 100, EPS, 2.0, opts );

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

Check warning on line 59 in lib/node_modules/@stdlib/stats/base/dists/betaprime/pdf/benchmark/benchmark.native.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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',

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

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

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

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

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

t.end();
});
Expand All @@ -83,16 +83,16 @@ tape( 'if provided a valid `alpha` and `beta`, the function returns a function w

pdf = factory( 0.5, 1.0 );
y = pdf( NINF );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( -100.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( -0.5 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( 0.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

t.end();
});
Expand All @@ -104,26 +104,26 @@ tape( 'if provided `beta <= 0`, the created function always returns `NaN`', func
pdf = factory( 0.0, -1.0 );

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

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

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

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

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

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

t.end();
});
Expand All @@ -135,26 +135,26 @@ tape( 'if provided `alpha <= 0`, the created function always returns `NaN`', fun
pdf = factory( -1.0, 0.5 );

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

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

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

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

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

pdf = factory( NINF, NaN );
y = pdf( 2.0 );
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 @@ -55,28 +55,28 @@ tape( 'main export is a function', opts, function test( t ) {

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
var y = pdf( NaN, 1.0, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = pdf( 0.0, NaN, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = pdf( 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 number for `x` and a valid `alpha` and `beta`, the function returns `0`', opts, function test( t ) {
var y;

y = pdf( NINF, 1.0, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( -100.0, 1.0, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( -0.5, 1.0, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

y = pdf( 0.0, 1.0, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

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

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

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

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

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

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

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

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

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

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

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

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

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

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

t.end();
});
Expand Down
Loading