From c74e75b8dbf5c127d82035747612f6b6a75cee86 Mon Sep 17 00:00:00 2001 From: saurabhraghuvanshii Date: Fri, 28 Feb 2025 03:20:36 +0530 Subject: [PATCH 1/2] bench: refactor random 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: 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 --- --- .../math/base/special/cabs/benchmark/c/benchmark.c | 13 ++++++++----- .../special/cabs/benchmark/c/native/benchmark.c | 13 ++++++++----- .../@stdlib/math/base/special/cabs/test/test.js | 6 +++--- .../math/base/special/cabs/test/test.native.js | 6 +++--- .../math/base/special/cabs2/benchmark/c/benchmark.c | 13 ++++++++----- .../special/cabs2/benchmark/c/native/benchmark.c | 13 ++++++++----- .../@stdlib/math/base/special/cabs2/test/test.js | 6 +++--- .../math/base/special/cabs2/test/test.native.js | 6 +++--- 8 files changed, 44 insertions(+), 32 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/benchmark.c index 21dd59f01c82..bbac57b85517 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/benchmark.c @@ -89,19 +89,22 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; double complex z; double elapsed; - double re; - double im; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0*rand_double() ) - 500.0; + im[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = re + im*I; + z = re[ i%100 ] + im[ i%100 ]*I; y = cabs( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c index 4d9dcd645842..27dfe98d43c8 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c @@ -92,20 +92,23 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; double elapsed; - double re; - double im; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0*rand_double() ) - 500.0; + im[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + stdlib_complex128_t z; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = stdlib_complex128( re, im ); + z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] ); y = stdlib_base_cabs( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js index 801b6e32937f..91f4794b4e4b 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.js @@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js index 4000a697045d..8cce5f7094c8 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs/test/test.native.js @@ -80,13 +80,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/benchmark.c index 4735e525d9e1..6ac7de6954ec 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/benchmark.c @@ -99,19 +99,22 @@ double cabs2( double complex z ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; double complex z; double elapsed; - double re; - double im; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0*rand_double() ) - 500.0; + im[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = re + im*I; + z = re[ i%100] + im[ i%100 ]*I; y = cabs2( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c index 3b7c869545f9..4fa2aac48cc1 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c @@ -92,20 +92,23 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; double elapsed; - double re; - double im; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0*rand_double() ) - 500.0; + im[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + stdlib_complex128_t z; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0*rand_double() ) - 500.0; - im = ( 1000.0*rand_double() ) - 500.0; - z = stdlib_complex128( re, im ); + z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] ); y = stdlib_base_cabs2( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.js index 8742cbd8ee97..d8d19330c9f6 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.js @@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs2( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs2( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs2( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.native.js index a2ac51442104..5a69718f5f9d 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs2/test/test.native.js @@ -80,13 +80,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs2( new Complex128( NaN, 3.0 ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs2( new Complex128( 5.0, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = cabs2( new Complex128( NaN, NaN ) ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); From 17ac94a76775045dbb348c817dd979b31bedd453 Mon Sep 17 00:00:00 2001 From: saurabhraghuvanshii Date: Fri, 28 Feb 2025 13:15:10 +0530 Subject: [PATCH 2/2] chore: refactor cabsf and cabs2f --- 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: 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 --- --- .../special/cabs/benchmark/c/native/benchmark.c | 2 +- .../special/cabs2/benchmark/c/native/benchmark.c | 2 +- .../base/special/cabs2f/benchmark/c/benchmark.c | 13 ++++++++----- .../special/cabs2f/benchmark/c/native/benchmark.c | 13 ++++++++----- .../@stdlib/math/base/special/cabs2f/test/test.js | 6 +++--- .../math/base/special/cabsf/benchmark/c/benchmark.c | 13 ++++++++----- .../special/cabsf/benchmark/c/native/benchmark.c | 13 ++++++++----- .../@stdlib/math/base/special/cabsf/test/test.js | 6 +++--- 8 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c index 27dfe98d43c8..b80610e1cef4 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs/benchmark/c/native/benchmark.c @@ -108,7 +108,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] ); + z = stdlib_complex128( re[ i%100 ], im[ i%100 ] ); y = stdlib_base_cabs( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c index 4fa2aac48cc1..f83aca8f6868 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2/benchmark/c/native/benchmark.c @@ -108,7 +108,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - z = stdlib_complex128( re[ i % 100 ], im[ i % 100 ] ); + z = stdlib_complex128( re[ i%100 ], im[ i%100 ] ); y = stdlib_base_cabs2( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/benchmark.c index 499af2bb548b..c2e825878319 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/benchmark.c @@ -99,19 +99,22 @@ float cabs2f( float complex z ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; float complex z; double elapsed; double t; - float re; - float im; float y; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + im[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0f*rand_float() ) - 500.0f; - im = ( 1000.0f*rand_float() ) - 500.0f; - z = re + im*I; + z = re[ i%100 ] + im[ i%100 ]*I; y = cabs2f( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c index 6a9e4a273010..1e95701e6980 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/benchmark/c/native/benchmark.c @@ -91,19 +91,22 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; float complex z; double elapsed; double t; - float re; - float im; float y; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + im[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0f*rand_float() ) - 500.0f; - im = ( 1000.0f*rand_float() ) - 500.0f; - z = re + im*I; + z = re[ i%100 ] + im[ i%100 ]*I; y = stdlib_base_cabs2f( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js index 5dafe7f9ffbc..8f80136351f3 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabs2f/test/test.js @@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabs2f( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = cabs2f( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); v = cabs2f( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/benchmark.c index 11edbf3f5125..bf6e6a769de2 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/benchmark.c @@ -89,19 +89,22 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; float complex z; double elapsed; double t; - float re; - float im; float y; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + im[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0f*rand_float() ) - 500.0f; - im = ( 1000.0f*rand_float() ) - 500.0f; - z = re + im*I; + z = re[ i%100 ] + im[ i%100 ]*I; y = cabsf( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/native/benchmark.c index daa1b62852ac..9d04101972f3 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/native/benchmark.c @@ -91,19 +91,22 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double re[ 100 ]; + double im[ 100 ]; float complex z; double elapsed; double t; - float re; - float im; float y; int i; + for ( i = 0; i < 100; i++ ) { + re[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + im[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - re = ( 1000.0f*rand_float() ) - 500.0f; - im = ( 1000.0f*rand_float() ) - 500.0f; - z = re + im*I; + z = re[ i%100 ] + im[ i%100 ]*I; y = stdlib_base_cabsf( z ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/math/base/special/cabsf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cabsf/test/test.js index 839c6cdb8971..c5e170a3059f 100644 --- a/lib/node_modules/@stdlib/math/base/special/cabsf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cabsf/test/test.js @@ -71,13 +71,13 @@ tape( 'if either the real or imaginary component is `NaN`, the function returns var v; v = cabsf( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'expected value' ); v = cabsf( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'expected value' ); v = cabsf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( v ), true, 'returns NaN' ); + t.strictEqual( isnanf( v ), true, 'expected value' ); t.end(); });