From c27c7aa0238d5b0e98fc200ba986210749c2ba2e Mon Sep 17 00:00:00 2001 From: vivek maurya Date: Sat, 11 Jan 2025 16:18:11 +0000 Subject: [PATCH 1/2] refactor: update math/base/assert/is-probability to follow latest project conventions --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../math/base/assert/is-probability/README.md | 11 ++-- .../is-probability/benchmark/benchmark.js | 9 ++- .../benchmark/benchmark.native.js | 9 ++- .../benchmark/c/native/benchmark.c | 9 ++- .../assert/is-probability/examples/index.js | 11 ++-- .../base/assert/is-probability/manifest.json | 34 +++++++++- .../base/assert/is-probability/src/addon.c | 65 +++---------------- .../base/assert/is-probability/test/test.js | 24 +++---- .../assert/is-probability/test/test.native.js | 24 +++---- 9 files changed, 98 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md b/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md index d909224a03e6..41d2d8f17c8d 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md @@ -56,17 +56,20 @@ bool = isProbability( NaN ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isProbability = require( '@stdlib/math/base/assert/is-probability' ); var bool; +var len; var x; var i; +len = 100; +x = discreteUniform( len, -1.0, 1.0 ); + for ( i = 0; i < 100; i++ ) { - x = ( randu()*2.0 ) - 1.0; - bool = isProbability( x ); - console.log( '%d is %s', x, ( bool ) ? 'a probability' : 'not a probability' ); + bool = isProbability( x[ i ] ); + console.log( '%d is %s', x[ i ], ( bool ) ? 'a probability' : 'not a probability' ); } ``` diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js index eba9ad9aca6e..a7dd581fe420 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; var isProbability = require( './../lib' ); @@ -30,14 +30,17 @@ var isProbability = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { + var len; var x; var y; var i; + len = 100; + x = discreteUniform( len, 1.0, -1.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*2.0 ) - 0.0; - y = isProbability( x ); + y = isProbability( x[ i % len ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js index 04cef48026c3..2d516d1347e8 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -39,14 +39,17 @@ var opts = { // MAIN // bench( pkg+'::native', opts, function benchmark( b ) { + var len; var x; var y; var i; + len = 100; + x = discreteUniform( len, -1.0, 1.0 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*2.0 ) - 0.0; - y = isProbability( x ); + y = isProbability( x[ i % len ] ); if ( typeof y !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/c/native/benchmark.c index 05b22e77a77b..0fd4ee800ee2 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/c/native/benchmark.c @@ -92,15 +92,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double t; bool b; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double() * 2.0 ) - 1.0;; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double() * 2.0 ) - 0.0; - b = stdlib_base_is_probability( x ); + b = stdlib_base_is_probability( x[ i % 100 ] ); if ( b != true && b != false ) { printf( "should return either true or false\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js index 4b2fc5c08395..2b1330e48f16 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js @@ -18,15 +18,18 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isProbability = require( './../lib' ); var bool; +var len; var x; var i; +len = 100; +x = discreteUniform( len, -1.0, 1.0 ); + for ( i = 0; i < 100; i++ ) { - x = ( randu()*2.0 ) - 1.0; - bool = isProbability( x ); - console.log( '%d is %s', x, ( bool ) ? 'a probability' : 'not a probability' ); + bool = isProbability( x[ i ] ); + console.log( '%d is %s', x[ i ], ( bool ) ? 'a probability' : 'not a probability' ); } diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/manifest.json b/lib/node_modules/@stdlib/math/base/assert/is-probability/manifest.json index 04e61e361caa..9d74cf717f8c 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/manifest.json +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,36 @@ ], "confs": [ { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/create-int32", + "@stdlib/napi/export" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", "src": [ "./src/main.c" ], diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/src/addon.c b/lib/node_modules/@stdlib/math/base/assert/is-probability/src/addon.c index 230719980644..c60b755fd9a9 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/src/addon.c @@ -17,9 +17,12 @@ */ #include "stdlib/math/base/assert/is_probability.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/create_int32.h" +#include "stdlib/napi/export.h" #include #include -#include /** * Receives JavaScript callback invocation data. @@ -29,60 +32,10 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Get callback arguments: - size_t argc = 1; - napi_value argv[ 1 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - // Check whether we were provided the correct number of arguments: - if ( argc < 1 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 1 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - bool result = stdlib_base_is_probability( x ); - - napi_value v; - status = napi_create_int32( env, (int32_t)result, &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Initializes a Node-API module. -* -* @param env environment under which the function is invoked -* @param exports exports object -* @return main export -*/ -static napi_value init( napi_env env, napi_value exports ) { - napi_value fcn; - napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_probability( x ), out ); + return out; } -NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.js index 3e8a7e51d869..7a5ef76b57e0 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.js @@ -40,9 +40,9 @@ tape( 'the function returns `false` if provided a number less than `0.0`', funct var x; var i; for ( i = 0; i < 1000; i++ ) { - x = -1.0 - ( randu()*1000.0 ); + x = -1.0 - ( randu() * 1000.0 ); bool = isProbability( x ); - t.equal( bool, false, 'returns false when provided '+x ); + t.equal( bool, false, 'returns expected value when provided '+x ); } t.end(); }); @@ -52,9 +52,9 @@ tape( 'the function returns `false` if provided a number greater than `1.0`', fu var x; var i; for ( i = 0; i < 1000; i++ ) { - x = ( randu()*1000.0 ) + 2.0; + x = ( randu() * 1000.0 ) + 2.0; bool = isProbability( x ); - t.equal( bool, false, 'returns false when provided '+x ); + t.equal( bool, false, 'returns expected value when provided '+x ); } t.end(); }); @@ -66,34 +66,34 @@ tape( 'the function returns `true` if provided a probability', function test( t for ( i = 0; i < 1000; i++ ) { x = randu(); bool = isProbability( x ); - t.equal( bool, true, 'returns true when provided '+x ); + t.equal( bool, true, 'returns expected value when provided '+x ); } t.end(); }); tape( 'the function returns `true` if provided `+-0`', function test( t ) { - t.equal( isProbability( 0.0 ), true, 'returns true' ); - t.equal( isProbability( -0.0 ), true, 'returns true' ); + t.equal( isProbability( 0.0 ), true, 'returns expected value' ); + t.equal( isProbability( -0.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `true` if provided `1`', function test( t ) { - t.equal( isProbability( 1.0 ), true, 'returns true' ); + t.equal( isProbability( 1.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `+infinity`', function test( t ) { - t.equal( isProbability( PINF ), false, 'returns false' ); + t.equal( isProbability( PINF ), false, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `-infinity`', function test( t ) { - t.equal( isProbability( NINF ), false, 'returns false' ); + t.equal( isProbability( NINF ), false, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `NaN`', function test( t ) { - t.equal( isProbability( NaN ), false, 'returns false' ); - t.equal( isProbability( 0.0/0.0 ), false, 'returns false' ); + t.equal( isProbability( NaN ), false, 'returns expected value' ); + t.equal( isProbability( 0.0 / 0.0 ), false, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.native.js index a8d18fbcd613..a8022bf23cb3 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/test/test.native.js @@ -49,9 +49,9 @@ tape( 'the function returns `false` if provided a number less than `0.0`', opts, var x; var i; for ( i = 0; i < 1000; i++ ) { - x = -1.0 - ( randu()*1000.0 ); + x = -1.0 - ( randu() * 1000.0 ); bool = isProbability( x ); - t.equal( bool, false, 'returns false when provided '+x ); + t.equal( bool, false, 'returns expected value when provided '+x ); } t.end(); }); @@ -61,9 +61,9 @@ tape( 'the function returns `false` if provided a number greater than `1.0`', op var x; var i; for ( i = 0; i < 1000; i++ ) { - x = ( randu()*1000.0 ) + 2.0; + x = ( randu() * 1000.0 ) + 2.0; bool = isProbability( x ); - t.equal( bool, false, 'returns false when provided '+x ); + t.equal( bool, false, 'returns expected value when provided '+x ); } t.end(); }); @@ -75,34 +75,34 @@ tape( 'the function returns `true` if provided a probability', opts, function te for ( i = 0; i < 1000; i++ ) { x = randu(); bool = isProbability( x ); - t.equal( bool, true, 'returns true when provided '+x ); + t.equal( bool, true, 'returns expected value when provided '+x ); } t.end(); }); tape( 'the function returns `true` if provided `+-0`', opts, function test( t ) { - t.equal( isProbability( 0.0 ), true, 'returns true' ); - t.equal( isProbability( -0.0 ), true, 'returns true' ); + t.equal( isProbability( 0.0 ), true, 'returns expected value' ); + t.equal( isProbability( -0.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `true` if provided `1`', opts, function test( t ) { - t.equal( isProbability( 1.0 ), true, 'returns true' ); + t.equal( isProbability( 1.0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `+infinity`', opts, function test( t ) { - t.equal( isProbability( PINF ), false, 'returns false' ); + t.equal( isProbability( PINF ), false, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `-infinity`', opts, function test( t ) { - t.equal( isProbability( NINF ), false, 'returns false' ); + t.equal( isProbability( NINF ), false, 'returns expected value' ); t.end(); }); tape( 'the function returns `false` if provided `NaN`', opts, function test( t ) { - t.equal( isProbability( NaN ), false, 'returns false' ); - t.equal( isProbability( 0.0/0.0 ), false, 'returns false' ); + t.equal( isProbability( NaN ), false, 'returns expected value' ); + t.equal( isProbability( 0.0 / 0.0 ), false, 'returns expected value' ); t.end(); }); From 5316c0b34633fbe9286635757060b3e46470fe33 Mon Sep 17 00:00:00 2001 From: vivek maurya Date: Sat, 11 Jan 2025 16:33:40 +0000 Subject: [PATCH 2/2] refactor: update math/base/assert/is-probability to follow latest project conventions --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/math/base/assert/is-probability/README.md | 4 ++-- .../math/base/assert/is-probability/benchmark/benchmark.js | 4 ++-- .../base/assert/is-probability/benchmark/benchmark.native.js | 4 ++-- .../@stdlib/math/base/assert/is-probability/examples/index.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md b/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md index 41d2d8f17c8d..d93d2a7ba704 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/README.md @@ -56,7 +56,7 @@ bool = isProbability( NaN ); ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isProbability = require( '@stdlib/math/base/assert/is-probability' ); var bool; @@ -65,7 +65,7 @@ var x; var i; len = 100; -x = discreteUniform( len, -1.0, 1.0 ); +x = uniform( len, -1.0, 1.0 ); for ( i = 0; i < 100; i++ ) { bool = isProbability( x[ i ] ); diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js index a7dd581fe420..d8aa7b920c5f 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; var isProbability = require( './../lib' ); @@ -36,7 +36,7 @@ bench( pkg, function benchmark( b ) { var i; len = 100; - x = discreteUniform( len, 1.0, -1.0 ); + x = uniform( len, 1.0, -1.0 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js index 2d516d1347e8..f839abf3e90f 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -45,7 +45,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { var i; len = 100; - x = discreteUniform( len, -1.0, 1.0 ); + x = uniform( len, -1.0, 1.0 ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js b/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js index 2b1330e48f16..67cc396d15a2 100644 --- a/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/assert/is-probability/examples/index.js @@ -18,7 +18,7 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isProbability = require( './../lib' ); var bool; @@ -27,7 +27,7 @@ var x; var i; len = 100; -x = discreteUniform( len, -1.0, 1.0 ); +x = uniform( len, -1.0, 1.0 ); for ( i = 0; i < 100; i++ ) { bool = isProbability( x[ i ] );