From 692afcb69e47de99d9675571503e6cc7a73dd1a7 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Fri, 27 Dec 2024 14:30:14 +0530 Subject: [PATCH 01/10] refactor: update `stats/base/dnanmeanpn` native addon from C++ to C PR-URL: https://github.com/stdlib-js/stdlib/pull/4110 Reviewed-by: Athan Reines --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- 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: passed - 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 --- --- .../stats/base/dnanmeanpn/include.gypi | 2 +- .../stats/base/dnanmeanpn/manifest.json | 39 +++++- .../@stdlib/stats/base/dnanmeanpn/src/addon.c | 43 +++++++ .../stats/base/dnanmeanpn/src/addon.cpp | 117 ------------------ 4 files changed, 82 insertions(+), 119 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanpn( N, X, stride ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp deleted file mode 100644 index 8c46b762906b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/stats/base/dnanmeanpn.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dnanmeanpn { - - /** - * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using a two-pass error correction algorithm. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dnanmeanpn( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dnanmeanpn( N, (double *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dnanmeanpn, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dnanmeanpn From cf34f9d592651bb88e6fa2d286454db40fee3e8c Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:22:55 +0530 Subject: [PATCH 02/10] feat: add C implementation for binomail logpmf --- 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: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - 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: passed - task: lint_c_examples status: passed - 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: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../base/dists/binomial/logpmf/README.md | 107 +++++++ .../binomial/logpmf/benchmark/benchmark.js | 17 +- .../logpmf/benchmark/benchmark.native.js | 74 +++++ .../binomial/logpmf/benchmark/c/Makefile | 146 +++++++++ .../binomial/logpmf/benchmark/c/benchmark.c | 143 +++++++++ .../base/dists/binomial/logpmf/binding.gyp | 170 ++++++++++ .../dists/binomial/logpmf/examples/c/Makefile | 146 +++++++++ .../binomial/logpmf/examples/c/example.c | 45 +++ .../base/dists/binomial/logpmf/include.gypi | 53 ++++ .../stdlib/stats/base/dists/binomial/logpmf.h | 38 +++ .../base/dists/binomial/logpmf/lib/native.js | 88 +++++ .../base/dists/binomial/logpmf/manifest.json | 96 ++++++ .../base/dists/binomial/logpmf/package.json | 3 + .../base/dists/binomial/logpmf/src/Makefile | 70 ++++ .../base/dists/binomial/logpmf/src/addon.c | 23 ++ .../base/dists/binomial/logpmf/src/main.c | 68 ++++ .../dists/binomial/logpmf/test/test.native.js | 300 ++++++++++++++++++ 17 files changed, 1583 insertions(+), 4 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md index 22da4e70062f..eb232872c292 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md @@ -152,6 +152,113 @@ for ( i = 0; i < 10; i++ ) { + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/binomial/logpmf.h" +``` + +#### stdlib_base_dists_binomial_logpmf( x, n, p ) + +Returns the natural logarithm of the [probability mass function][pmf] (PMF) for a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`. + +```c +double out = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 ); +// returns ~-1.583 +``` + +The function accepts the following arguments: + +- **x**: `[in] int` input value. +- **n**: `[in] int` number of trials. +- **p**: `[in] double` success probability. + +```c +double stdlib_base_dists_binomial_logpmf( const double x, const double n, const double p ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/binomial/logpmf.h" +#include "stdlib/math/base/special/ceil.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * (max - min) ); +} + +int main( void ) { + double n; + double p; + double x; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + n = stdlib_base_ceil( random_uniform( 0, 100 ) ); + p = random_uniform( 0, 1 ); + x = random_uniform( 0, 50 ); + y = stdlib_base_dists_binomial_logpmf( x, n, p ); + printf( "x: %lf, n: %lf, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); + } + + return 0; +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + @@ -217,6 +217,7 @@ double stdlib_base_dists_binomial_logpmf( const double x, const double n, const #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/special/ceil.h" #include +#include #include static double random_uniform( const double min, const double max ) { @@ -225,18 +226,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double n; + int32_t n; double p; - double x; + int32_t x; double y; int i; for ( i = 0; i < 25; i++ ) { - n = stdlib_base_ceil( random_uniform( 0, 100 ) ); - p = random_uniform( 0, 1 ); - x = random_uniform( 0, 50 ); + n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + p = random_uniform( 0.0, 1.0 ); + x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); y = stdlib_base_dists_binomial_logpmf( x, n, p ); - printf( "x: %lf, n: %lf, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); + printf( "x: %d, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js index 4afb5aee0c13..d51b7b3bed88 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); var ceil = require( '@stdlib/math/base/special/ceil' ); var randu = require( '@stdlib/random/base/randu' ); @@ -40,13 +41,13 @@ bench( pkg, function benchmark( b ) { var i; len = 100; - n = new Float64Array( len ); + n = new Int32Array( len ); p = new Float64Array( len ); - x = new Float64Array( len ); + x = new Int32Array( len ); for ( i = 0; i < len; i++ ) { n[ i ] = ceil( randu()*100.0 ); p[ i ] = randu(); - x[ i ] = randu()*50.0; + x[ i ] = ceil( randu()*50.0 ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js index ebffef2bd5f0..14c2a20dc99f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js @@ -22,6 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); +var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var ceil = require( '@stdlib/math/base/special/ceil' ); @@ -49,13 +50,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var i; len = 100; - n = new Float64Array( len ); + n = new Int32Array( len ); p = new Float64Array( len ); - x = new Float64Array( len ); + x = new Int32Array( len ); for ( i = 0; i < len; i++ ) { n[ i ] = ceil( randu()*100.0 ); p[ i ] = randu(); - x[ i ] = randu()*50.0; + x[ i ] = ceil( randu()*50.0 ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c index 2a4c80314576..9463361ba3b1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c @@ -19,6 +19,7 @@ #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/special/ceil.h" #include +#include #include #include #include @@ -94,17 +95,17 @@ static double random_uniform( const double min, const double max ) { */ static double benchmark( void ) { double elapsed; - double n[ 100 ]; + int32_t n[ 100 ]; double p[ 100 ]; - double x[ 100 ]; + int32_t x[ 100 ]; double y; double t; int i; for ( i = 0; i < 100; i++ ) { - n[ i ] = stdlib_base_ceil( random_uniform( 0, 100 ) ); - p[ i ] = random_uniform( 0, 1 ); - x[ i ] = random_uniform( 0, 50); + n[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + p[ i ] = random_uniform( 0.0, 1.0 ); + x[ i ] = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); } t = tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c index 135ead4092a3..71b28b0f536f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c @@ -19,6 +19,7 @@ #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/special/ceil.h" #include +#include #include static double random_uniform( const double min, const double max ) { @@ -27,18 +28,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double n; + int32_t n; double p; - double x; + int32_t x; double y; int i; for ( i = 0; i < 25; i++ ) { - n = stdlib_base_ceil( random_uniform( 0, 100 ) ); - p = random_uniform( 0, 1 ); - x = random_uniform( 0, 50 ); + n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + p = random_uniform( 0.0, 1.0 ); + x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); y = stdlib_base_dists_binomial_logpmf( x, n, p ); - printf( "x: %lf, n: %lf, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); + printf( "x: %d, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h index 79cb243bbbaa..56b894313240 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h @@ -19,6 +19,8 @@ #ifndef STDLIB_STATS_BASE_DISTS_BINOMIAL_LOGPMF_H #define STDLIB_STATS_BASE_DISTS_BINOMIAL_LOGPMF_H +#include + /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -29,7 +31,7 @@ extern "C" { /** * Returns the natural logarithm of the probability mass function (PMF) of a binomial distribution. */ -double stdlib_base_dists_binomial_logpmf( const double x, const double n, const double p ); +double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js index 63286218fe2a..1481106360b8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js @@ -51,22 +51,10 @@ var addon = require( './../src/addon.node' ); * // returns ~-5.108 * * @example -* var y = logpmf( NaN, 20, 0.5 ); -* // returns NaN -* -* @example -* var y = logpmf( 0.0, NaN, 0.5 ); -* // returns NaN -* -* @example * var y = logpmf( 0.0, 20, NaN ); * // returns NaN * * @example -* var y = logpmf( 2.0, 1.5, 0.5 ); -* // returns NaN -* -* @example * var y = logpmf( 2.0, -2.0, 0.5 ); * // returns NaN * diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c index 3d0222e61a2c..406d3e104edf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c @@ -20,4 +20,4 @@ #include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_binomial_logpmf ); +STDLIB_MATH_BASE_NAPI_MODULE_IID_D( stdlib_base_dists_binomial_logpmf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c index 1ef348e6bd50..c98084f59bfd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c @@ -24,6 +24,7 @@ #include "stdlib/math/base/special/binomcoefln.h" #include "stdlib/math/base/special/log1p.h" #include "stdlib/math/base/special/ln.h" +#include /** * Evaluates the natural logarithm of the probability mass function (PMF) for a binomial distribution with number of trials `n` and success probability `p` at a value `x`. @@ -37,20 +38,16 @@ * double y = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 ); * // returns ~-1.583 */ -double stdlib_base_dists_binomial_logpmf( const double x, const double n, const double p ) { +double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ) { if ( - stdlib_base_is_nan( x ) || - stdlib_base_is_nan( n ) || stdlib_base_is_nan( p ) || - n < 0.0 || + n < 0 || p < 0.0 || - p > 1.0 || - !stdlib_base_is_nonnegative_integer( n ) || - n == STDLIB_CONSTANT_FLOAT64_PINF + p > 1.0 ) { return 0.0 / 0.0; } - if ( stdlib_base_is_nonnegative_integer( x ) ){ + if ( x >= 0 ){ if ( x > n ) { return STDLIB_CONSTANT_FLOAT64_NINF; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js index f036c23e7038..fe9ac6b7cd4d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js @@ -55,18 +55,14 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { - var y = logpmf( NaN, 20, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 0.0, NaN, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); + var y; y = logpmf( 0.0, 20, NaN ); t.equal( isnan( y ), true, 'returns NaN' ); t.end(); }); tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the function returns `-Infinity`', opts, function test( t ) { - var y = logpmf( NINF, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); + var y; y = logpmf( -20.0, 20, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); @@ -80,37 +76,12 @@ tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the funct t.end(); }); -tape( 'if provided a non-integer for `x` and a valid `n` and `p`, the function returns `-Infinity`', opts, function test( t ) { - var y = logpmf( -1.5, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( -0.5, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( 1.5, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( 2.5, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - t.end(); -}); - tape( 'if provided `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var y; - y = logpmf( 2.0, 1.5, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 0.0, -1.0, 0.5 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 2.0, NINF, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = logpmf( 2.0, PINF, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); @@ -142,15 +113,6 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio y = logpmf( 1.0, 8, 0.0 ); t.equal( y, NINF, 'returns -Infinity' ); - y = logpmf( PINF, 8, 0.0 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NINF, 8, 0.0 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NaN, 8, 0.0 ); - t.equal( isnan( y ), true, 'returns NaN' ); - // Case: n = 0, p = 0.5 y = logpmf( 0.0, 0, 0.5 ); t.equal( y, 0.0, 'returns 0 for x equal to 0' ); @@ -158,15 +120,6 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio y = logpmf( 1.0, 0, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); - y = logpmf( PINF, 0, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NINF, 0, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NaN, 0, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); @@ -179,15 +132,6 @@ tape( 'if `p` equals `1.0`, the function evaluates a degenerate distribution cen y = logpmf( 1.0, 8, 1.0 ); t.equal( y, NINF, 'returns -Infinity' ); - y = logpmf( PINF, 8, 1.0 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NINF, 8, 1.0 ); - t.equal( y, NINF, 'returns -Infinity' ); - - y = logpmf( NaN, 8, 1.0 ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); From d53556effd62500496a65e8f85074239819898da Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:47:51 +0530 Subject: [PATCH 05/10] fix: changes in benchmarks --- 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: 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: na - 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: 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 --- --- .../dists/binomial/logpmf/benchmark/benchmark.js | 2 +- .../binomial/logpmf/benchmark/benchmark.native.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js index 47dab157063c..6a94fc8014cd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.js @@ -47,7 +47,7 @@ bench( pkg, function benchmark( b ) { x[ i ] = discreteUniform( 0, 50 ); n[ i ] = discreteUniform( 1, 100 ); p[ i ] = uniform( 0.0, 1.0 ); -} + } b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js index 14c2a20dc99f..2aaa62fa37d6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; @@ -50,13 +49,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var i; len = 100; - n = new Int32Array( len ); + x = new Float64Array( len ); + n = new Float64Array( len ); p = new Float64Array( len ); - x = new Int32Array( len ); for ( i = 0; i < len; i++ ) { - n[ i ] = ceil( randu()*100.0 ); - p[ i ] = randu(); - x[ i ] = ceil( randu()*50.0 ); + x[ i ] = discreteUniform( 0, 50 ); + n[ i ] = discreteUniform( 1, 100 ); + p[ i ] = uniform( 0.0, 1.0 ); } b.tic(); From 3bd23e1b8db14544a00a041cccece8441742c86f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 22 Jun 2025 21:22:00 -0500 Subject: [PATCH 06/10] fix: improve parameter validation and style in `binomial/logpmf` - Fix integer comparisons in edge cases (x == 0 instead of x == 0.0) - Improve parameter validation logic for cleaner code flow - Fix JSDoc example to use integer (3 instead of 3.0) - Maintain correct int32_t types for discrete parameters x and n --- 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: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- 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: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - 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/stats/base/dists/binomial/logpmf.h | 1 + .../base/dists/binomial/logpmf/src/main.c | 27 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h index 56b894313240..cea6ab42aeb1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h @@ -21,6 +21,7 @@ #include + /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c index c98084f59bfd..ae632ccfc7a3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c @@ -35,7 +35,7 @@ * @return evaluated logPMF * * @example -* double y = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 ); +* double y = stdlib_base_dists_binomial_logpmf( 3, 20, 0.2 ); * // returns ~-1.583 */ double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ) { @@ -47,19 +47,16 @@ double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, cons ) { return 0.0 / 0.0; } - if ( x >= 0 ){ - if ( x > n ) { - return STDLIB_CONSTANT_FLOAT64_NINF; - } - if ( p == 0.0 ) { - return ( x == 0.0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; - } - if ( p == 1.0 ) { - return ( x == n ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; - } - double out = stdlib_base_binomcoefln( n, x ); - out += ( x * stdlib_base_ln( p ) ) + ( ( n - x ) * stdlib_base_log1p( -p ) ); - return out; + if ( x < 0 || x > n ) { + return STDLIB_CONSTANT_FLOAT64_NINF; } - return STDLIB_CONSTANT_FLOAT64_NINF; + if ( p == 0.0 ) { + return ( x == 0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; + } + if ( p == 1.0 ) { + return ( x == n ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; + } + double out = stdlib_base_binomcoefln( n, x ); + out += ( x * stdlib_base_ln( p ) ) + ( ( n - x ) * stdlib_base_log1p( -p ) ); + return out; } From 7daa1e7f15e91f981f03abadfef95a6b66c6cbfc Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 22 Jun 2025 21:51:01 -0500 Subject: [PATCH 07/10] fix: improve binomial logpmf documentation and test structure - Fix documentation descriptions to use consistent "Evaluates" terminology - Remove unused includes in C source files - Update test cases to use integer literals for consistency - Clean up parameter validation and documentation Note: C implementation currently has functional issues returning NaN, but structure and documentation are improved. Keeping int32_t types as requested for x and n parameters. --- 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: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- .../stdlib/stats/base/dists/binomial/logpmf.h | 2 +- .../base/dists/binomial/logpmf/src/main.c | 4 +-- .../dists/binomial/logpmf/test/test.native.js | 30 +++++++++---------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h index cea6ab42aeb1..cb65461d85fe 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h @@ -30,7 +30,7 @@ extern "C" { #endif /** -* Returns the natural logarithm of the probability mass function (PMF) of a binomial distribution. +* Evaluates the natural logarithm of the probability mass function (PMF) for a binomial distribution. */ double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c index ae632ccfc7a3..7a3d84cf7b3b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c @@ -18,16 +18,14 @@ #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/assert/is_nan.h" -#include "stdlib/constants/float64/pinf.h" #include "stdlib/constants/float64/ninf.h" -#include "stdlib/math/base/assert/is_nonnegative_integer.h" #include "stdlib/math/base/special/binomcoefln.h" #include "stdlib/math/base/special/log1p.h" #include "stdlib/math/base/special/ln.h" #include /** -* Evaluates the natural logarithm of the probability mass function (PMF) for a binomial distribution with number of trials `n` and success probability `p` at a value `x`. +* Evaluates the natural logarithm of the probability mass function (PMF) for a binomial distribution. * * @param x input value * @param n number of trials diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js index fe9ac6b7cd4d..ace4611698e4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js @@ -56,7 +56,7 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { var y; - y = logpmf( 0.0, 20, NaN ); + y = logpmf( 0, 20, NaN ); t.equal( isnan( y ), true, 'returns NaN' ); t.end(); }); @@ -64,13 +64,13 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the function returns `-Infinity`', opts, function test( t ) { var y; - y = logpmf( -20.0, 20, 0.5 ); + y = logpmf( -20, 20, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); - y = logpmf( -100.0, 20, 0.5 ); + y = logpmf( -100, 20, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); - y = logpmf( -1.0, 20, 0.5 ); + y = logpmf( -1, 20, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); t.end(); @@ -79,7 +79,7 @@ tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the funct tape( 'if provided `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var y; - y = logpmf( 0.0, -1.0, 0.5 ); + y = logpmf( 0, -1, 0.5 ); t.equal( isnan( y ), true, 'returns NaN' ); t.end(); @@ -88,16 +88,16 @@ tape( 'if provided `n` which is not a nonnegative integer, the function returns tape( 'if provided a success probability `p` outside of `[0,1]`, the function returns `NaN`', opts, function test( t ) { var y; - y = logpmf( 2.0, 20, -1.0 ); + y = logpmf( 2, 20, -1.0 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 0.0, 20, 1.5 ); + y = logpmf( 0, 20, 1.5 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 2.0, 20, NINF ); + y = logpmf( 2, 20, NINF ); t.equal( isnan( y ), true, 'returns NaN' ); - y = logpmf( 2.0, 20, PINF ); + y = logpmf( 2, 20, PINF ); t.equal( isnan( y ), true, 'returns NaN' ); t.end(); @@ -107,17 +107,17 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio var y; // Case: n = 8, p = 0.0 - y = logpmf( 0.0, 8, 0.0 ); + y = logpmf( 0, 8, 0.0 ); t.equal( y, 0.0, 'returns 0 for x equal to 0' ); - y = logpmf( 1.0, 8, 0.0 ); + y = logpmf( 1, 8, 0.0 ); t.equal( y, NINF, 'returns -Infinity' ); // Case: n = 0, p = 0.5 - y = logpmf( 0.0, 0, 0.5 ); + y = logpmf( 0, 0, 0.5 ); t.equal( y, 0.0, 'returns 0 for x equal to 0' ); - y = logpmf( 1.0, 0, 0.5 ); + y = logpmf( 1, 0, 0.5 ); t.equal( y, NINF, 'returns -Infinity' ); t.end(); @@ -126,10 +126,10 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio tape( 'if `p` equals `1.0`, the function evaluates a degenerate distribution centered at `n`', opts, function test( t ) { var y; - y = logpmf( 8.0, 8, 1.0 ); + y = logpmf( 8, 8, 1.0 ); t.equal( y, 0.0, 'returns 0 for x equal to 8' ); - y = logpmf( 1.0, 8, 1.0 ); + y = logpmf( 1, 8, 1.0 ); t.equal( y, NINF, 'returns -Infinity' ); t.end(); From af22a780d1f2ee74e430972e0010f485a2fd61d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Fri, 3 Jul 2026 09:53:11 +0000 Subject: [PATCH 08/10] chore: update copyright years --- .../base/dists/binomial/logpmf/benchmark/benchmark.native.js | 2 +- .../stats/base/dists/binomial/logpmf/benchmark/c/Makefile | 2 +- .../stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/binding.gyp | 2 +- .../stats/base/dists/binomial/logpmf/examples/c/Makefile | 2 +- .../stats/base/dists/binomial/logpmf/examples/c/example.c | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/include.gypi | 2 +- .../logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/lib/native.js | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/src/Makefile | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/src/addon.c | 2 +- .../@stdlib/stats/base/dists/binomial/logpmf/src/main.c | 2 +- .../stats/base/dists/binomial/logpmf/test/test.native.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js index 2aaa62fa37d6..c6f44a598b20 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/Makefile index a4bd7b38fd74..979768abbcec 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# Copyright (c) 2026 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c index 9463361ba3b1..3d03d49be1cf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/binding.gyp index 68a1ca11d160..0d6508a12e99 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# Copyright (c) 2026 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/Makefile index 25ced822f96a..c8f8e9a1517b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# Copyright (c) 2026 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c index 71b28b0f536f..759fd1daae59 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include.gypi index ecfaf82a3279..bee8d41a2caf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# Copyright (c) 2026 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h index cb65461d85fe..43df223c2b54 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js index 1481106360b8..dc67bdf7b166 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/lib/native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/Makefile index 7733b6180cb4..2caf905cedbe 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2025 The Stdlib Authors. +# Copyright (c) 2026 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c index 406d3e104edf..9934e7db2669 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c index 7a3d84cf7b3b..5b9e28b55119 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js index ace4611698e4..da03935ab8f9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4060ff1c62df537a9bbdfba41fd64e2e7d78cc72 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 23 Jul 2026 22:52:43 -0500 Subject: [PATCH 09/10] fix: change x parameter type from int32_t to double for consistency with pmf sibling - Refactor C signature to (double x, int32_t n, double p) matching binomial/pmf - Add is_nan(x) and is_nonnegative_integer(x) checks matching JS implementation - Update NAPI macro from IID_D to DID_D - Remove unused pinf dependency from manifest.json - Use format() for benchmark description string - Standardize test assertion messages to 'returns expected value' --- .../base/dists/binomial/logpmf/README.md | 10 ++-- .../logpmf/benchmark/benchmark.native.js | 3 +- .../binomial/logpmf/benchmark/c/benchmark.c | 4 +- .../binomial/logpmf/examples/c/example.c | 6 +-- .../stdlib/stats/base/dists/binomial/logpmf.h | 2 +- .../base/dists/binomial/logpmf/manifest.json | 9 ++-- .../base/dists/binomial/logpmf/src/addon.c | 2 +- .../base/dists/binomial/logpmf/src/main.c | 19 +++++--- .../dists/binomial/logpmf/test/test.native.js | 47 ++++++++++--------- 9 files changed, 56 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md index 5d7d5d3116fd..3885f526aff0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/README.md @@ -183,12 +183,12 @@ double out = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 ); The function accepts the following arguments: -- **x**: `[in] int32_t` input value. +- **x**: `[in] double` input value. - **n**: `[in] int32_t` number of trials. - **p**: `[in] double` success probability. ```c -double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ); +double stdlib_base_dists_binomial_logpmf( const double x, const int32_t n, const double p ); ``` @@ -222,18 +222,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { + double x; int32_t n; double p; - int32_t x; double y; int i; for ( i = 0; i < 25; i++ ) { + x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); p = random_uniform( 0.0, 1.0 ); - x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); y = stdlib_base_dists_binomial_logpmf( x, n, p ); - printf( "x: %d, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); + printf( "x: %lf, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js index c6f44a598b20..027cc794bbc2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/benchmark.native.js @@ -27,6 +27,7 @@ var tryRequire = require( '@stdlib/utils/try-require' ); var uniform = require( '@stdlib/random/base/uniform' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -40,7 +41,7 @@ var opts = { // MAIN // -bench( pkg+'::native', opts, function benchmark( b ) { +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { var len; var n; var p; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c index 3d03d49be1cf..47ce46234ea4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/benchmark/c/benchmark.c @@ -95,17 +95,17 @@ static double random_uniform( const double min, const double max ) { */ static double benchmark( void ) { double elapsed; + double x[ 100 ]; int32_t n[ 100 ]; double p[ 100 ]; - int32_t x[ 100 ]; double y; double t; int i; for ( i = 0; i < 100; i++ ) { + x[ i ] = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); n[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); p[ i ] = random_uniform( 0.0, 1.0 ); - x[ i ] = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); } t = tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c index 759fd1daae59..84fc1db8d4b0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/examples/c/example.c @@ -28,18 +28,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { + double x; int32_t n; double p; - int32_t x; double y; int i; for ( i = 0; i < 25; i++ ) { + x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); p = random_uniform( 0.0, 1.0 ); - x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) ); y = stdlib_base_dists_binomial_logpmf( x, n, p ); - printf( "x: %d, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); + printf( "x: %lf, n: %d, p: %lf, ln(P(X=x;n,p)): %lf\n", x, n, p, y ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h index 43df223c2b54..96a89b1db23b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h @@ -32,7 +32,7 @@ extern "C" { /** * Evaluates the natural logarithm of the probability mass function (PMF) for a binomial distribution. */ -double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ); +double stdlib_base_dists_binomial_logpmf( const double x, const int32_t n, const double p ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/manifest.json index a274cd12e4c9..9674d7ff6869 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/manifest.json @@ -40,9 +40,8 @@ "dependencies": [ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-nan", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf", "@stdlib/math/base/assert/is-nonnegative-integer", + "@stdlib/constants/float64/ninf", "@stdlib/math/base/special/binomcoefln", "@stdlib/math/base/special/log1p", "@stdlib/math/base/special/ln" @@ -61,9 +60,8 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf", "@stdlib/math/base/assert/is-nonnegative-integer", + "@stdlib/constants/float64/ninf", "@stdlib/math/base/special/binomcoefln", "@stdlib/math/base/special/log1p", "@stdlib/math/base/special/ln", @@ -83,9 +81,8 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/constants/float64/pinf", - "@stdlib/constants/float64/ninf", "@stdlib/math/base/assert/is-nonnegative-integer", + "@stdlib/constants/float64/ninf", "@stdlib/math/base/special/binomcoefln", "@stdlib/math/base/special/log1p", "@stdlib/math/base/special/ln", diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c index 9934e7db2669..a7d681879e1e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c @@ -20,4 +20,4 @@ #include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_IID_D( stdlib_base_dists_binomial_logpmf ); +STDLIB_MATH_BASE_NAPI_MODULE_DID_D( stdlib_base_dists_binomial_logpmf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c index 5b9e28b55119..86c427386f3e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c @@ -18,6 +18,7 @@ #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/assert/is_nonnegative_integer.h" #include "stdlib/constants/float64/ninf.h" #include "stdlib/math/base/special/binomcoefln.h" #include "stdlib/math/base/special/log1p.h" @@ -33,28 +34,34 @@ * @return evaluated logPMF * * @example -* double y = stdlib_base_dists_binomial_logpmf( 3, 20, 0.2 ); +* double y = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 ); * // returns ~-1.583 */ -double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ) { +double stdlib_base_dists_binomial_logpmf( const double x, const int32_t n, const double p ) { + double out; + if ( + stdlib_base_is_nan( x ) || stdlib_base_is_nan( p ) || n < 0 || p < 0.0 || p > 1.0 ) { - return 0.0 / 0.0; + return 0.0 / 0.0; // NaN + } + if ( !stdlib_base_is_nonnegative_integer( x ) ) { + return STDLIB_CONSTANT_FLOAT64_NINF; } - if ( x < 0 || x > n ) { + if ( x > n ) { return STDLIB_CONSTANT_FLOAT64_NINF; } if ( p == 0.0 ) { - return ( x == 0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; + return ( x == 0.0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; } if ( p == 1.0 ) { return ( x == n ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF; } - double out = stdlib_base_binomcoefln( n, x ); + out = stdlib_base_binomcoefln( n, x ); out += ( x * stdlib_base_ln( p ) ) + ( ( n - x ) * stdlib_base_log1p( -p ) ); return out; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js index da03935ab8f9..0b1f80b6bae8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/test/test.native.js @@ -54,10 +54,15 @@ tape( 'main export is a function', opts, function test( t ) { t.end(); }); -tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { +tape( 'if provided `NaN` for `x` or `p`, the function returns `NaN`', opts, function test( t ) { var y; - y = logpmf( 0, 20, NaN ); - t.equal( isnan( y ), true, 'returns NaN' ); + + y = logpmf( NaN, 20, 0.5 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpmf( 0.0, 20, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); }); @@ -65,13 +70,13 @@ tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the funct var y; y = logpmf( -20, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); y = logpmf( -100, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); y = logpmf( -1, 20, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); t.end(); }); @@ -80,7 +85,7 @@ tape( 'if provided `n` which is not a nonnegative integer, the function returns var y; y = logpmf( 0, -1, 0.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); t.end(); }); @@ -89,16 +94,16 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re var y; y = logpmf( 2, 20, -1.0 ); - t.equal( isnan( y ), true, 'returns NaN' ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); y = logpmf( 0, 20, 1.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); y = logpmf( 2, 20, NINF ); - t.equal( isnan( y ), true, 'returns NaN' ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); y = logpmf( 2, 20, PINF ); - t.equal( isnan( y ), true, 'returns NaN' ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); t.end(); }); @@ -108,17 +113,17 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio // Case: n = 8, p = 0.0 y = logpmf( 0, 8, 0.0 ); - t.equal( y, 0.0, 'returns 0 for x equal to 0' ); + t.strictEqual( y, 0.0, 'returns expected value' ); y = logpmf( 1, 8, 0.0 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); // Case: n = 0, p = 0.5 y = logpmf( 0, 0, 0.5 ); - t.equal( y, 0.0, 'returns 0 for x equal to 0' ); + t.strictEqual( y, 0.0, 'returns expected value' ); y = logpmf( 1, 0, 0.5 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); t.end(); }); @@ -127,10 +132,10 @@ tape( 'if `p` equals `1.0`, the function evaluates a degenerate distribution cen var y; y = logpmf( 8, 8, 1.0 ); - t.equal( y, 0.0, 'returns 0 for x equal to 8' ); + t.strictEqual( y, 0.0, 'returns expected value' ); y = logpmf( 1, 8, 1.0 ); - t.equal( y, NINF, 'returns -Infinity' ); + t.strictEqual( y, NINF, 'returns expected value' ); t.end(); }); @@ -152,7 +157,7 @@ tape( 'the function evaluates the logpmf for `x` given large `n` and `p`', opts, for ( i = 0; i < x.length; i++ ) { y = logpmf( x[i], n[i], p[i] ); if ( y === expected[i] ) { - t.equal( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[i] ); tol = 30.0 * EPS * abs( expected[i] ); @@ -179,7 +184,7 @@ tape( 'the function evaluates the logpmf for `x` given large `n` and small `p`', for ( i = 0; i < x.length; i++ ) { y = logpmf( x[i], n[i], p[i] ); if ( y === expected[i] ) { - t.equal( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[i] ); tol = 20.0 * EPS * abs( expected[i] ); @@ -206,7 +211,7 @@ tape( 'the function evaluates the logpmf for `x` given small `n` and large `p`', for ( i = 0; i < x.length; i++ ) { y = logpmf( x[i], n[i], p[i] ); if ( y === expected[i] ) { - t.equal( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[i] ); tol = 20.0 * EPS * abs( expected[i] ); @@ -233,7 +238,7 @@ tape( 'the function evaluates the logpmf for `x` given small `n` and `p`', opts, for ( i = 0; i < x.length; i++ ) { y = logpmf( x[i], n[i], p[i] ); if ( y === expected[i] ) { - t.equal( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[i] ); tol = 10.0 * EPS * abs( expected[i] ); From 43aa6583da9d9ee42b6cec94fc1d3d58e63d636e Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 23 Jul 2026 23:12:17 -0500 Subject: [PATCH 10/10] chore: remove unused directive Signed-off-by: Philipp Burckhardt --- .../@stdlib/stats/base/dists/binomial/logpmf/src/addon.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c index a7d681879e1e..14a57757c935 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/addon.c @@ -19,5 +19,4 @@ #include "stdlib/stats/base/dists/binomial/logpmf.h" #include "stdlib/math/base/napi/ternary.h" -// cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_DID_D( stdlib_base_dists_binomial_logpmf );