Skip to content

bench: update random value generation #6858

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 2 commits 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,10 +21,8 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var skewness = require( './../lib' );
Expand All @@ -33,23 +31,21 @@ var skewness = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var n;
var p;
var y;
var i;

len = 100;
n = new Int32Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
n[ i ] = discreteUniform( 1, 100 );
p[ i ] = uniform( 0.0, 1.0 );
}
n = discreteUniform( 100, 1, 100, {
'dtype': 'int32'
});
p = uniform( 100, 0.0, 1.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = skewness( n[ i % len ], p[ i % len ] );
y = skewness( n[ i % n.length ], p[ i % p.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,11 +22,9 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;

Expand All @@ -42,23 +40,21 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var n;
var p;
var y;
var i;

len = 100;
n = new Int32Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
n[ i ] = discreteUniform( 1, 100 );
p[ i ] = uniform( 0.0, 1.0 );
}
n = discreteUniform( 100, 1, 100, {
'dtype': 'int32'
});
p = uniform( 100, 0.0, 1.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = skewness( n[ i % len ], p[ i % len ] );
y = skewness( n[ i % n.length ], p[ i % p.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ 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 = skewness( NaN, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

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

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

t.end();
});
Expand All @@ -59,19 +59,19 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur
var v;

v = skewness( 1.5, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( -2, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( -1, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 2.5, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( PINF, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -80,16 +80,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
var v;

v = skewness( 20, -1.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, 1.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, NINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, PINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ tape( 'if provided `NaN` for `p`, the function returns `NaN`', opts, function te
var v;

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

t.end();
});
Expand All @@ -64,10 +64,10 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur
var v;

v = skewness( -2, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( -1, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -76,16 +76,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
var v;

v = skewness( 20, -1.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, 1.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, NINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = skewness( 20, PINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

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

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var stdev = require( './../lib' );
Expand All @@ -32,23 +31,21 @@ var stdev = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var n;
var p;
var y;
var i;

len = 100;
n = new Float64Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
n[ i ] = discreteUniform( 1, 100 );
p[ i ] = uniform( 0.0, 1.0 );
}
n = discreteUniform( 100, 1, 100, {
'dtype': 'int32'
});
p = uniform( 100, 0.0, 1.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = stdev( n[ i % len ], p[ i % len ] );
y = stdev( n[ i % n.length ], p[ i % p.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,9 +22,8 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var tryRequire = require( '@stdlib/utils/try-require' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
Expand All @@ -41,23 +40,21 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var n;
var p;
var y;
var i;

len = 100;
n = new Float64Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
n[ i ] = discreteUniform( 1, 100 );
p[ i ] = uniform( 0.0, 1.0 );
}
n = discreteUniform( 100, 1, 100, {
'dtype': 'int32'
});
p = uniform( 100, 0.0, 1.0, {
'dtype': 'float64'
});

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = stdev( n[ i % len ], p[ i % len ] );
y = stdev( n[ i % n.length ], p[ i % p.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ 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 = stdev( NaN, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

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

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

t.end();
});
Expand All @@ -57,19 +57,19 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur
var v;

v = stdev( 1.5, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( -2, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( -1, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 2.5, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( PINF, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -78,16 +78,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
var v;

v = stdev( 20, -1.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, 1.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, NINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, PINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ 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 v = stdev( NaN, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

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

t.end();
});
Expand All @@ -63,10 +63,10 @@ tape( 'if provided an `n` which is not a nonnegative integer, the function retur
var v;

v = stdev( -2, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( -1, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -75,16 +75,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re
var v;

v = stdev( 20, -1.0 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, 1.5 );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, NINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

v = stdev( 20, PINF );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );

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