Skip to content
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,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 cdf = require( './../lib' );
Expand All @@ -32,23 +31,21 @@ var cdf = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var opts;
var k;
var x;
var y;
var i;

len = 100;
x = new Float64Array( len );
k = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 100.0 );
k[ i ] = discreteUniform( 1, 100 );
}
opts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 100.0, opts );
k = discreteUniform( 100, 1, 100, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = cdf( x[ i % len ], k[ i % len ] );
y = cdf( x[ i % x.length ], k[ i % k.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -63,23 +60,23 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var opts;
var k;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 100.0, opts );

k = 10.0;
mycdf = cdf.factory( k );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 100.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
26 changes: 13 additions & 13 deletions lib/node_modules/@stdlib/stats/base/dists/chi/cdf/test/test.cdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,35 @@ 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, 1.0 );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
y = cdf( 0.0, NaN );
t.equal( isnan( y ), true, 'returns NaN' );
t.equal( isnan( y ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `+infinity` for `x` and a finite `k`, the function returns `1`', function test( t ) {
var y = cdf( PINF, 1.0 );
t.equal( y, 1.0, 'returns 1' );
t.equal( y, 1.0, 'returns expected value' );
t.end();
});

tape( 'if provided `-infinity` for `x` and a finite `k`, the function returns `0`', function test( t ) {
var y = cdf( NINF, 1.0 );
t.equal( y, 0.0, 'returns 0' );
t.equal( y, 0.0, 'returns expected value' );
t.end();
});

tape( 'if provided a negative `k`, the function always returns `NaN`', function test( t ) {
var y;

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

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

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

t.end();
});
Expand All @@ -81,22 +81,22 @@ tape( 'if provided a `k` equal to `0`, the function evaluates a degenerate distr
var y;

y = cdf( PINF, 0.0 );
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 2.5, 0.0 );
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 0.0, 0.0 );
t.equal( y, 1.0, 'returns 1 for x equal to 0' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( -2.0, 0.0 );
t.equal( y, 0.0, 'returns 0 for x smaller than 0' );
t.equal( y, 0.0, 'returns expected value' );

y = cdf( NINF, 0.0 );
t.equal( y, 0.0, 'returns 0 for x smaller than 0' );
t.equal( y, 0.0, 'returns expected value' );

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

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

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

t.end();
});
Expand All @@ -69,7 +69,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `

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

t.end();
});
Expand All @@ -80,7 +80,7 @@ tape( 'if provided a finite `k`, the function returns a function which returns `

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

t.end();
});
Expand All @@ -92,10 +92,10 @@ tape( 'if provided a negative `k`, the created function always returns `NaN`', f
cdf = factory( -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' );

t.end();
});
Expand All @@ -107,22 +107,22 @@ tape( 'if `k` equals `0`, the created function evaluates a degenerate distributi
cdf = factory( 0.0 );

y = cdf( PINF );
t.equal( y, 1.0, 'returns 1 for x greater than one' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 3.0 );
t.equal( y, 1.0, 'returns 1 for x greater than 0' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( 0.0 );
t.equal( y, 1.0, 'returns 1 for x equal to 0' );
t.equal( y, 1.0, 'returns expected value' );

y = cdf( -0.5 );
t.equal( y, 0.0, 'returns 0 for x smaller than one' );
t.equal( y, 0.0, 'returns expected value' );

y = cdf( NINF );
t.equal( y, 0.0, 'returns 0 for x smaller than one' );
t.equal( y, 0.0, 'returns expected value' );

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

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