From af92abffc68b7c60a4d1db4a1eb5c1298854fda1 Mon Sep 17 00:00:00 2001 From: hrshya Date: Fri, 21 Mar 2025 23:46:08 +0530 Subject: [PATCH 1/4] bench: update random value generation --- .../fibonacci-index/benchmark/benchmark.js | 11 ++-- .../benchmark/benchmark.native.js | 9 ++- .../fibonacci-index/benchmark/c/benchmark.c | 9 ++- .../benchmark/c/native/benchmark.c | 9 ++- .../base/special/fibonacci-index/test/test.js | 10 +-- .../fibonacci-index/test/test.native.js | 10 +-- .../special/fibonacci/benchmark/benchmark.js | 61 +++++++++++-------- .../fibonacci/benchmark/benchmark.native.js | 7 ++- .../special/fibonacci/benchmark/c/benchmark.c | 9 ++- .../fibonacci/benchmark/c/native/benchmark.c | 9 ++- .../math/base/special/fibonacci/test/test.js | 12 ++-- .../special/fibonacci/test/test.native.js | 4 +- 12 files changed, 95 insertions(+), 65 deletions(-) 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..635a466e2170 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,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var floor = require( '@stdlib/math/base/special/floor' ); +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 +38,16 @@ bench( pkg, function benchmark( b ) { var y; var i; - FN = new Array( 76 ); + FN = zeros( 76 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } + + x = floor( uniform( 100, 3.0, 78.0 ) ); + 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..f09c47e07d79 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 @@ -24,6 +24,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 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 +47,16 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - FN = new Array( 76 ); + FN = zeros( 76 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } + + x = floor( uniform( 100, 3.0, 78.0 ) ); + 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..9e8187edc094 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 when provided a NaN' ); 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..25ca465774e9 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 when provided a NaN' ); 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..31a1153c37ad 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,12 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var floor = require( '@stdlib/math/base/special/floor' ); 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 +46,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +72,11 @@ bench( pkg+'::analytic', function benchmark( b ) { return round( pow( PHI, n ) / SQRT_5 ); } + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +94,11 @@ bench( pkg+'::table', function benchmark( b ) { var y; var i; + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +123,11 @@ bench( pkg+'::naive_recursion', function benchmark( b ) { return fibonacci( n-1 ) + fibonacci( n-2 ); } + x = floor( uniform( 100, 0.0, 40.0 ) ); // 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 +147,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 +161,11 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) { return arr[ n ]; } + x = floor( uniform( 100, 0.0, 40.0 ) ); // 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 +187,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 +197,11 @@ bench( pkg+'::naive_iterative', function benchmark( b ) { return arr[ n ]; } + x = floor( uniform( 100, 0.0, 79.0 ) ); // limit upper bound + 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 +235,11 @@ bench( pkg+'::iterative', function benchmark( b ) { return b; } + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +259,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 +276,11 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) { return arr[ n ]; } + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +323,11 @@ bench( pkg+'::iterative_doubling', function benchmark( b ) { return a + b; } + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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 +347,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 +387,11 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { return a + b; } + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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..0e2e9878cc25 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,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 floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -44,10 +44,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = floor( uniform( 100, 0.0, 79.0 ) ); + 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..1c0ccd10a652 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 when provided +infinity' ); 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 when provided a NaN' ); 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(); }); From f201eee020f6c8ca68078431b55639ccfec75020 Mon Sep 17 00:00:00 2001 From: hrshya Date: Sat, 22 Mar 2025 00:12:57 +0530 Subject: [PATCH 2/4] fix: fixes the import --- .../base/special/fibonacci-index/benchmark/benchmark.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f09c47e07d79..1b031663ffd4 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,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 floor = require( '@stdlib/math/base/special/floor' ); var zeros = require( '@stdlib/array/base/zeros' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); From 7aff2b524fe3b88ec3a46147405299a6f5f0ee6e Mon Sep 17 00:00:00 2001 From: hrshya Date: Sat, 22 Mar 2025 12:36:05 +0530 Subject: [PATCH 3/4] fix: updates uniform to discrete-uniform --- .../fibonacci-index/benchmark/benchmark.js | 5 ++-- .../benchmark/benchmark.native.js | 5 ++-- .../base/special/fibonacci-index/test/test.js | 2 +- .../fibonacci-index/test/test.native.js | 2 +- .../special/fibonacci/benchmark/benchmark.js | 23 +++++++++---------- .../fibonacci/benchmark/benchmark.native.js | 5 ++-- .../math/base/special/fibonacci/test/test.js | 4 ++-- 7 files changed, 21 insertions(+), 25 deletions(-) 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 635a466e2170..6f8da6bf72ac 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,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -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' ); @@ -43,7 +42,7 @@ bench( pkg, function benchmark( b ) { FN[ i ] = fibonacci( i ); } - x = floor( uniform( 100, 3.0, 78.0 ) ); + x = discreteUniform( 100, 3, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 1b031663ffd4..fcfb95a1c7e6 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,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -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' ); @@ -52,7 +51,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { FN[ i ] = fibonacci( i ); } - x = floor( uniform( 100, 3.0, 78.0 ) ); + x = discreteUniform( 100, 3, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 9e8187edc094..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,7 +37,7 @@ 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 expected value when provided a 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 25ca465774e9..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,7 +46,7 @@ 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 expected value when provided a 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 31a1153c37ad..f62674677795 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,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -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' ); @@ -46,7 +45,7 @@ bench( pkg, function benchmark( b ) { var y; var i; - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -72,7 +71,7 @@ bench( pkg+'::analytic', function benchmark( b ) { return round( pow( PHI, n ) / SQRT_5 ); } - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -94,7 +93,7 @@ bench( pkg+'::table', function benchmark( b ) { var y; var i; - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -123,7 +122,7 @@ bench( pkg+'::naive_recursion', function benchmark( b ) { return fibonacci( n-1 ) + fibonacci( n-2 ); } - x = floor( uniform( 100, 0.0, 40.0 ) ); // limit upper bound + x = discreteUniform( 100, 0, 40 ); // limit upper bound b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -161,7 +160,7 @@ bench( pkg+'::recursion_memoized', function benchmark( b ) { return arr[ n ]; } - x = floor( uniform( 100, 0.0, 40.0 ) ); // limit upper bound + x = discreteUniform( 100, 0, 40 ); // limit upper bound b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -197,7 +196,7 @@ bench( pkg+'::naive_iterative', function benchmark( b ) { return arr[ n ]; } - x = floor( uniform( 100, 0.0, 79.0 ) ); // limit upper bound + x = discreteUniform( 100, 0, 79 ); // limit upper bound b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -235,7 +234,7 @@ bench( pkg+'::iterative', function benchmark( b ) { return b; } - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -276,7 +275,7 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) { return arr[ n ]; } - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -323,7 +322,7 @@ bench( pkg+'::iterative_doubling', function benchmark( b ) { return a + b; } - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -387,7 +386,7 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { return a + b; } - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 0e2e9878cc25..62bab2be9ce6 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 uniform = require( '@stdlib/random/array/uniform' ); -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,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - x = floor( uniform( 100, 0.0, 79.0 ) ); + x = discreteUniform( 100, 0, 79 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 1c0ccd10a652..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 @@ -54,13 +54,13 @@ tape( 'if provided a negative number, the function returns `NaN`', function test tape( 'if provided positive infinity, the function returns `NaN`', function test( t ) { var v = fibonacci( PINF ); - t.strictEqual( isnan( v ), true, 'returns expected value 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 expected value when provided a NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); From f1c469a4517d5a2da07ed2d9757f2c29160888a1 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 22 Mar 2025 05:41:53 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Signed-off-by: Athan --- .../fibonacci-index/benchmark/benchmark.js | 2 +- .../benchmark/benchmark.native.js | 2 +- .../special/fibonacci/benchmark/benchmark.js | 16 ++++++++-------- .../fibonacci/benchmark/benchmark.native.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) 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 6f8da6bf72ac..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 @@ -37,7 +37,7 @@ bench( pkg, function benchmark( b ) { var y; var i; - FN = zeros( 76 ); + FN = zeros( 79 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } 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 fcfb95a1c7e6..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 @@ -46,7 +46,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - FN = zeros( 76 ); + FN = zeros( 79 ); for ( i = 3; i < 79; i++ ) { FN[ i ] = fibonacci( i ); } 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 f62674677795..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 @@ -45,7 +45,7 @@ bench( pkg, function benchmark( b ) { var y; var i; - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -71,7 +71,7 @@ bench( pkg+'::analytic', function benchmark( b ) { return round( pow( PHI, n ) / SQRT_5 ); } - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -93,7 +93,7 @@ bench( pkg+'::table', function benchmark( b ) { var y; var i; - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -196,7 +196,7 @@ bench( pkg+'::naive_iterative', function benchmark( b ) { return arr[ n ]; } - x = discreteUniform( 100, 0, 79 ); // limit upper bound + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -234,7 +234,7 @@ bench( pkg+'::iterative', function benchmark( b ) { return b; } - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -275,7 +275,7 @@ bench( pkg+'::iterative_memoized', function benchmark( b ) { return arr[ n ]; } - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -322,7 +322,7 @@ bench( pkg+'::iterative_doubling', function benchmark( b ) { return a + b; } - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { @@ -386,7 +386,7 @@ bench( pkg+'::iterative_doubling_memoized', function benchmark( b ) { return a + b; } - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { 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 62bab2be9ce6..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 @@ -43,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; - x = discreteUniform( 100, 0, 79 ); + x = discreteUniform( 100, 0, 78 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) {