From 82244c24700b61d21a187b0fdb68f09cc6e1b6e9 Mon Sep 17 00:00:00 2001 From: saurabhraghuvanshii Date: Sun, 23 Feb 2025 23:57:00 +0530 Subject: [PATCH 1/2] bench: refactor random number generation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/special/besselj0/benchmark/benchmark.js | 7 ++++--- .../special/besselj0/benchmark/benchmark.native.js | 7 ++++--- .../base/special/besselj0/benchmark/c/benchmark.c | 9 ++++++--- .../special/besselj0/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../special/besselj0/benchmark/c/native/benchmark.c | 9 ++++++--- .../@stdlib/math/base/special/besselj0/test/test.js | 2 +- .../base/special/besselj1/benchmark/benchmark.js | 7 ++++--- .../special/besselj1/benchmark/benchmark.native.js | 7 ++++--- .../base/special/besselj1/benchmark/c/benchmark.c | 9 ++++++--- .../special/besselj1/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../special/besselj1/benchmark/c/native/benchmark.c | 9 ++++++--- .../@stdlib/math/base/special/besselj1/test/test.js | 2 +- .../base/special/bessely0/benchmark/benchmark.js | 7 ++++--- .../special/bessely0/benchmark/benchmark.native.js | 7 ++++--- .../base/special/bessely0/benchmark/c/benchmark.c | 9 ++++++--- .../special/bessely0/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../special/bessely0/benchmark/c/native/benchmark.c | 9 ++++++--- .../@stdlib/math/base/special/bessely0/test/test.js | 6 +++--- .../base/special/bessely1/benchmark/benchmark.js | 7 ++++--- .../base/special/bessely1/benchmark/c/benchmark.c | 9 ++++++--- .../special/bessely1/benchmark/c/cephes/benchmark.c | 9 ++++++--- .../@stdlib/math/base/special/bessely1/test/test.js | 6 +++--- .../math/base/special/beta/benchmark/benchmark.js | 9 +++++---- .../base/special/beta/benchmark/benchmark.native.js | 9 +++++---- .../special/beta/benchmark/c/cephes/benchmark.c | 13 ++++++++----- .../special/beta/benchmark/c/native/benchmark.c | 13 ++++++++----- .../@stdlib/math/base/special/beta/test/test.js | 8 ++++---- 27 files changed, 132 insertions(+), 84 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.js index dfc0412ae71e..78cd38a74435 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.js @@ -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 j0 = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100000.0 ) - 0.0; - y = j0( x ); + y = j0( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.native.js index 8e98bee0f578..8f860019119f 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 100000.0 ) - 0.0; - y = j0( x ); + y = j0( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/benchmark.c index a5225b15622a..d743fb9b1500 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/benchmark.c @@ -100,16 +100,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = j0( x ); + y = j0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/cephes/benchmark.c index c857e91da331..66a80b9135ef 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/cephes/benchmark.c @@ -94,16 +94,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = j0( x ); + y = j0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c index fb6e255fb836..47b7e1b2f37e 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c @@ -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 ] = ( 100000.0 * rand_double() ) - 0.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 100000.0 * rand_double() ) - 0.0; - y = stdlib_base_besselj0( x ); + y = stdlib_base_besselj0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/test/test.js b/lib/node_modules/@stdlib/math/base/special/besselj0/test/test.js index 5ce97679d8e0..c5ce285453e8 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/test/test.js @@ -319,7 +319,7 @@ tape( 'the function is an even function (f(x) = f(-x))', function test( t ) { tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v = j0( NaN ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.js index 75ca49eaa217..12ec22f5c46e 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.js @@ -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 j1 = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100000.0 ) - 0.0; - y = j1( x ); + y = j1( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.native.js index e33590ec12e7..86da1bfc49f2 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 100000.0 ) - 0.0; - y = j1( x ); + y = j1( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/benchmark.c index cb943e76334e..e3cd97a7ae37 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/benchmark.c @@ -100,16 +100,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = j1( x ); + y = j1( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/cephes/benchmark.c index b1606fbdbb85..73b74fd765cc 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/cephes/benchmark.c @@ -94,16 +94,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = j1( x ); + y = j1( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c index 32dbd0f894ef..17793127443b 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c @@ -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 ] = ( 100000.0 * rand_double() ) - 0.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 100000.0 * rand_double() ) - 0.0; - y = stdlib_base_besselj1( x ); + y = stdlib_base_besselj1( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js index fd296f3fe2ca..a46c3d5d52c7 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/test/test.js @@ -319,7 +319,7 @@ tape( 'the function is an odd function (f(x) = -f(-x))', function test( t ) { tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v = j1( NaN ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.js index e01a94fe59d3..2d793deb859b 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.js @@ -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 y0 = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100000.0 ) - 0.0; - y = y0( x ); + y = y0( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.native.js index 3c66eb27156b..a2d00f840658 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 100000.0 ) - 0.0; - y = y0( x ); + y = y0( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/benchmark.c index 0382a493d9d0..a43fa80b942b 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/benchmark.c @@ -100,16 +100,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = y0( x ); + y = y0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/cephes/benchmark.c index 869c396e193d..dfae9da6bfd9 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/cephes/benchmark.c @@ -94,16 +94,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = y0( x ); + y = y0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c index 4d283dc99378..f656321ff395 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c @@ -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 ] = ( 100000.0 * rand_double() ) - 0.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 100000.0 * rand_double() ) - 0.0; - y = stdlib_base_bessely0( x ); + y = stdlib_base_bessely0( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js index 31f3350c1100..f7b9c1d79978 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/test/test.js @@ -266,7 +266,7 @@ tape( 'the function returns `NaN` for negative numbers', function test( t ) { for ( i = 0; i < 1000; i++ ) { x = -( randu() * 100.0 ) - EPS; v = y0( x ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); } t.end(); }); @@ -279,7 +279,7 @@ tape( 'the function returns `-Infintiy` if provided `0.0`', function test( t ) { tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v = y0( NaN ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -291,6 +291,6 @@ tape( 'the function returns `0.0` if provided `+infinity`', function test( t ) { tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) { var v = y0( NINF ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/benchmark.js index d6089a2d98b5..a9a084661354 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/benchmark.js @@ -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 y1 = require( './../lib' ); @@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 100, 0.0, 100000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*100000.0 ) - 0.0; - y = y1( x ); + y = y1( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/benchmark.c index a130001cc91d..77072dac01b8 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/benchmark.c @@ -100,16 +100,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = y1( x ); + y = y1( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/cephes/benchmark.c index c172e1b86c9b..df5362df8822 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely1/benchmark/c/cephes/benchmark.c @@ -94,16 +94,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 ] = rand_double() * 100000.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = rand_double() * 100000.0; - y = y1( x ); + y = y1( x[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bessely1/test/test.js b/lib/node_modules/@stdlib/math/base/special/bessely1/test/test.js index 8ccb327be333..7344bdfe2bba 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely1/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/bessely1/test/test.js @@ -256,7 +256,7 @@ tape( 'the function returns `NaN` for negative numbers', function test( t ) { for ( i = 0; i < 1000; i++ ) { x = -( randu() * 100.0 ) - EPS; v = y1( x ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); } t.end(); }); @@ -269,7 +269,7 @@ tape( 'the function returns `-Infinity` if provided `0`', function test( t ) { tape( 'the function returns `NaN` if provided `NaN`', function test( t ) { var v = y1( NaN ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -281,6 +281,6 @@ tape( 'the function returns `0.0` if provided `+infinity`', function test( t ) { tape( 'the function returns `NaN` if provided `-infinity`', function test( t ) { var v = y1( NINF ); - t.equal( isnan( v ), true, 'returns NaN' ); + t.equal( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.js index 1d36e4549170..027e4e63034a 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.js @@ -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 beta = require( './../lib' ); @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = uniform( 100, 0.0, 1000.0 ); + y = uniform( 100, 0.0, 1000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 0.0; - y = ( randu()*1000.0 ) - 0.0; - z = beta( x, y ); + z = beta( x[ i % x.length ], y[ i % y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.native.js index 4a0b4a47ab57..82775a1178c9 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/beta/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; + x = uniform( 100, 0.0, 1000.0 ); + y = uniform( 100, 0.0, 1000.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 1000.0 ) - 0.0; - y = ( randu() * 1000.0 ) - 0.0; - z = beta( x, y ); + z = beta( x[ i % x.length ], y[ i % y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c index b8bd05e3906f..35350d33a269 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c @@ -94,18 +94,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 z; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1000.0*rand_double() ) + 0.0; + y[ i ]= ( 1000.0*rand_double() ) + 0.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) + 0.0; - y = ( 1000.0*rand_double() ) + 0.0; - z = beta( x, y ); + z = beta( x[ i%100 ], y[ i%100 ] ); if ( z != z ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c index c079551c2ecc..243f9dc764fb 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c @@ -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() * 1000.0 ) + 0.0 ); + y[ i ]= ( ( rand_double() * 1000.0 ) + 0.0 ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( ( rand_double() * 1000.0 ) + 0.0 ); - y = ( ( rand_double() * 1000.0 ) + 0.0 ); - r = stdlib_base_beta( x, y ); + r = stdlib_base_beta( x[ i%100 ], y[ i%100 ] ); if ( r != r ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/beta/test/test.js b/lib/node_modules/@stdlib/math/base/special/beta/test/test.js index f7ba097da1b4..56b0c6d0a751 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/beta/test/test.js @@ -61,17 +61,17 @@ tape( 'main export is a function', function test( t ) { tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) { var val = beta( NaN, 2.0 ); - t.ok( isnan( val ), 'returns NaN' ); + t.ok( isnan( val ), 'returns expected value' ); val = beta( 2.0, NaN ); - t.ok( isnan( val ), 'returns NaN' ); + t.ok( isnan( val ), 'returns expected value' ); t.end(); }); tape( 'the function returns `NaN` if provided negative values', function test( t ) { var val = beta( -2.0, 5.0 ); - t.ok( isnan( val ), 'returns NaN' ); + t.ok( isnan( val ), 'returns expected value' ); val = beta( 4.0, -3.0 ); - t.ok( isnan( val ), 'returns NaN' ); + t.ok( isnan( val ), 'returns expected value' ); t.end(); }); From 1ae4d0e1dd455318ddce867c4be4738378f7538a Mon Sep 17 00:00:00 2001 From: saurabhraghuvanshii Date: Wed, 26 Feb 2025 21:34:40 +0530 Subject: [PATCH 2/2] chore: address comments change --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: failed --- --- .../math/base/special/besselj0/benchmark/c/native/benchmark.c | 2 +- .../math/base/special/besselj1/benchmark/c/native/benchmark.c | 2 +- .../math/base/special/bessely0/benchmark/c/native/benchmark.c | 2 +- .../math/base/special/beta/benchmark/c/cephes/benchmark.c | 4 ++-- .../math/base/special/beta/benchmark/c/native/benchmark.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c index 47b7e1b2f37e..d0f7d405c547 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj0/benchmark/c/native/benchmark.c @@ -97,7 +97,7 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 100000.0 * rand_double() ) - 0.0; + x[ i ] = 100000.0 * rand_double(); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c index 17793127443b..9194bb2d406b 100644 --- a/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/besselj1/benchmark/c/native/benchmark.c @@ -97,7 +97,7 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 100000.0 * rand_double() ) - 0.0; + x[ i ] = 100000.0 * rand_double(); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c index f656321ff395..09dde22587ff 100644 --- a/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bessely0/benchmark/c/native/benchmark.c @@ -97,7 +97,7 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 100000.0 * rand_double() ) - 0.0; + x[ i ] = 100000.0 * rand_double(); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c index 35350d33a269..8433414901a4 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/cephes/benchmark.c @@ -102,8 +102,8 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( 1000.0*rand_double() ) + 0.0; - y[ i ]= ( 1000.0*rand_double() ) + 0.0; + x[ i ] = 1000.0 * rand_double(); + y[ i ]= 1000.0 * rand_double(); } t = tic(); diff --git a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c index 243f9dc764fb..54bfb839fa4c 100644 --- a/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/beta/benchmark/c/native/benchmark.c @@ -98,8 +98,8 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = ( ( rand_double() * 1000.0 ) + 0.0 ); - y[ i ]= ( ( rand_double() * 1000.0 ) + 0.0 ); + x[ i ] = rand_double() * 1000.0; + y[ i ]= rand_double() * 1000.0; } t = tic();