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,8 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var Int32Array = require( '@stdlib/array/int32' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var TRIBONACCI = require( './../lib/tribonacci.json' );
Expand All @@ -36,10 +36,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, 0, 63 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*64.0 );
y = tribonacci( x );
y = tribonacci( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -57,10 +58,11 @@ bench( pkg+'::table', function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, 0, 63 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*64.0 );
y = TRIBONACCI[ x ];
y = TRIBONACCI[ x[ i % x.length ] ];
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down Expand Up @@ -88,10 +90,11 @@ bench( pkg+'::naive_recursion', function benchmark( b ) {
return tribonacci( n-1 ) + tribonacci( n-2 ) + tribonacci( n-3 );
}

x = discreteUniform( 100, 0, 10 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*10.0 ); // limit upper bound
y = tribonacci( x );
y = tribonacci( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -111,7 +114,7 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) {
var y;
var i;

arr = new Array( 64 );
arr = new Int32Array( 64 );
arr[ 0 ] = 0;
arr[ 1 ] = 0;
arr[ 2 ] = 1;
Expand All @@ -125,10 +128,11 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) {
return arr[ n ];
}

x = discreteUniform( 100, 0, 10 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*10.0 ); // limit upper bound
y = tribonacci( x );
y = tribonacci( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -150,7 +154,7 @@ bench( pkg+'::naive_iterative', function benchmark( b ) {
var arr;
var i;

arr = new Array( n+1 );
arr = new Int32Array( n+1 );
arr[ 0 ] = 0;
arr[ 1 ] = 0;
arr[ 2 ] = 1;
Expand All @@ -160,10 +164,11 @@ bench( pkg+'::naive_iterative', function benchmark( b ) {
return arr[ n ];
}

x = discreteUniform( 100, 0, 63 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*64.0 );
y = tribonacci( x );
y = tribonacci( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down Expand Up @@ -200,10 +205,11 @@ bench( pkg+'::iterative', function benchmark( b ) {
return c;
}

x = discreteUniform( 100, 0, 63 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*64.0 );
y = tribonacci( x );
y = tribonacci( x[ i % x.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -223,7 +229,7 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) {
var y;
var i;

arr = new Array( 64 );
arr = new Int32Array( 64 );
arr[ 0 ] = 0;
arr[ 1 ] = 0;
arr[ 2 ] = 1;
Expand All @@ -240,10 +246,11 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) {
return arr[ n ];
}

x = discreteUniform( 100, 0, 63 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = floor( randu()*64.0 );
y = tribonacci( x );
y = tribonacci( 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, 63 );

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

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

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = (int)floor( 64.0*rand_double() );
y = tribonacci( x );
y = tribonacci( x[ i%100 ] );
if ( y < 0 ) {
printf( "should return a nonnegative integer\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 ) {
int32_t x[ 100 ];
double elapsed;
int32_t x;
double t;
double y;
int i;

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

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = (int32_t)floor( 40.0*rand_double() );
y = stdlib_base_tribonacci( x );
y = stdlib_base_tribonacci( x[ i%100 ] );
if ( y < 0 ) {
printf( "should return a nonnegative integer\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ tape( 'if provided a negative number, the function returns `NaN`', function test
var v;
var i;

t.strictEqual( isnan( tribonacci( -3.14 ) ), true, 'returns NaN' );
t.strictEqual( isnan( tribonacci( -3.14 ) ), true, 'returns expected value' );

for ( i = -1; i > -100; i-- ) {
v = tribonacci( i );
t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i );
t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i );
}
t.end();
});

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

tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
var v = tribonacci( 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 a non-integer, the function returns `NaN`', function test( t ) {
var v = tribonacci( 3.14 );
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -85,7 +85,7 @@ tape( 'if provided nonnegative integers greater than `63`, the function returns
var v;
for ( i = 64; i < 500; i++ ) {
v = tribonacci( i );
t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i );
t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tape( 'if provided a negative number, the function returns `NaN`', opts, functio

for ( i = -1; i > -100; i-- ) {
v = tribonacci( i );
t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i );
t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i );
}
t.end();
});
Expand All @@ -73,7 +73,7 @@ tape( 'if provided nonnegative integers greater than `63`, the function returns
var v;
for ( i = 64; i < 500; i++ ) {
v = tribonacci( i );
t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i );
t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i );
}
t.end();
});
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 @@ -35,10 +35,11 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = uniform( 100, EPS, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) + EPS;
y = trigamma( x );
y = trigamma( 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 EPS = require( '@stdlib/constants/float64/eps' );
var tryRequire = require( '@stdlib/utils/try-require' );
Expand All @@ -44,10 +44,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var y;
var i;

x = uniform( 100, EPS, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 100.0 ) + EPS;
y = trigamma( x );
y = trigamma( 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,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 ] = ( 100.0 * rand_double() );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0 * rand_double() );
y = stdlib_base_trigamma( x );
y = stdlib_base_trigamma( x[ 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 @@ -85,8 +85,8 @@ double tic() {
* @return elapsed time in seconds
*/
double benchmark() {
double x[ 100 ];
double elapsed;
double x;
double y;
double t;
int i;
Expand All @@ -97,10 +97,13 @@ double benchmark() {
// Define a uniform distribution for generating pseudorandom numbers as "doubles" between a minimum value (inclusive) and a maximum value (exclusive):
uniform_real_distribution<> randu( 0.1, 100.0 );

for ( i = 0; i < 100; i++ ) {
x[ i ] = randu( rng );
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = randu( rng );
y = boost::math::trigamma( x );
y = boost::math::trigamma( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Loading