Skip to content

Commit aac1d84

Browse files
committed
fix: update the C implementation with correct parameter types
--- 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: na - 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: 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 ---
1 parent c56302d commit aac1d84

File tree

9 files changed

+74
-154
lines changed

9 files changed

+74
-154
lines changed

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ for ( i = 0; i < 10; i++ ) {
188188
Evaluates the [probability mass function][pmf] (PMF) for a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
189189

190190
```c
191-
double out = stdlib_base_dists_hypergeometric_stdev( 16, 11, 4 );
192-
// returns ~0.829
191+
double out = stdlib_base_dists_hypergeometric_pmf( 1.0, 8, 4, 2 );
192+
// returns ~0.571
193193
```
194194

195195
The function accepts the following arguments:
196196

197197
- **x**: `[in] double` input value.
198-
- **N**: `[in] double` population size.
199-
- **K**: `[in] double` subpopulation size.
200-
- **n**: `[in] double` number of draws.
198+
- **N**: `[in] int32_t` population size.
199+
- **K**: `[in] int32_t` subpopulation size.
200+
- **n**: `[in] int32_t` number of draws.
201201

202202
```c
203-
double stdlib_base_dists_hypergeometric_pmf ( const double x, const double N, const double K, const double n );
203+
double stdlib_base_dists_hypergeometric_pmf ( const double x, const int32_t N, const int32_t K, const int32_t n );
204204
```
205205
206206
</section>
@@ -222,31 +222,32 @@ double stdlib_base_dists_hypergeometric_pmf ( const double x, const double N, co
222222
### Examples
223223
224224
```c
225-
#include "stdlib/math/base/special/round.h"
226225
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
227-
#include <stdio.h>
226+
#include "stdlib/math/base/special/round.h"
228227
#include <stdlib.h>
228+
#include <stdint.h>
229+
#include <stdio.h>
229230
230231
static double random_uniform( const double min, const double max ) {
231232
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
232233
return min + ( v * ( max - min ) );
233234
}
234235
235236
int main( void ) {
236-
double pmf;
237-
double N;
238-
double K;
239-
double n;
237+
int32_t N;
238+
int32_t K;
239+
int32_t n;
240240
double x;
241+
double y;
241242
int i;
242243
243244
for ( i = 0; i < 10; i++ ) {
245+
x = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
244246
N = stdlib_base_round( random_uniform( 0.0, 20.0 ) );
245247
K = stdlib_base_round( random_uniform( 0.0, N ) );
246248
n = stdlib_base_round( random_uniform( 0.0, N ) );
247-
x = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
248-
pmf = stdlib_base_dists_hypergeometric_pmf( x, N, K, n );
249-
printf( "x: %lf, N: %lf, K: %lf, n: %lf, P(X=x;N,K,n): %lf\n", x, N, K, n, pmf );
249+
y = stdlib_base_dists_hypergeometric_pmf( x, N, K, n );
250+
printf( "x: %lf, N: %d, K: %d, n: %d, P(X=x;N,K,n): %lf\n", x, N, K, n, y );
250251
}
251252
}
252253
```

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/benchmark/benchmark.native.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var Float64Array = require( '@stdlib/array/float64' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
29-
var round = require( '@stdlib/math/base/special/round' );
3029
var pkg = require( './../package.json' ).name;
3130

3231

@@ -55,15 +54,15 @@ bench( pkg+'::native', opts, function benchmark( b ) {
5554
n = new Float64Array( len );
5655
x = new Float64Array( len );
5756
for ( i = 0; i < len; i++ ) {
58-
N[ i ] = round( randu()*100.0 );
59-
K[ i ] = round( randu()*N );
60-
n[ i ] = round( randu()*N );
61-
x[ i ] = round( randu()*10.0 );
57+
x[ i ] = discreteUniform( 1, 10 );
58+
N[ i ] = discreteUniform( 1, 100 );
59+
K[ i ] = discreteUniform( 1, N[ i ] );
60+
n[ i ] = discreteUniform( 1, N[ i ] );
6261
}
6362

6463
b.tic();
6564
for ( i = 0; i < b.iterations; i++ ) {
66-
y = pmf( x[ i % len ], N[ i % len ], K[ i % len ], n[ i % len ] );
65+
y = pmf( x[ i%len ], N[ i%len ], K[ i%len ], n[ i%len ] );
6766
if ( isnan( y ) ) {
6867
b.fail( 'should not return NaN' );
6968
}

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

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

19-
#include "stdlib/math/base/special/round.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
21-
#include <math.h>
22-
#include <stdio.h>
20+
#include "stdlib/math/base/special/round.h"
2321
#include <stdlib.h>
22+
#include <stdio.h>
23+
#include <stdint.h>
2424
#include <time.h>
2525
#include <sys/time.h>
2626

@@ -93,32 +93,32 @@ static double random_uniform( const double min, const double max ) {
9393
* @return elapsed time in seconds
9494
*/
9595
static double benchmark( void ) {
96-
double elapsed;
97-
double N[ 100 ];
98-
double K[ 100 ];
99-
double n[ 100 ];
96+
int32_t N[ 100 ];
97+
int32_t K[ 100 ];
98+
int32_t n[ 100 ];
10099
double x[ 100 ];
101-
double pmf;
100+
double elapsed;
101+
double y;
102102
double t;
103103
int i;
104104

105105
for ( i = 0; i < 100; i++ ) {
106106
N[ i ] = stdlib_base_round( random_uniform( 1.0, 100.0 ) );
107-
K[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
108-
n[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
109-
x[ i ] = stdlib_base_round( random_uniform( 0.0, n[ i ] ) );
107+
K[ i ] = stdlib_base_round( random_uniform( 1.0, N[ i ] ) );
108+
n[ i ] = stdlib_base_round( random_uniform( 1.0, N[ i ] ) );
109+
x[ i ] = stdlib_base_round( random_uniform( 1.0, 10.0 ) );
110110
}
111111

112112
t = tic();
113113
for ( i = 0; i < ITERATIONS; i++ ) {
114-
pmf = stdlib_base_dists_hypergeometric_pmf( x[ i % 100 ], N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
115-
if ( pmf != pmf ) {
114+
y = stdlib_base_dists_hypergeometric_pmf( x[ i%100 ], N[ i%100 ], K[ i%100 ], n[ i%100 ] );
115+
if ( y != y ) {
116116
printf( "should not return NaN\n" );
117117
break;
118118
}
119119
}
120120
elapsed = tic() - t;
121-
if ( pmf != pmf ) {
121+
if ( y != y ) {
122122
printf( "should not return NaN\n" );
123123
}
124124
return elapsed;

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/examples/c/example.c

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

19-
#include "stdlib/math/base/special/round.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/pmf.h"
21-
#include <stdio.h>
20+
#include "stdlib/math/base/special/round.h"
2221
#include <stdlib.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
2324

2425
static double random_uniform( const double min, const double max ) {
2526
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
2627
return min + ( v * ( max - min ) );
2728
}
2829

2930
int main( void ) {
30-
double pmf;
31-
double N;
32-
double K;
33-
double n;
31+
int32_t N;
32+
int32_t K;
33+
int32_t n;
34+
double y;
3435
double x;
3536
int i;
3637

3738
for ( i = 0; i < 10; i++ ) {
39+
x = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
3840
N = stdlib_base_round( random_uniform( 0.0, 20.0 ) );
3941
K = stdlib_base_round( random_uniform( 0.0, N ) );
4042
n = stdlib_base_round( random_uniform( 0.0, N ) );
41-
x = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
42-
pmf = stdlib_base_dists_hypergeometric_pmf( x, N, K, n );
43-
printf( "x: %lf, N: %lf, K: %lf, n: %lf, P(X=x;N,K,n): %lf\n", x, N, K, n, pmf );
43+
y = stdlib_base_dists_hypergeometric_pmf( x, N, K, n );
44+
printf( "x: %lf, N: %d, K: %d, n: %d, P(X=x;N,K,n): %lf\n", x, N, K, n, y );
4445
}
4546
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/include/stdlib/stats/base/dists/hypergeometric/pmf.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_PMF_H
2020
#define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_PMF_H
2121

22+
#include <stdint.h>
23+
2224
/*
2325
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
2426
*/
@@ -28,14 +30,8 @@ extern "C" {
2830

2931
/**
3032
* Evaluates the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
31-
*
32-
* @param x input value
33-
* @param N population size
34-
* @param K subpopulation size
35-
* @param n number of draws
36-
* @return evaluated PMF
3733
*/
38-
double stdlib_base_dists_hypergeometric_pmf( const double x, const double N, const double K, const double n );
34+
double stdlib_base_dists_hypergeometric_pmf( const double x, const int32_t N, const int32_t K, const int32_t n );
3935

4036
#ifdef __cplusplus
4137
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/lib/native.js

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Evaluates the probability mass function (PMF) for a hypergeometric distribution.
29+
* Evaluates the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
3030
*
31-
* @private
32-
* @param {number} x - number of successes
33-
* @param {number} N - population size
34-
* @param {number} K - subpopulation size
35-
* @param {number} n - number of draws
36-
* @returns {number} evaluated PMF
31+
* @param {number} x - input value
32+
* @param {NonNegativeInteger} N - population size
33+
* @param {NonNegativeInteger} K - subpopulation size
34+
* @param {NonNegativeInteger} n - number of draws
35+
* @returns {Probability} evaluated PMF
3736
*
3837
* @example
3938
* var y = pmf( 1.0, 8, 4, 2 );
@@ -52,31 +51,7 @@ var addon = require( './../src/addon.node' );
5251
* // returns 0.0
5352
*
5453
* @example
55-
* var y = pmf( NaN, 10, 5, 2 );
56-
* // returns NaN
57-
*
58-
* @example
59-
* var y = pmf( 0.0, NaN, 5, 2 );
60-
* // returns NaN
61-
*
62-
* @example
63-
* var y = pmf( 0.0, 10, NaN, 2 );
64-
* // returns NaN
65-
*
66-
* @example
67-
* var y = pmf( 0.0, 10, 5, NaN );
68-
* // returns NaN
69-
*
70-
* @example
71-
* var y = pmf( 2.0, 10.5, 5, 2 );
72-
* // returns NaN
73-
*
74-
* @example
75-
* var y = pmf( 2.0, 5, 1.5, 2 );
76-
* // returns NaN
77-
*
78-
* @example
79-
* var y = pmf( 2.0, 10, 5, -2.0 );
54+
* var y = pmf( 2.0, 10, 5, -2 );
8055
* // returns NaN
8156
*
8257
* @example

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/pmf/manifest.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/quaternary",
42-
"@stdlib/math/base/assert/is-nonnegative-integer",
43-
"@stdlib/constants/float64/pinf",
44-
"@stdlib/math/base/assert/is-nan",
4542
"@stdlib/math/base/special/exp",
4643
"@stdlib/math/base/special/factorialln",
4744
"@stdlib/math/base/special/max",
48-
"@stdlib/math/base/special/min"
45+
"@stdlib/math/base/special/min",
46+
"@stdlib/math/base/assert/is-nonnegative-integer"
4947
]
5048
},
5149
{
@@ -60,14 +58,12 @@
6058
"libraries": [],
6159
"libpath": [],
6260
"dependencies": [
63-
"@stdlib/math/base/assert/is-nonnegative-integer",
64-
"@stdlib/constants/float64/pinf",
65-
"@stdlib/math/base/assert/is-nan",
6661
"@stdlib/math/base/special/exp",
6762
"@stdlib/math/base/special/factorialln",
6863
"@stdlib/math/base/special/max",
6964
"@stdlib/math/base/special/min",
70-
"@stdlib/math/base/special/round"
65+
"@stdlib/math/base/special/round",
66+
"@stdlib/math/base/assert/is-nonnegative-integer"
7167
]
7268
},
7369
{
@@ -82,14 +78,12 @@
8278
"libraries": [],
8379
"libpath": [],
8480
"dependencies": [
85-
"@stdlib/math/base/assert/is-nonnegative-integer",
86-
"@stdlib/constants/float64/pinf",
87-
"@stdlib/math/base/assert/is-nan",
8881
"@stdlib/math/base/special/exp",
8982
"@stdlib/math/base/special/factorialln",
9083
"@stdlib/math/base/special/max",
9184
"@stdlib/math/base/special/min",
92-
"@stdlib/math/base/special/round"
85+
"@stdlib/math/base/special/round",
86+
"@stdlib/math/base/assert/is-nonnegative-integer"
9387
]
9488
}
9589
]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ double stdlib_base_dists_hypergeometric_pmf( const double x, const int32_t N, co
4848
return 0.0/0.0; // NaN
4949
}
5050

51-
mins = stdlib_base_max( 0, n + K - N );
51+
mins = stdlib_base_max( 0, n+K-N );
5252
maxs = stdlib_base_min( K, n );
5353

5454
if ( stdlib_base_is_nonnegative_integer( x ) && mins <= x && x <= maxs ) {
5555
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 );
56+
ldenom = stdlib_base_factorialln( N ) + stdlib_base_factorialln( x ) + stdlib_base_factorialln( n-x );
57+
ldenom += stdlib_base_factorialln( K-x ) + stdlib_base_factorialln( N-K+x-n );
5758
lpmf = lnum - ldenom;
5859
return stdlib_base_exp( lpmf );
5960
}

0 commit comments

Comments
 (0)