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

chore: update random value generation and test messages #6343

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

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
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 @@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y );
z = gammainc( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -59,11 +60,12 @@ bench( pkg+':regularized=true', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, true );
z = gammainc( x[ i%x.length ], y[ i%y.length ], true );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -82,11 +84,12 @@ bench( pkg+':regularized=false', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, false );
z = gammainc( x[ i%x.length ], y[ i%y.length ], false );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -105,11 +108,12 @@ bench( pkg+':regularized=true,upper=true', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, true, true );
z = gammainc( x[ i%x.length ], y[ i%y.length ], true, true );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -128,11 +132,12 @@ bench( pkg+':regularized=true,upper=false', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, true, false );
z = gammainc( x[ i%x.length ], y[ i%y.length ], true, false );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -151,11 +156,12 @@ bench( pkg+':regularized=false,upper=true', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, false, true );
z = gammainc( x[ i%x.length ], y[ i%y.length ], false, true );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -174,11 +180,12 @@ bench( pkg+':regularized=false,upper=false', function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1000.0 );
y = uniform( 100, EPS, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 0.0;
y = ( randu()*1000.0 ) + EPS;
z = gammainc( x, y, false, false );
z = gammainc( x[ i%x.length ], y[ i%y.length ], false, false );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,20 @@ static double rand_double( void ) {
*/
static double benchmark1( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) - 0.0;
y[ i ] = ( 99.9*rand_double() ) + 0.1;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) - 0.0;
y = ( 99.9*rand_double() ) + 0.1;
z = igam( x, y );
z = igam( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -126,17 +129,20 @@ static double benchmark1( void ) {
*/
static double benchmark2( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 100.0*rand_double() ) - 0.0;
y[ i ] = ( 99.9*rand_double() ) + 0.1;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) - 0.0;
y = ( 99.9*rand_double() ) + 0.1;
z = igamc( x, y );
z = igamc( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/gammainc/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var val;

val = gammainc( NaN, 2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

val = gammainc( 4, NaN );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

t.end();
});
Expand All @@ -64,15 +64,15 @@ tape( 'the function returns NaN if provided x < 0 or s <= 0', function test( t )

// Case: x < 0
val = gammainc( -0.1, 2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

// Case: s = 0
val = gammainc( 0.1, 0 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

// Case: s < 0
val = gammainc( 0.1, -2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

t.end();
});
Expand All @@ -82,7 +82,7 @@ tape( 'the function returns 0 for the lower incomplete gamma function when the f
var s;
for ( s = 1; s < 10; s++ ) {
val = gammainc( 0, s );
t.ok( val === 0, 'returns 0' );
t.ok( val === 0, 'returns expected value' );
}
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var gammaincinv = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, 0.0, 1.0 );
y = uniform( 100, 0.1, 1000.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu();
y = ( randu()*1000.0 ) + 0.1;
z = gammaincinv( x, y );
z = gammaincinv( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 1000.0*rand_double() ) + 0.1;
y[ i ] = ( 0.5*rand_double() );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) + 0.1;
y = ( 0.5*rand_double() );
z = igami( x, y );
z = igami( x[ i%100 ], y[ i%100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
var val;

val = gammaincinv( NaN, 2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

val = gammaincinv( 0.5, NaN );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

t.end();
});
Expand All @@ -108,10 +108,10 @@ tape( 'the function returns `NaN` if provided `p` outside the interval `[0,1]`',
var val;

val = gammaincinv( 1.2, 2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

val = gammaincinv( -0.1, 2 );
t.strictEqual( isnan( val ), true, 'returns NaN' );
t.strictEqual( isnan( val ), true, 'returns expected value' );

t.end();
});
Expand All @@ -124,7 +124,7 @@ tape( 'the function returns `0` if provided `p = 1`', function test( t ) {
a = incrspace( 0, 100, 10 );
for ( i = 0; i < a.length; i++ ) {
val = gammaincinv( 1, a[ i ] );
t.notOk( val === 0, 'returns 0' );
t.notOk( val === 0, 'returns expected value' );
}
t.end();
});
Expand All @@ -137,7 +137,7 @@ tape( 'the function returns `+Infinity` if provided `p = 0`', function test( t )
a = incrspace( 0, 100, 10 );
for ( i = 0; i < a.length; i++ ) {
val = gammaincinv( 0, a[ i ] );
t.notOk( val === PINF, 'returns +Infinity' );
t.notOk( val === PINF, 'returns expected value' );
}
t.end();
});
Expand All @@ -150,7 +150,7 @@ tape( 'the function returns `0` if provided `p = 0` when `upper = true`', functi
a = incrspace( 0, 100, 10 );
for ( i = 0; i < a.length; i++ ) {
val = gammaincinv( 0, a[ i ], true );
t.notOk( val === 0, 'returns 0' );
t.notOk( val === 0, 'returns expected value' );
}
t.end();
});
Expand All @@ -163,7 +163,7 @@ tape( 'the function returns `+Infinity` if provided `p = 1` when `upper = true`'
a = incrspace( 0, 100, 10 );
for ( i = 0; i < a.length; i++ ) {
val = gammaincinv( 1, a[ i ], true );
t.notOk( val === PINF, 'returns +Infinity' );
t.notOk( val === PINF, 'returns expected value' );
}
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var gammaln = require( './../lib' );
Expand All @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*1000.0 ) - 500.0;
y = gammaln( x );
y = gammaln( 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,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, -500.0, 500.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 1000.0 ) - 500.0;
y = gammaln( x );
y = gammaln( 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 @@ -90,15 +90,18 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double x[ 100 ];
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 1000.0*rand_double() ) - 500.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0*rand_double() ) - 500.0;
y = lgamma( x );
y = lgamma( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Loading