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/cosine #4861

Merged
merged 1 commit into from
Jan 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 @@ -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 EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;
Expand All @@ -44,9 +44,9 @@ bench( pkg, function benchmark( b ) {
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*100.0 ) - 50.0;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
x[ i ] = uniform( -50.0, 50.0 );
mu[ i ] = uniform( -10.0, 10.0 );
s[ i ] = uniform( EPS, 5.0 );
}

b.tic();
Expand All @@ -66,6 +66,7 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var mu;
var s;
var x;
Expand All @@ -75,11 +76,15 @@ bench( pkg+':factory', function benchmark( b ) {
mu = 10.0;
s = 4.0;
mycdf = cdf.factory( mu, s );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 50.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*50.0 );
y = mycdf( x );
y = mycdf( x[ i % len ] );
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 EPS = require( '@stdlib/constants/float64/eps' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
Expand Down Expand Up @@ -53,9 +53,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*100.0 ) - 50.0;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
x[ i ] = uniform( -50.0, 50.0 );
mu[ i ] = uniform( -10.0, 10.0 );
s[ i ] = uniform( EPS, 5.0 );
}

b.tic();
Expand Down
Loading
Loading