Skip to content

bench: update random value generation #6794

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 3 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
bench: update random value generation
  • Loading branch information
hrshya committed Apr 23, 2025
commit abcc371eda58b51ac4b9c64b6a08821f47d3c9ff
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 @@ -31,27 +30,20 @@

// MAIN //

bench( pkg, function benchmark( b ) {

Check failure on line 33 in lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Variable declarations inside of function are not ordered by length (in decreasing order)
var alpha;
var beta;
var len;
var x;
var y;
var i;

len = 100;
alpha = new Float64Array( len );
beta = new Float64Array( len );
x = 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 );
}
var opts = {
'dtype': 'float64'
};
var alpha = uniform( 100, EPS, 100.0, opts );
var beta = uniform( 100, EPS, 100.0, opts );
var x = uniform( 100, EPS, 2.0, opts )

Check failure on line 42 in lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Missing semicolon

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

Check warning on line 46 in lib/node_modules/@stdlib/stats/base/dists/beta/cdf/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 @@ -64,27 +56,26 @@
b.end();
});

bench( pkg+':factory', function benchmark( b ) {

Check failure on line 59 in lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Variable declarations inside of function are not ordered by length (in decreasing order)
var mycdf;
var alpha;
var beta;
var len;
var x;
var y;
var i;

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

Check failure on line 70 in lib/node_modules/@stdlib/stats/base/dists/beta/cdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

x is already defined

alpha = 100.56789;
beta = 55.54321;
mycdf = cdf.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 = mycdf( x[ i % len ] );
y = mycdf( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
50 changes: 25 additions & 25 deletions lib/node_modules/@stdlib/stats/base/dists/beta/cdf/test/test.cdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,42 @@ tape( 'main export is a function', function test( t ) {

tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
var y = cdf( NaN, 0.0, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = cdf( 0.0, NaN, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = cdf( 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 number greater than or equal to one for `x` and a finite `alpha` and `beta`, the function returns `1`', function test( t ) {
var y = cdf( PINF, 0.5, 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 100.0, 0.5, 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 10.0, 0.5, 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 1.0, 0.5, 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

t.end();
});

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 ) {
var y = cdf( NINF, 0.5, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

y = cdf( 2.0, 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 @@ -56,23 +56,23 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',

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

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

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

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

cdf = factory( NaN, NaN );
y = cdf( 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 finite `alpha` and `beta`, the function returns a function

cdf = factory( 0.5, 1.0 );
y = cdf( PINF );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 100.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 10.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );

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

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

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

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

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

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

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

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

cdf = factory( 1.0, -1.0 );

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

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

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

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

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

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

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

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

cdf = factory( -1.0, 0.5 );

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

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

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

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

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

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

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