Skip to content

Commit 3df0f9c

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: 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: passed - task: lint_javascript_benchmarks status: na - 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: 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 42683e1 commit 3df0f9c

File tree

10 files changed

+116
-181
lines changed

10 files changed

+116
-181
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ double out = stdlib_base_dists_hypergeometric_logpmf( 1.0, 8, 4, 2 );
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_logpmf ( const double x, const double N, const double K, const double n );
203+
double stdlib_base_dists_hypergeometric_logpmf ( 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_logpmf ( const double x, const double N,
222222
### Examples
223223
224224
```c
225-
#include "stdlib/math/base/special/round.h"
226225
#include "stdlib/stats/base/dists/hypergeometric/logpmf.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 log_pmf;
237-
double N;
238-
double K;
239-
double n;
237+
int32_t N;
238+
int32_t K;
239+
int32_t n;
240+
double y;
240241
double x;
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-
log_pmf = stdlib_base_dists_hypergeometric_logpmf( x, N, K, n );
249-
printf( "x: %lf, N: %lf, K: %lf, n: %lf, ln(P(X=x;N,K,n)): %lf\n", x, N, K, n, log_pmf );
249+
y = stdlib_base_dists_hypergeometric_logpmf( x, N, K, n );
250+
printf( "x: %lf, N: %d, K: %d, n: %d, ln(P(X=x;N,K,n)): %lf\n", x, N, K, n, y );
250251
}
251252
}
252253
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bench( pkg, function benchmark( b ) {
5353

5454
b.tic();
5555
for ( i = 0; i < b.iterations; i++ ) {
56-
y = logpmf( x[ i % len ], N[ i % len ], K[ i % len ], n[ i % len ] );
56+
y = logpmf( x[ i%len ], N[ i%len ], K[ i%len ], n[ i%len ] );
5757
if ( isnan( y ) ) {
5858
b.fail( 'should not return NaN' );
5959
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/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() * 90.0 ) + 10.0 );
59-
K[ i ] = round( randu() * N[ i ] );
60-
n[ i ] = round( randu() * N[ i ] );
61-
x[ i ] = round( randu() * n[ i ] );
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 = logpmf( x[ i % len ], N[ i % len ], K[ i % len ], n[ i % len ] );
65+
y = logpmf( 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/logpmf/benchmark/c/benchmark.c

Lines changed: 16 additions & 15 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/logpmf.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

@@ -62,32 +62,32 @@ static double random_uniform( const double min, const double max ) {
6262
}
6363

6464
static double benchmark( void ) {
65-
double elapsed;
66-
double N[ 100 ];
67-
double K[ 100 ];
68-
double n[ 100 ];
65+
int32_t N[ 100 ];
66+
int32_t K[ 100 ];
67+
int32_t n[ 100 ];
6968
double x[ 100 ];
70-
double log_pmf;
69+
double elapsed;
70+
double y;
7171
double t;
7272
int i;
7373

7474
for ( i = 0; i < 100; i++ ) {
75-
N[ i ] = stdlib_base_round( random_uniform( 5.0, 100.0 ) );
76-
K[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
77-
n[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
78-
x[ i ] = stdlib_base_round( random_uniform( 0.0, n[ i ] ) );
75+
N[ i ] = stdlib_base_round( random_uniform( 1.0, 100.0 ) );
76+
K[ i ] = stdlib_base_round( random_uniform( 1.0, N[ i ] ) );
77+
n[ i ] = stdlib_base_round( random_uniform( 1.0, N[ i ] ) );
78+
x[ i ] = stdlib_base_round( random_uniform( 1.0, 10.0 ) );
7979
}
8080

8181
t = tic();
8282
for ( i = 0; i < ITERATIONS; i++ ) {
83-
log_pmf = stdlib_base_dists_hypergeometric_logpmf( x[ i % 100 ], N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
84-
if ( log_pmf != log_pmf ) {
83+
y = stdlib_base_dists_hypergeometric_logpmf( x[ i%100 ], N[ i%100 ], K[ i%100 ], n[ i%100 ] );
84+
if ( y != y ) {
8585
printf( "should not return NaN\n" );
8686
break;
8787
}
8888
}
8989
elapsed = tic() - t;
90-
if ( log_pmf != log_pmf ) {
90+
if ( y != y ) {
9191
printf( "should not return NaN\n" );
9292
}
9393
return elapsed;
@@ -97,6 +97,7 @@ int main( void ) {
9797
double elapsed;
9898
int i;
9999

100+
// Use the current time to seed the random number generator:
100101
srand( time( NULL ) );
101102

102103
print_version();

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/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/logpmf.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 log_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-
log_pmf = stdlib_base_dists_hypergeometric_logpmf( x, N, K, n );
43-
printf( "x: %lf, N: %lf, K: %lf, n: %lf, ln(P(X=x;N,K,n)): %lf\n", x, N, K, n, log_pmf );
43+
y = stdlib_base_dists_hypergeometric_logpmf( x, N, K, n );
44+
printf( "x: %lf, N: %d, K: %d, n: %d, ln(P(X=x;N,K,n)): %lf\n", x, N, K, n, y );
4445
}
4546
}

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' );
2828
/**
2929
* Evaluates the natural logarithm of the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K` and number of draws `n`.
3030
*
31+
* @private
3132
* @param {number} x - input value
3233
* @param {NonNegativeInteger} N - population size
3334
* @param {NonNegativeInteger} K - subpopulation size
@@ -51,31 +52,15 @@ var addon = require( './../src/addon.node' );
5152
* // returns -Infinity
5253
*
5354
* @example
54-
* var y = logpmf( NaN, 10, 5, 2 );
55+
* var y = logpmf( 2.0, -10, 5, 2 );
5556
* // returns NaN
5657
*
5758
* @example
58-
* var y = logpmf( 0.0, NaN, 5, 2 );
59+
* var y = logpmf( 2.0, 10, -5, 2 );
5960
* // returns NaN
6061
*
6162
* @example
62-
* var y = logpmf( 0.0, 10, NaN, 2 );
63-
* // returns NaN
64-
*
65-
* @example
66-
* var y = logpmf( 0.0, 10, 5, NaN );
67-
* // returns NaN
68-
*
69-
* @example
70-
* var y = logpmf( 2.0, 10.5, 5, 2 );
71-
* // returns NaN
72-
*
73-
* @example
74-
* var y = logpmf( 2.0, 5, 1.5, 2 );
75-
* // returns NaN
76-
*
77-
* @example
78-
* var y = logpmf( 2.0, 10, 5, -2.0 );
63+
* var y = logpmf( 2.0, 10, 5, -2 );
7964
* // returns NaN
8065
*
8166
* @example

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
"dependencies": [
4141
"@stdlib/math/base/napi/quaternary",
4242
"@stdlib/math/base/assert/is-nonnegative-integer",
43-
"@stdlib/math/base/assert/is-nan",
44-
"@stdlib/constants/float64/pinf",
4543
"@stdlib/constants/float64/ninf",
4644
"@stdlib/math/base/special/factorialln",
4745
"@stdlib/math/base/special/max",
@@ -61,8 +59,6 @@
6159
"libpath": [],
6260
"dependencies": [
6361
"@stdlib/math/base/assert/is-nonnegative-integer",
64-
"@stdlib/math/base/assert/is-nan",
65-
"@stdlib/constants/float64/pinf",
6662
"@stdlib/constants/float64/ninf",
6763
"@stdlib/math/base/special/factorialln",
6864
"@stdlib/math/base/special/max",
@@ -83,8 +79,6 @@
8379
"libpath": [],
8480
"dependencies": [
8581
"@stdlib/math/base/assert/is-nonnegative-integer",
86-
"@stdlib/math/base/assert/is-nan",
87-
"@stdlib/constants/float64/pinf",
8882
"@stdlib/constants/float64/ninf",
8983
"@stdlib/math/base/special/factorialln",
9084
"@stdlib/math/base/special/max",

0 commit comments

Comments
 (0)