From 0dc5f6edb54618a8249a3db3b8c20ca003e2e834 Mon Sep 17 00:00:00 2001 From: hrshya Date: Wed, 19 Mar 2025 01:09:20 +0530 Subject: [PATCH 1/5] bench: update random value generation --- .../special/flipsign/benchmark/benchmark.js | 9 ++--- .../flipsign/benchmark/benchmark.native.js | 7 ++-- .../flipsign/benchmark/c/native/benchmark.c | 13 ++++--- .../math/base/special/flipsign/lib/main.js | 2 +- .../math/base/special/flipsign/test/test.js | 36 +++++++++---------- .../base/special/flipsign/test/test.native.js | 36 +++++++++---------- 6 files changed, 54 insertions(+), 49 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js index 27869c571d9c..90255db0f6d7 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/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 flipsign = require( './../lib' ); @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = uniform( 100.0, -5.0e6, 5.0e6 ); + y = uniform( 100.0, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1.0e7 ) - 5.0e6; - y = ( randu()*1.0e7 ) - 5.0e6; - z = flipsign( x, y ); + z = flipsign( 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/flipsign/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js index ea846d2e175b..ff1d1ddfae2a 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js @@ -44,11 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; + x = uniform( 100.0, -5.0e6, 5.0e6 ); + y = uniform( 100.0, -5.0e6, 5.0e6 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1.0e7 ) - 5.0e6; - y = ( randu()*1.0e7 ) - 5.0e6; - z = flipsign( x, y ); + z = flipsign( x[ i%x.length ], y[ i%x.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/c/native/benchmark.c index bcc9d9ee4795..1c19caa65ba2 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/c/native/benchmark.c @@ -91,17 +91,20 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; - double y; + double x[ 100 ]; + double y[ 100 ]; double z; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 1000.0*rand_double() ) - 500.0; + y[ i ] = ( 1000.0*rand_double() ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 1000.0*rand_double() ) - 500.0; - y = ( 1000.0*rand_double() ) - 500.0; - z = stdlib_base_flipsign( x, y ); + z = stdlib_base_flipsign( 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/flipsign/lib/main.js b/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js index 8599d656fc7d..19c4ad1fd531 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js @@ -23,7 +23,7 @@ var SIGN_MASK = require( '@stdlib/constants/float64/high-word-sign-mask' ); var toWords = require( '@stdlib/number/float64/base/to-words' ); var getHighWord = require( '@stdlib/number/float64/base/get-high-word' ); -var fromWords = require( '@stdlib/number/float64/base/from-words' ); +var fromWords = require( '@stdlib/number/float64/base/from-word' ); // VARIABLES // diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.js b/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.js index 38d068fd9a46..5dce63ca3d72 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.js @@ -63,10 +63,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', function test( t ) { var z; z = flipsign( NaN, -1.0 ); - t.equal( isnan( z ), true, 'returns NaN' ); + t.equal( isnan( z ), true, 'returns expected value' ); z = flipsign( NaN, 1.0 ); - t.equal( isnan( z ), true, 'returns NaN' ); + t.equal( isnan( z ), true, 'returns expected value' ); t.end(); }); @@ -75,10 +75,10 @@ tape( 'if `y` is `NaN`, the function could (theoretically) return either a posit var z; z = flipsign( -1.0, NaN ); - t.equal( isnan( z ), false, 'does not return NaN' ); + t.equal( isnan( z ), false, 'returns expected value' ); z = flipsign( 1.0, NaN ); - t.equal( isnan( z ), false, 'does not return NaN' ); + t.equal( isnan( z ), false, 'returns expected value' ); t.end(); }); @@ -87,10 +87,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', function var z; z = flipsign( PINF, -1.0 ); - t.equal( z, NINF, 'returns -infinity' ); + t.equal( z, NINF, 'returns expected value' ); z = flipsign( PINF, 1.0 ); - t.equal( z, PINF, 'returns +infinity' ); + t.equal( z, PINF, 'returns expected value' ); t.end(); }); @@ -99,10 +99,10 @@ tape( 'if `y` is `+infinity`, the function returns `x`', function test( t ) { var z; z = flipsign( -1.0, PINF ); - t.equal( z, -1.0, 'returns -1' ); + t.equal( z, -1.0, 'returns expected value' ); z = flipsign( 1.0, PINF ); - t.equal( z, 1.0, 'returns +1' ); + t.equal( z, 1.0, 'returns expected value' ); t.end(); }); @@ -111,10 +111,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', function var z; z = flipsign( NINF, -1.0 ); - t.equal( z, PINF, 'returns +infinity' ); + t.equal( z, PINF, 'returns expected value' ); z = flipsign( NINF, 1.0 ); - t.equal( z, NINF, 'returns -infinity' ); + t.equal( z, NINF, 'returns expected value' ); t.end(); }); @@ -123,10 +123,10 @@ tape( 'if `y` is `-infinity`, the function returns `-x`', function test( t ) { var z; z = flipsign( -1.0, NINF ); - t.equal( z, +1.0, 'returns +1' ); + t.equal( z, +1.0, 'returns expected value' ); z = flipsign( 1.0, NINF ); - t.equal( z, -1.0, 'returns -1' ); + t.equal( z, -1.0, 'returns expected value' ); t.end(); }); @@ -138,10 +138,10 @@ tape( 'the function supports using `+-0` to flip a sign', function test( t ) { x = 3.14; z = flipsign( x, 0.0 ); - t.equal( z, 3.14, 'returns +3.14' ); + t.equal( z, 3.14, 'returns expected value' ); z = flipsign( x, -0.0 ); - t.equal( z, -3.14, 'returns -3.14' ); + t.equal( z, -3.14, 'returns expected value' ); t.end(); }); @@ -150,16 +150,16 @@ tape( 'the function supports `x` being `+-0`', function test( t ) { var z; z = flipsign( -0.0, 1.0 ); - t.equal( isNegativeZero( z ), true, 'returns -0' ); + t.equal( isNegativeZero( z ), true, 'returns expected value' ); z = flipsign( -0.0, -1.0 ); - t.equal( isPositiveZero( z ), true, 'returns +0' ); + t.equal( isPositiveZero( z ), true, 'returns expected value' ); z = flipsign( 0.0, 1.0 ); - t.equal( isPositiveZero( z ), true, 'returns +0' ); + t.equal( isPositiveZero( z ), true, 'returns expected value' ); z = flipsign( 0.0, -1.0 ); - t.equal( isNegativeZero( z ), true, 'returns -0' ); + t.equal( isNegativeZero( z ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.native.js index f4cbf1508eb4..9f4cdfa7b942 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/test/test.native.js @@ -72,10 +72,10 @@ tape( 'if `x` is `NaN`, the function returns `NaN`', opts, function test( t ) { var z; z = flipsign( NaN, -1.0 ); - t.equal( isnan( z ), true, 'returns NaN' ); + t.equal( isnan( z ), true, 'returns expected value' ); z = flipsign( NaN, 1.0 ); - t.equal( isnan( z ), true, 'returns NaN' ); + t.equal( isnan( z ), true, 'returns expected value' ); t.end(); }); @@ -84,10 +84,10 @@ tape( 'if `y` is `NaN`, the function could (theoretically) return either a posit var z; z = flipsign( -1.0, NaN ); - t.equal( isnan( z ), false, 'does not return NaN' ); + t.equal( isnan( z ), false, 'returns expected value' ); z = flipsign( 1.0, NaN ); - t.equal( isnan( z ), false, 'does not return NaN' ); + t.equal( isnan( z ), false, 'returns expected value' ); t.end(); }); @@ -96,10 +96,10 @@ tape( 'if `x` is `+infinity`, the function returns an infinite number', opts, fu var z; z = flipsign( PINF, -1.0 ); - t.equal( z, NINF, 'returns -infinity' ); + t.equal( z, NINF, 'returns expected value' ); z = flipsign( PINF, 1.0 ); - t.equal( z, PINF, 'returns +infinity' ); + t.equal( z, PINF, 'returns expected value' ); t.end(); }); @@ -108,10 +108,10 @@ tape( 'if `y` is `+infinity`, the function returns `x`', opts, function test( t var z; z = flipsign( -1.0, PINF ); - t.equal( z, -1.0, 'returns -1' ); + t.equal( z, -1.0, 'returns expected value' ); z = flipsign( 1.0, PINF ); - t.equal( z, 1.0, 'returns +1' ); + t.equal( z, 1.0, 'returns expected value' ); t.end(); }); @@ -120,10 +120,10 @@ tape( 'if `x` is `-infinity`, the function returns an infinite number', opts, fu var z; z = flipsign( NINF, -1.0 ); - t.equal( z, PINF, 'returns +infinity' ); + t.equal( z, PINF, 'returns expected value' ); z = flipsign( NINF, 1.0 ); - t.equal( z, NINF, 'returns -infinity' ); + t.equal( z, NINF, 'returns expected value' ); t.end(); }); @@ -132,10 +132,10 @@ tape( 'if `y` is `-infinity`, the function returns `-x`', opts, function test( t var z; z = flipsign( -1.0, NINF ); - t.equal( z, +1.0, 'returns +1' ); + t.equal( z, +1.0, 'returns expected value' ); z = flipsign( 1.0, NINF ); - t.equal( z, -1.0, 'returns -1' ); + t.equal( z, -1.0, 'returns expected value' ); t.end(); }); @@ -147,10 +147,10 @@ tape( 'the function supports using `+-0` to flip a sign', opts, function test( t x = 3.14; z = flipsign( x, 0.0 ); - t.equal( z, 3.14, 'returns +3.14' ); + t.equal( z, 3.14, 'returns expected value' ); z = flipsign( x, -0.0 ); - t.equal( z, -3.14, 'returns -3.14' ); + t.equal( z, -3.14, 'returns expected value' ); t.end(); }); @@ -159,16 +159,16 @@ tape( 'the function supports `x` being `+-0`', opts, function test( t ) { var z; z = flipsign( -0.0, 1.0 ); - t.equal( isNegativeZero( z ), true, 'returns -0' ); + t.equal( isNegativeZero( z ), true, 'returns expected value' ); z = flipsign( -0.0, -1.0 ); - t.equal( isPositiveZero( z ), true, 'returns +0' ); + t.equal( isPositiveZero( z ), true, 'returns expected value' ); z = flipsign( 0.0, 1.0 ); - t.equal( isPositiveZero( z ), true, 'returns +0' ); + t.equal( isPositiveZero( z ), true, 'returns expected value' ); z = flipsign( 0.0, -1.0 ); - t.equal( isNegativeZero( z ), true, 'returns -0' ); + t.equal( isNegativeZero( z ), true, 'returns expected value' ); t.end(); }); From 8f5af381f7180da3a51b33667c264c387cd3d321 Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Wed, 19 Mar 2025 01:26:16 +0530 Subject: [PATCH 2/5] Update main.js Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js b/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js index 19c4ad1fd531..8599d656fc7d 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/lib/main.js @@ -23,7 +23,7 @@ var SIGN_MASK = require( '@stdlib/constants/float64/high-word-sign-mask' ); var toWords = require( '@stdlib/number/float64/base/to-words' ); var getHighWord = require( '@stdlib/number/float64/base/get-high-word' ); -var fromWords = require( '@stdlib/number/float64/base/from-word' ); +var fromWords = require( '@stdlib/number/float64/base/from-words' ); // VARIABLES // From 4240a1601c528526badf49e44f5054ff7b83ccc0 Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Wed, 19 Mar 2025 01:32:47 +0530 Subject: [PATCH 3/5] Update benchmark.native.js Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- .../math/base/special/flipsign/benchmark/benchmark.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js index ff1d1ddfae2a..c30af3c23e35 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/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; From a76f9f2a4e2ec57a08f13f039c8dd877a41eb6df Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Wed, 19 Mar 2025 01:42:06 +0530 Subject: [PATCH 4/5] Update benchmark.js Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- .../@stdlib/math/base/special/flipsign/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js index 90255db0f6d7..25cca068facb 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.js @@ -35,8 +35,8 @@ bench( pkg, function benchmark( b ) { var z; var i; - x = uniform( 100.0, -5.0e6, 5.0e6 ); - y = uniform( 100.0, -5.0e6, 5.0e6 ); + x = uniform( 100, -5.0e6, 5.0e6 ); + y = uniform( 100, -5.0e6, 5.0e6 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { From 5c12d3d4d875deefe2c313e78c06839322f906b5 Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Wed, 19 Mar 2025 01:42:37 +0530 Subject: [PATCH 5/5] Update benchmark.native.js Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- .../math/base/special/flipsign/benchmark/benchmark.native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js index c30af3c23e35..d12b7b173125 100644 --- a/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/flipsign/benchmark/benchmark.native.js @@ -44,8 +44,8 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; - x = uniform( 100.0, -5.0e6, 5.0e6 ); - y = uniform( 100.0, -5.0e6, 5.0e6 ); + x = uniform( 100, -5.0e6, 5.0e6 ); + y = uniform( 100, -5.0e6, 5.0e6 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) {