From 256a13250faddba766fcfc5aab555efbadbb7669 Mon Sep 17 00:00:00 2001 From: hrshya Date: Thu, 20 Mar 2025 22:12:06 +0530 Subject: [PATCH 1/3] bench: update random value generation --- .../base/special/max/benchmark/benchmark.js | 16 +++---- .../special/max/benchmark/benchmark.native.js | 9 ++-- .../base/special/max/benchmark/c/benchmark.c | 13 +++--- .../max/benchmark/c/native/benchmark.c | 13 +++--- .../math/base/special/max/test/test.js | 20 ++++----- .../math/base/special/max/test/test.native.js | 20 ++++----- .../base/special/maxf/benchmark/benchmark.js | 10 +++-- .../maxf/benchmark/benchmark.native.js | 10 +++-- .../base/special/maxn/benchmark/benchmark.js | 14 ++++--- .../base/special/maxn/benchmark/c/benchmark.c | 13 +++--- .../math/base/special/maxn/test/test.js | 42 +++++++++---------- 11 files changed, 101 insertions(+), 79 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.js index 96f0b265b814..14fa52478b52 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/max/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 max = require( './../lib' ); @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = uniform( 100, -500.0, 500.0 ); + y = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = ( randu()*1000.0 ) - 500.0; - z = max( x, y ); + z = max( x[ i%x.length ], y[ i%y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } @@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) { var z; var i; + x = uniform( 100, -500.0, 500.0 ); + y = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = ( randu()*1000.0 ) - 500.0; - z = Math.max( x, y ); // eslint-disable-line stdlib/no-builtin-math + z = Math.max( x[ i%x.length ], y[ i%y.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js index 14d4e921b2c6..e85b5a50c7cb 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/max/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, -100.0, 100.0 ); + y = uniform( 100, -100.0, 100.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*200.0 ) - 100.0; - y = ( randu()*200.0 ) - 100.0; - z = max( x, y ); + z = max( 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/max/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c index 3fe643841fae..3eeb5300bbd5 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/benchmark.c @@ -90,17 +90,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 = fmax( x, y ); + z = fmax( 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/max/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c index 8aa23811087b..0430b7645eee 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c @@ -92,16 +92,19 @@ static double rand_double( void ) { static double benchmark( void ) { double elapsed; double t; - double x; - double y; + double x[ 100 ]; + double y[ 100 ]; double z; int i; - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { + for ( i = 0; i < 100; i++ ) { x = ( 200.0*rand_double() ) - 100.0; y = ( 200.0*rand_double() ) - 100.0; - z = stdlib_base_max( x, y ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + z = stdlib_base_max( 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/max/test/test.js b/lib/node_modules/@stdlib/math/base/special/max/test/test.js index ea1869c0b23b..f165d8326282 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/max/test/test.js @@ -40,10 +40,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) { var v; v = max( NaN, 3.14 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = max( 3.14, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -52,10 +52,10 @@ tape( 'the function returns `+Infinity` if provided `+Infinity`', function test( var v; v = max( PINF, 3.14 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); v = max( 3.14, PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); @@ -64,16 +64,16 @@ tape( 'the function returns a correctly signed zero', function test( t ) { var v; v = max( +0.0, -0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = max( -0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = max( -0.0, -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = max( +0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -82,10 +82,10 @@ tape( 'the function returns the maximum value', function test( t ) { var v; v = max( 4.2, 3.14 ); - t.strictEqual( v, 4.2, 'returns max value' ); + t.strictEqual( v, 4.2, 'returns expected value' ); v = max( -4.2, 3.14 ); - t.strictEqual( v, 3.14, 'returns max value' ); + t.strictEqual( v, 3.14, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js index 646b9e92539b..b3365ac98e1b 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/max/test/test.native.js @@ -49,10 +49,10 @@ tape( 'the function returns `NaN` if provided a `NaN`', opts, function test( t ) var v; v = max( NaN, 3.14 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = max( 3.14, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -61,10 +61,10 @@ tape( 'the function returns `Infinity` if provided `Infinity`', opts, function t var v; v = max( PINF, 3.14 ); - t.strictEqual( v, PINF, 'returns infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); v = max( 3.14, PINF ); - t.strictEqual( v, PINF, 'returns infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); @@ -73,16 +73,16 @@ tape( 'the function returns a correctly signed zero', opts, function test( t ) { var v; v = max( +0.0, -0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = max( -0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = max( -0.0, -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = max( +0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -91,10 +91,10 @@ tape( 'the function returns the maximum value', opts, function test( t ) { var v; v = max( 4.2, 3.14 ); - t.strictEqual( v, 4.2, 'returns max value' ); + t.strictEqual( v, 4.2, 'returns expected value' ); v = max( -4.2, 3.14 ); - t.strictEqual( v, 3.14, 'returns max value' ); + t.strictEqual( v, 3.14, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.js index b77d841b1ce6..67e4b0739a39 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pkg = require( './../package.json' ).name; var maxf = require( './../lib' ); @@ -35,8 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; - x = randu( 100, -100.0, 100.0 ); - y = randu( 100, -100.0, 100.0 ); + x = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); + y = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.native.js index 2286ad36f820..e34316fb2215 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/maxf/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -44,8 +44,12 @@ bench( pkg+'::native', opts, function benchmark( b ) { var z; var i; - x = randu( 100, -100.0, 100.0 ); - y = randu( 100, -100.0, 100.0 ); + x = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); + y = uniform( 100, -100.0, 100.0, { + 'dtype': 'float32' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js index e7b911ce871c..3768abb7996a 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) { var z; var i; + x = uniform( 100, -500.0, 500.0 ); + y = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = ( randu()*1000.0 ) - 500.0; - z = maxn( x, y ); + z = maxn( x[ i % x.length ], y[ i % y.length ] ); if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } @@ -58,11 +59,12 @@ bench( pkg+'::built-in', function benchmark( b ) { var z; var i; + x = uniform( 100, -500.0, 500.0 ); + y = uniform( 100, -500.0, 500.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*1000.0 ) - 500.0; - y = ( randu()*1000.0 ) - 500.0; - z = Math.max( x, y ); // eslint-disable-line stdlib/no-builtin-math + z = Math.max( x[ i % x.length ], y[ i % y.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnan( z ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/c/benchmark.c index 3fe643841fae..3eeb5300bbd5 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/c/benchmark.c @@ -90,17 +90,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 = fmax( x, y ); + z = fmax( 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/maxn/test/test.js b/lib/node_modules/@stdlib/math/base/special/maxn/test/test.js index 4e89edf05acf..046b10702629 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxn/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/maxn/test/test.js @@ -41,16 +41,16 @@ tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) { var v; v = maxn( NaN, 3.14 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = maxn( 3.14, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = maxn( NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = maxn( 3.14, 4.2, NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -59,16 +59,16 @@ tape( 'the function returns `+Infinity` if provided `+Infinity`', function test( var v; v = maxn( PINF, 3.14 ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); v = maxn( 3.14, PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); v = maxn( PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); v = maxn( 3.14, 4.2, PINF ); - t.strictEqual( v, PINF, 'returns +infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); t.end(); }); @@ -83,25 +83,25 @@ tape( 'the function returns a correctly signed zero', function test( t ) { var v; v = maxn( +0.0, -0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = maxn( -0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = maxn( -0.0, -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = maxn( +0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = maxn( -0.0 ); - t.strictEqual( isNegativeZero( v ), true, 'returns -0' ); + t.strictEqual( isNegativeZero( v ), true, 'returns expected value' ); v = maxn( +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); v = maxn( +0.0, -0.0, +0.0 ); - t.strictEqual( isPositiveZero( v ), true, 'returns +0' ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); }); @@ -110,22 +110,22 @@ tape( 'the function returns the maximum value', function test( t ) { var v; v = maxn( 4.2, 3.14 ); - t.strictEqual( v, 4.2, 'returns max value' ); + t.strictEqual( v, 4.2, 'returns expected value' ); v = maxn( -4.2, 3.14 ); - t.strictEqual( v, 3.14, 'returns max value' ); + t.strictEqual( v, 3.14, 'returns expected value' ); v = maxn( 3.14 ); - t.strictEqual( v, 3.14, 'returns max value' ); + t.strictEqual( v, 3.14, 'returns expected value' ); v = maxn( NINF ); - t.strictEqual( v, NINF, 'returns max value' ); + t.strictEqual( v, NINF, 'returns expected value' ); v = maxn( 4.2, 3.14, -1.0 ); - t.strictEqual( v, 4.2, 'returns max value' ); + t.strictEqual( v, 4.2, 'returns expected value' ); v = maxn( 3.14, 4.2, -1.0, -3.14 ); - t.strictEqual( v, 4.2, 'returns max value' ); + t.strictEqual( v, 4.2, 'returns expected value' ); t.end(); }); From c3b728fc620c869216d00a0c1028f2bc5230ea7c Mon Sep 17 00:00:00 2001 From: Harsh <149176984+hrshya@users.noreply.github.com> Date: Thu, 20 Mar 2025 22:31:47 +0530 Subject: [PATCH 2/3] fixes lint issue Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com> --- .../@stdlib/math/base/special/maxn/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js index 3768abb7996a..64114e9ecd3a 100644 --- a/lib/node_modules/@stdlib/math/base/special/maxn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/maxn/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 maxn = require( './../lib' ); From 707bb0dd29257828adc07478fc3402c1b0c43fe8 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 20 Mar 2025 18:15:52 -0700 Subject: [PATCH 3/3] bench: fix assignment Signed-off-by: Athan --- .../math/base/special/max/benchmark/c/native/benchmark.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c index 0430b7645eee..ee966ba3c803 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/max/benchmark/c/native/benchmark.c @@ -91,15 +91,15 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double t; double x[ 100 ]; double y[ 100 ]; + double t; double z; int i; for ( i = 0; i < 100; i++ ) { - x = ( 200.0*rand_double() ) - 100.0; - y = ( 200.0*rand_double() ) - 100.0; + x[ i ] = ( 200.0*rand_double() ) - 100.0; + y[ i ] = ( 200.0*rand_double() ) - 100.0; } t = tic();