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,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 @@ -33,25 +32,22 @@

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

len = 100;
x = new Float64Array( len );
x0 = new Float64Array( len );
gamma = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( -100.0, 0.0 );
x0[ i ] = uniform( -50.0, 50.0 );
gamma[ i ] = uniform( EPS, 20.0 );
}
opts = {
'dtype': 'float64'
};
x = uniform( 100, -100.0, 0.0, opts );
x0 = uniform( 100, -50.0, 50.0, opts );
gamma = uniform( 100, EPS, 20.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logpdf( x[ i % len ], x0[ i % len ], gamma[ i % len ] );
y = logpdf( x[ i % x.length ], x0[ i % x0.length ], gamma[ i % gamma.length ] );

Check warning on line 50 in lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 88. Maximum allowed is 80
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -67,24 +63,24 @@
bench( pkg+':factory', function benchmark( b ) {
var mylogpdf;
var gamma;
var len;
var opts;
var x0;
var x;
var y;
var i;

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

x0 = 0.0;
gamma = 1.5;
mylogpdf = logpdf.factory( x0, gamma );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 100.0 );
}

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

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var EPS = require( '@stdlib/constants/float64/eps' );
var uniform = require( '@stdlib/random/base/uniform' );
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 @@ -42,25 +41,22 @@

bench( pkg+'::native', opts, function benchmark( b ) {
var gamma;
var len;
var opts;
var x0;
var x;
var y;
var i;

len = 100;
x = new Float64Array( len );
x0 = new Float64Array( len );
gamma = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( -100.0, 100.0 );
x0[ i ] = uniform( -50.0, 50.0 );
gamma[ i ] = uniform( EPS, 20.0 );
}
opts = {
'dtype': 'float64'
};
x = uniform( 100, -100.0, 100.0, opts );
x0 = uniform( 100, -50.0, 50.0, opts );
gamma = uniform( 100, EPS, 20.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logpdf( x[ i % len ], x0[ i % len ], gamma[ i % len ] );
y = logpdf( x[ i % x.length ], x0[ i % x0.length ], gamma[ i % gamma.length ] );

Check warning on line 59 in lib/node_modules/@stdlib/stats/base/dists/cauchy/logpdf/benchmark/benchmark.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 88. Maximum allowed is 80
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
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`',

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

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

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

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

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

t.end();
});
Expand All @@ -83,7 +83,7 @@ tape( 'if provided a valid `x0` and `gamma`, the function returns a function whi

logpdf = factory( 0.0, 1.0 );
y = logpdf( PINF );
t.equal( y, NINF, 'returns -Infinity' );
t.equal( y, NINF, 'returns expected value' );

t.end();
});
Expand All @@ -94,7 +94,7 @@ tape( 'if provided a valid `x0` and `gamma`, the function returns a function whi

logpdf = factory( 0.0, 1.0 );
y = logpdf( NINF );
t.equal( y, NINF, 'returns -Infinity' );
t.equal( y, NINF, 'returns expected value' );

t.end();
});
Expand All @@ -105,33 +105,33 @@ tape( 'if provided a nonpositive `gamma`, the created function always returns `N

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

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

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

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

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

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

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

logpdf = factory( NaN, NINF );
y = logpdf( 2.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 @@ -48,64 +48,64 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', functio
var y;

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

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

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

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

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

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

y = logpdf( NaN, NaN, 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 `x0` and `gamma`, the function returns `-Infinity`', function test( t ) {
var y = logpdf( PINF, 0.0, 1.0 );
t.equal( y, NINF, 'returns -Infinity' );
t.equal( y, NINF, 'returns expected value' );
t.end();
});

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

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

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

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

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

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

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

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

y = logpdf( 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 @@ -57,64 +57,64 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
var y;

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

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

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

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

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

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

y = logpdf( NaN, NaN, 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 `x0` and `gamma`, the function returns `-Infinity`', opts, function test( t ) {
var y = logpdf( PINF, 0.0, 1.0 );
t.equal( y, NINF, 'returns -Infinity' );
t.equal( y, NINF, 'returns expected value' );
t.end();
});

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

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

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

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

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

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

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

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

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

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