Skip to content

Commit c56302d

Browse files
committed
feat: temp commit
--- 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: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - 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 ---
1 parent ca195a1 commit c56302d

File tree

2 files changed

+20
-15
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/src

2 files changed

+20
-15
lines changed

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/src/addon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/napi/quaternary.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
20+
#include "stdlib/math/base/napi/quaternary.h"
2121

2222
// cppcheck-suppress shadowFunction
23-
STDLIB_MATH_BASE_NAPI_MODULE_DDDD_D( stdlib_base_dists_hypergeometric_pmf )
23+
STDLIB_MATH_BASE_NAPI_MODULE_DIII_D( stdlib_base_dists_hypergeometric_pmf )

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/src/main.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/constants/float64/pinf.h"
20-
#include "stdlib/math/base/assert/is_nan.h"
19+
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
2120
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
22-
#include "stdlib/math/base/special/exp.h"
2321
#include "stdlib/math/base/special/factorialln.h"
22+
#include "stdlib/math/base/special/exp.h"
2423
#include "stdlib/math/base/special/max.h"
2524
#include "stdlib/math/base/special/min.h"
26-
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
25+
#include <stdint.h>
2726

2827
/**
2928
* Evaluates the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
@@ -35,21 +34,27 @@
3534
* @return evaluated PMF
3635
*
3736
* @example
38-
* double sd = stdlib_base_dists_hypergeometric_pmf( 1.0, 8, 4, 2 );
37+
* double y = stdlib_base_dists_hypergeometric_pmf( 1.0, 8, 4, 2 );
3938
* // returns ~0.571
4039
*/
41-
double stdlib_base_dists_hypergeometric_pmf( const double x, const double N, const double K, const double n ) {
42-
if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( N ) || stdlib_base_is_nan( K ) || stdlib_base_is_nan( n ) || !stdlib_base_is_nonnegative_integer( N ) || !stdlib_base_is_nonnegative_integer( K ) || !stdlib_base_is_nonnegative_integer( n ) || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) {
43-
return NAN;
40+
double stdlib_base_dists_hypergeometric_pmf( const double x, const int32_t N, const int32_t K, const int32_t n ) {
41+
double ldenom;
42+
double lnum;
43+
double lpmf;
44+
double maxs;
45+
double mins;
46+
47+
if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) {
48+
return 0.0/0.0; // NaN
4449
}
4550

46-
double mins = stdlib_base_max( 0, n + K - N );
47-
double maxs = stdlib_base_min( K, n );
51+
mins = stdlib_base_max( 0, n + K - N );
52+
maxs = stdlib_base_min( K, n );
4853

4954
if ( stdlib_base_is_nonnegative_integer( x ) && mins <= x && x <= maxs ) {
50-
double lnum = stdlib_base_factorialln( n ) + stdlib_base_factorialln( K ) + stdlib_base_factorialln( N - n ) + stdlib_base_factorialln( N - K );
51-
double ldenom = stdlib_base_factorialln( N ) + stdlib_base_factorialln( x ) + stdlib_base_factorialln( n - x ) + stdlib_base_factorialln( K - x ) + stdlib_base_factorialln( N - K + x - n );
52-
double lpmf = lnum - ldenom;
55+
lnum = stdlib_base_factorialln( n ) + stdlib_base_factorialln( K ) + stdlib_base_factorialln( N-n ) + stdlib_base_factorialln( N-K );
56+
ldenom = stdlib_base_factorialln( N ) + stdlib_base_factorialln( x ) + stdlib_base_factorialln( n-x ) + stdlib_base_factorialln( K-x ) + stdlib_base_factorialln( N-K+x-n );
57+
lpmf = lnum - ldenom;
5358
return stdlib_base_exp( lpmf );
5459
}
5560
return 0.0;

0 commit comments

Comments
 (0)