Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var binet = require( './../lib' );
Expand All @@ -35,10 +34,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, 0, 79 );

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

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/random/array/discrete-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 @@ -44,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, 0, 79 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu() * 79.0 );
y = binet( x );
y = binet( 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 @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "stdlib/math/base/special/binet.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -99,16 +100,19 @@ double binet( double x ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double t;
double x;
double y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = floor( 79.0*rand_double() );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = floor( 79.0*rand_double() );
y = binet( x );
y = stdlib_base_binet( x[ i%100 ] );
if ( y < 0 ) {
printf( "should return a nonnegative number\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = floor( 79.0*rand_double() );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = floor( 79.0 * rand_double() );
y = stdlib_base_binet( x );
y = stdlib_base_binet( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/binet/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@

tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
var v = binet( NaN );
t.strictEqual( isnan( v ), true, 'returns NaN when provided a NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) {
var v = binet( PINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

tape( 'if provided `-infinity`, the function returns `NaN`', function test( t ) {
var v = binet( NINF );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -77,7 +77,7 @@
t.end();
});

tape( 'for nonpositive integers, the function approximates the nth negaFibonacci number', function test( t ) {

Check warning on line 80 in lib/node_modules/@stdlib/math/base/special/binet/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "nega"
var expected;
var delta;
var tol;
Expand All @@ -87,7 +87,7 @@
v = binet( i );
expected = negaFibonacci( i );
if ( v === expected ) {
t.strictEqual( v, expected, 'returns the '+i+'th negaFibonacci number' );

Check warning on line 90 in lib/node_modules/@stdlib/math/base/special/binet/test/test.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "nega"
} else {
delta = abs( v - expected );
tol = 12.0 * EPS * abs( expected );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ bench( pkg, function benchmark( b ) {
var y;
var z;
var i;
var j;

x = discreteUniform( 100, 20, 70 );
y = discreteUniform( x.length, 0, 20 );
y = discreteUniform( 100, 0, 20 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = i % x.length;
z = binomcoef( x[ j ], y[ j ] );
z = binomcoef( 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 @@ -43,15 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var z;
var i;
var j;

x = discreteUniform( 100, 20, 70 );
y = discreteUniform( x.length, 0, 20 );
y = discreteUniform( 100, 0, 20 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
j = i % x.length;
z = binomcoef( x[ j ], y[ j ] );
z = binomcoef( 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 @@ -90,18 +90,21 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
int64_t n[ 100 ];
int64_t k[ 100 ];
double elapsed;
int64_t n;
int64_t k;
double y;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
n[ i ] = (int64_t)round( 500.0 * rand_double() );
k[ i ] = (int64_t)round( 500.0 * rand_double() );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
n = (int64_t)round( 500.0 * rand_double() );
k = (int64_t)round( 500.0 * rand_double() );
y = stdlib_base_binomcoef( n, k );
y = stdlib_base_binomcoef( n[ i%100 ], k[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function returns `NaN` if provided `NaN` for any parameter', function test( t ) {
var v = binomcoef( 3, NaN );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );

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

t.end();
});
Expand Down Expand Up @@ -101,7 +101,7 @@ tape( 'the function returns `NaN` if the `n` value is not an integer', function
];

for ( i = 0; i < values.length; i++ ) {
t.strictEqual( isnan( binomcoef( values[i], 2 ) ), true, 'returns NaN when provided '+values[i] );
t.strictEqual( isnan( binomcoef( values[i], 2 ) ), true, 'returns expected value when provided '+values[i] );
}
t.end();
});
Expand All @@ -122,7 +122,7 @@ tape( 'the function returns `NaN` if the `k` value is not an integer', function
];

for ( i = 0; i < values.length; i++ ) {
t.strictEqual( isnan( binomcoef( 2, values[i] ) ), true, 'returns NaN when provided '+values[i] );
t.strictEqual( isnan( binomcoef( 2, values[i] ) ), true, 'returns expected value when provided '+values[i] );
}
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 boxcox = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var r;
var i;

x = uniform( 100, 1, 11 );
y = uniform( 100, 1, 11 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*10.0 ) + 1.0;
y = ( randu()*10.0 ) + 1.0;
r = boxcox( x, y );
r = boxcox( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( r ) ) {
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 @@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var r;
var i;

x = uniform( 100, 1, 11 );
y = uniform( 100, 1, 11 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 10.0 ) + 1.0;
y = ( randu() * 10.0 ) + 1.0;
r = boxcox( x, y );
r = boxcox( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( r ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ static double rand_double( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
double x[ 100 ];
double y[ 100 ];
double elapsed;
double x;
double y;
double r;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 10.0 ) + 1.0;
y[ i ] = ( rand_double() * 10.0 ) + 1.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( ( rand_double() * 10.0 ) + 1.0 );
y = ( ( rand_double() * 10.0 ) + 1.0 );
r = stdlib_base_boxcox( x, y );
r = stdlib_base_boxcox( x[ i%100 ], y[ i%100 ] );
if ( r != r ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var b;

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

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

b = boxcox( NaN, NaN );
t.equal( isnan( b ), true, 'returns NaN' );
t.equal( isnan( b ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -87,7 +87,7 @@ tape( 'the function returns `NaN` if `x` is negative', function test( t ) {
x = -1.0 * ( (randu()*100.0) + 1.0 );
y = randu() * 10.0;
b = boxcox( x, y );
t.equal( isnan( b ), true, 'returns NaN' );
t.equal( isnan( b ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
var b;

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

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

b = boxcox( NaN, NaN );
t.equal( isnan( b ), true, 'returns NaN' );
t.equal( isnan( b ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -96,7 +96,7 @@ tape( 'the function returns `NaN` if `x` is negative', opts, function test( t )
x = -1.0 * ( (randu()*100.0) + 1.0 );
y = randu() * 10.0;
b = boxcox( x, y );
t.equal( isnan( b ), true, 'returns NaN' );
t.equal( isnan( b ), true, '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 boxcox1p = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var r;
var i;

x = uniform( 100, 0.0, 10.0 );
y = uniform( 100, 0.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 10.0;
y = randu() * 10.0;
r = boxcox1p( x, y );
r = boxcox1p( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( r ) ) {
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 @@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var r;
var i;

x = uniform( 100, 0.0, 10.0 );
y = uniform( 100, 0.0, 10.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu() * 10.0;
y = randu() * 10.0;
r = boxcox1p( x, y );
r = boxcox1p( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( r ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Loading