diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.js index 09879f2951a3..fac7ebc132dc 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.js @@ -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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var zeros = require( '@stdlib/array/base/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var fibonacci = require( '@stdlib/math/base/special/fibonacci' ); var pkg = require( './../package.json' ).name; @@ -37,14 +37,16 @@ bench( pkg, function benchmark( b ) { var y; var i; - FN = new Array( 76 ); + FN = zeros( 79 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } + + x = discreteUniform( 100, 3, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( (randu()*75.0) + 3.0 ); - y = fibonacciIndex( FN[ x ] ); + y = fibonacciIndex( FN[ x[ i%x.length ] ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.native.js index a21f1484365c..002b584e10e8 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/benchmark.native.js @@ -22,8 +22,8 @@ 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 zeros = require( '@stdlib/array/base/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var fibonacci = require( '@stdlib/math/base/special/fibonacci' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -46,14 +46,16 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - FN = new Array( 76 ); + FN = zeros( 79 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } + + x = discreteUniform( 100, 3, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( ( randu() * 75.0 ) + 3.0 ); - y = fibonacciIndex( FN[ x ] ); + y = fibonacciIndex( FN[ x[ i%x.length ] ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/benchmark.c index dfcfa98fbbfc..1c66f755ab7a 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/benchmark.c @@ -102,15 +102,18 @@ int fibonacci_index( int F ) { static double benchmark( void ) { double elapsed; double t; - int x; + int x[ 100 ]; int y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = (int)floor( (100000.0*rand_double()) + 2.0 ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { // note: using actual Fibonacci numbers is not important - x = (int)floor( (100000.0*rand_double()) + 2.0 ); - y = fibonacci_index( x ); + y = fibonacci_index( x[ i%100 ] ); if ( y < 0 ) { printf( "should return a nonnegative integer\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/native/benchmark.c index ea61c5e478fd..4911a5282016 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/benchmark/c/native/benchmark.c @@ -91,15 +91,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 ] = (int)floor( ( 75.0 * rand_double() ) + 3.0 ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = (int)floor( ( 75.0 * rand_double() ) + 3.0 ); - y = stdlib_base_fibonacci_index( x ); + y = stdlib_base_fibonacci_index( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.js b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.js index 54f68db70918..0baece6bcc53 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.js @@ -37,13 +37,13 @@ tape( 'main export is a function', function test( t ) { tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { var n = fibonacciIndex( NaN ); - t.strictEqual( isnan( n ), true, 'returns NaN when provided a NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); tape( 'if provided `+infinity`, the function returns `NaN`', function test( t ) { var n = fibonacciIndex( PINF ); - t.strictEqual( isnan( n ), true, 'returns NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); @@ -51,18 +51,18 @@ tape( 'if provided a number less than or equal to 1, the function returns `NaN`' var n; var i; - t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns NaN' ); + t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns expected value' ); for ( i = 1; i > -100; i-- ) { n = fibonacciIndex( i ); - t.strictEqual( isnan( n ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( n ), true, 'returns expected value when provided ' + i ); } t.end(); }); tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) { var n = fibonacciIndex( 3.14 ); - t.strictEqual( isnan( n ), true, 'returns NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.native.js index 3e3874620058..88ef0b81ddaf 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci-index/test/test.native.js @@ -46,13 +46,13 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'if provided `NaN`, the function returns `NaN`', opts, function test( t ) { var n = fibonacciIndex( NaN ); - t.strictEqual( isnan( n ), true, 'returns NaN when provided a NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); tape( 'if provided `+infinity`, the function returns `NaN`', opts, function test( t ) { var n = fibonacciIndex( PINF ); - t.strictEqual( isnan( n ), true, 'returns NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); @@ -60,18 +60,18 @@ tape( 'if provided a number less than or equal to 1, the function returns `NaN`' var n; var i; - t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns NaN' ); + t.strictEqual( isnan( fibonacciIndex( -3.14 ) ), true, 'returns expected value' ); for ( i = 1; i > -100; i-- ) { n = fibonacciIndex( i ); - t.strictEqual( isnan( n ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( n ), true, 'returns expected value when provided ' + i ); } t.end(); }); tape( 'if provided a non-integer, the function returns `NaN`', opts, function test( t ) { var n = fibonacciIndex( 3.14 ); - t.strictEqual( isnan( n ), true, 'returns NaN' ); + t.strictEqual( isnan( n ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.js index 2cafaa3313c1..dc86132b3f0b 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.js @@ -21,11 +21,11 @@ // 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 round = require( '@stdlib/math/base/special/round' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/array/base/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PHI = require( '@stdlib/constants/float64/phi' ); var pkg = require( './../package.json' ).name; @@ -45,10 +45,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -70,10 +71,11 @@ bench( pkg+'::analytic', function benchmark( b ) { return round( pow( PHI, n ) / SQRT_5 ); } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -91,10 +93,11 @@ bench( pkg+'::table', function benchmark( b ) { var y; var i; + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = FIBONACCI[ x ]; + y = FIBONACCI[ x[ i%x.length ] ]; if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -119,10 +122,11 @@ bench( pkg+'::naive_recursion', function benchmark( b ) { return fibonacci( n-1 ) + fibonacci( n-2 ); } + x = discreteUniform( 100, 0, 40 ); // limit upper bound + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*40.0 ); // limit upper bound - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -142,7 +146,7 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) { var y; var i; - arr = new Array( 79 ); + arr = zeros( 79 ); arr[ 0 ] = 0; arr[ 1 ] = 1; arr[ 2 ] = 1; @@ -156,10 +160,11 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) { return arr[ n ]; } + x = discreteUniform( 100, 0, 40 ); // limit upper bound + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*40.0 ); // limit upper bound - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -181,7 +186,7 @@ bench( pkg+'::naive_iterative', function benchmark( b ) { var arr; var i; - arr = new Array( n+1 ); + arr = zeros( n+1 ); arr[ 0 ] = 0; arr[ 1 ] = 1; arr[ 2 ] = 1; @@ -191,10 +196,11 @@ bench( pkg+'::naive_iterative', function benchmark( b ) { return arr[ n ]; } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -228,10 +234,11 @@ bench( pkg+'::iterative', function benchmark( b ) { return b; } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -251,7 +258,7 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) { var y; var i; - arr = new Array( 79 ); + arr = zeros( 79 ); arr[ 0 ] = 0; arr[ 1 ] = 1; arr[ 2 ] = 1; @@ -268,10 +275,11 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) { return arr[ n ]; } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -314,10 +322,11 @@ bench( pkg+'::iterative_doubling', function benchmark( b ) { return a + b; } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -337,7 +346,7 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { var y; var i; - arr = new Array( 79 ); + arr = zeros( 79 ); arr[ 0 ] = 0; arr[ 1 ] = 1; arr[ 2 ] = 1; @@ -377,10 +386,11 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { return a + b; } + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.native.js index 9e4f0bd77038..835577df56bc 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/benchmark.native.js @@ -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; @@ -44,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = discreteUniform( 100, 0, 78 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*79.0 ); - y = fibonacci( x ); + y = fibonacci( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/benchmark.c index 95e423b77d0a..1dae474bfe60 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/benchmark.c @@ -104,14 +104,17 @@ int fibonacci( int n ) { static double benchmark( void ) { double elapsed; double t; - int x; + int x[ 100 ]; int y; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = (int)floor( 40.0*rand_double() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = (int)floor( 40.0*rand_double() ); - y = fibonacci( x ); + y = fibonacci( x[ i%100 ] ); if ( y < 0 ) { printf( "should return a nonnegative integer\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/native/benchmark.c index 33498eba3379..9d87e5d1812a 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/benchmark/c/native/benchmark.c @@ -91,15 +91,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - int32_t x; + int32_t x[ 100 ]; 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_fibonacci( x ); + y = stdlib_base_fibonacci( x[ i%100 ] ); if ( y < 0 ) { printf( "should return a nonnegative integer\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.js b/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.js index 072810ea3b5e..fe482023b1bd 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.js @@ -43,30 +43,30 @@ tape( 'if provided a negative number, the function returns `NaN`', function test var v; var i; - t.strictEqual( isnan( fibonacci( -3.14 ) ), true, 'returns NaN' ); + t.strictEqual( isnan( fibonacci( -3.14 ) ), true, 'returns expected value' ); for ( i = -1; i > -100; i-- ) { v = fibonacci( 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 = fibonacci( 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 = fibonacci( 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 = fibonacci( 3.14 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -85,7 +85,7 @@ tape( 'if provided nonnegative integers greater than `78`, the function returns var v; for ( i = 79; i < 500; i++ ) { v = fibonacci( i ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.native.js index 36893bf8af33..63099e14ebbe 100644 --- a/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/fibonacci/test/test.native.js @@ -53,7 +53,7 @@ tape( 'if provided a negative number, the function returns `NaN`', opts, functio for ( i = -1; i > -100; i-- ) { v = fibonacci( i ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i ); } t.end(); }); @@ -73,7 +73,7 @@ tape( 'if provided nonnegative integers greater than `78`, the function returns var v; for ( i = 79; i < 500; i++ ) { v = fibonacci( i ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i ); } t.end(); });