Skip to content

Commit 02b120c

Browse files
chore: updated double with int32_t
--- 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: failed ---
1 parent 58013ed commit 02b120c

File tree

10 files changed

+41
-107
lines changed

10 files changed

+41
-107
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ double out = stdlib_base_dists_binomial_pmf( 3.0, 20, 0.2 );
187187

188188
The function accepts the following arguments:
189189

190-
- **x**: `[in] int` input value.
191-
- **n**: `[in] int` number of trials.
190+
- **x**: `[in] int32_t` input value.
191+
- **n**: `[in] int32_t` number of trials.
192192
- **p**: `[in] double` success probability.
193193

194194
```c
195-
double stdlib_base_dists_binomial_pmf( const double x, const double n, const double p );
195+
double stdlib_base_dists_binomial_pmf( const int32_t x, const int32_t n, const double p );
196196
```
197197
198198
</section>
@@ -217,6 +217,7 @@ double stdlib_base_dists_binomial_pmf( const double x, const double n, const dou
217217
#include "stdlib/stats/base/dists/binomial/pmf.h"
218218
#include "stdlib/math/base/special/ceil.h"
219219
#include <stdlib.h>
220+
#include <stdint.h>
220221
#include <stdio.h>
221222
222223
static double random_uniform( const double min, const double max ) {
@@ -225,18 +226,18 @@ static double random_uniform( const double min, const double max ) {
225226
}
226227
227228
int main( void ) {
228-
double n;
229+
int32_t n;
229230
double p;
230-
double x;
231+
int32_t x;
231232
double y;
232233
int i;
233234
234235
for ( i = 0; i < 25; i++ ) {
235-
n = stdlib_base_ceil( random_uniform( 0, 100 ) );
236-
p = random_uniform( 0, 1 );
237-
x = random_uniform( 0, 50 );
236+
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
237+
p = random_uniform( 0.0, 1.0 );
238+
x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) );
238239
y = stdlib_base_dists_binomial_pmf( x, n, p );
239-
printf( "x: %lf, n: %lf, p: %lf, P(X=x;n,p): %lf\n", x, n, p, y );
240+
printf( "x: %d, n: %d, p: %lf, P(X=x;n,p): %lf\n", x, n, p, y );
240241
}
241242
242243
return 0;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24+
var Int32Array = require( '@stdlib/array/int32' );
2425
var Float64Array = require( '@stdlib/array/float64' );
2526
var ceil = require( '@stdlib/math/base/special/ceil' );
2627
var randu = require( '@stdlib/random/base/randu' );
@@ -40,13 +41,13 @@ bench( pkg, function benchmark( b ) {
4041
var i;
4142

4243
len = 100;
43-
n = new Float64Array( len );
44+
n = new Int32Array( len );
4445
p = new Float64Array( len );
45-
x = new Float64Array( len );
46+
x = new Int32Array( len );
4647
for ( i = 0; i < len; i++ ) {
4748
n[ i ] = ceil( randu()*100.0 );
4849
p[ i ] = randu();
49-
x[ i ] = randu()*50.0;
50+
x[ i ] = ceil( randu()*50.0 );
5051
}
5152

5253
b.tic();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25+
var Int32Array = require( '@stdlib/array/int32' );
2526
var Float64Array = require( '@stdlib/array/float64' );
2627
var tryRequire = require( '@stdlib/utils/try-require' );
2728
var ceil = require( '@stdlib/math/base/special/ceil' );
@@ -49,13 +50,13 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4950
var i;
5051

5152
len = 100;
52-
n = new Float64Array( len );
53+
n = new Int32Array( len );
5354
p = new Float64Array( len );
54-
x = new Float64Array( len );
55+
x = new Int32Array( len );
5556
for ( i = 0; i < len; i++ ) {
5657
n[ i ] = ceil( randu()*100.0 );
5758
p[ i ] = randu();
58-
x[ i ] = randu()*50.0;
59+
x[ i ] = ceil( randu()*50.0 );
5960
}
6061

6162
b.tic();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "stdlib/stats/base/dists/binomial/pmf.h"
2020
#include "stdlib/math/base/special/ceil.h"
2121
#include <stdlib.h>
22+
#include <stdint.h>
2223
#include <stdio.h>
2324
#include <math.h>
2425
#include <time.h>
@@ -94,17 +95,17 @@ static double random_uniform( const double min, const double max ) {
9495
*/
9596
static double benchmark( void ) {
9697
double elapsed;
97-
double n[ 100 ];
98+
int32_t n[ 100 ];
9899
double p[ 100 ];
99-
double x[ 100 ];
100+
int32_t x[ 100 ];
100101
double y;
101102
double t;
102103
int i;
103104

104105
for ( i = 0; i < 100; i++ ) {
105-
n[ i ] = stdlib_base_ceil( random_uniform( 0, 100 ) );
106-
p[ i ] = random_uniform( 0, 1 );
107-
x[ i ] = random_uniform( 0, 50);
106+
n[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
107+
p[ i ] = random_uniform( 0.0, 1.0 );
108+
x[ i ] = stdlib_base_ceil( random_uniform( 0.0, 50.0) );
108109
}
109110

110111
t = tic();

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "stdlib/stats/base/dists/binomial/pmf.h"
2020
#include "stdlib/math/base/special/ceil.h"
2121
#include <stdlib.h>
22+
#include <stdint.h>
2223
#include <stdio.h>
2324

2425
static double random_uniform( const double min, const double max ) {
@@ -27,18 +28,18 @@ static double random_uniform( const double min, const double max ) {
2728
}
2829

2930
int main( void ) {
30-
double n;
31+
int32_t n;
3132
double p;
32-
double x;
33+
int32_t x;
3334
double y;
3435
int i;
3536

3637
for ( i = 0; i < 25; i++ ) {
37-
n = stdlib_base_ceil( random_uniform( 0, 100 ) );
38-
p = random_uniform( 0, 1 );
39-
x = random_uniform( 0, 50 );
38+
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
39+
p = random_uniform( 0.0, 1.0 );
40+
x = stdlib_base_ceil( random_uniform( 0.0, 50.0 ) );
4041
y = stdlib_base_dists_binomial_pmf( x, n, p );
41-
printf( "x: %lf, n: %lf, p: %lf, P(X=x;n,p): %lf\n", x, n, p, y );
42+
printf( "x: %d, n: %d, p: %lf, P(X=x;n,p): %lf\n", x, n, p, y );
4243
}
4344

4445
return 0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Returns the probability mass function (PMF) of a binomial distribution.
30+
* Returns the probability mass function (PMF) for a binomial distribution with number of trials `n` and success probability `p` at a value `x`.
3131
*/
32-
double stdlib_base_dists_binomial_pmf( const double x, const double n, const double p );
32+
double stdlib_base_dists_binomial_pmf( const int32_t x, const int32_t n, const double p );
3333

3434
#ifdef __cplusplus
3535
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,10 @@ var addon = require( './../src/addon.node' );
5151
* // returns ~0.006
5252
*
5353
* @example
54-
* var y = pmf( NaN, 20, 0.5 );
55-
* // returns NaN
56-
*
57-
* @example
58-
* var y = pmf( 0.0, NaN, 0.5 );
59-
* // returns NaN
60-
*
61-
* @example
6254
* var y = pmf( 0.0, 20, NaN );
6355
* // returns NaN
6456
*
6557
* @example
66-
* var y = pmf( 2.0, 1.5, 0.5 );
67-
* // returns NaN
68-
*
69-
* @example
7058
* var y = pmf( 2.0, -2.0, 0.5 );
7159
* // returns NaN
7260
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
#include "stdlib/math/base/napi/ternary.h"
2121

2222
// cppcheck-suppress shadowFunction
23-
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_binomial_pmf );
23+
STDLIB_MATH_BASE_NAPI_MODULE_IID_D( stdlib_base_dists_binomial_pmf );

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,30 @@
2424
#include "stdlib/math/base/special/log1p.h"
2525
#include "stdlib/math/base/special/ln.h"
2626
#include "stdlib/math/base/special/exp.h"
27+
#include <stdint.h>
2728

2829
/**
2930
* Evaluates the probability mass function (PMF) for a binomial distribution with number of trials `n` and success probability `p` at a value `x`.
3031
*
3132
* @param x input value
3233
* @param n number of trials
3334
* @param p success probability
34-
* @return evaluated logPMF
35+
* @return evaluated PMF
3536
*
3637
* @example
3738
* double y = stdlib_base_dists_binomial_pmf( 3.0, 20, 0.2 );
3839
* // returns ~0.205
3940
*/
40-
double stdlib_base_dists_binomial_pmf( const double x, const double n, const double p ) {
41+
double stdlib_base_dists_binomial_pmf( const int32_t x, const int32_t n, const double p ) {
4142
if (
42-
stdlib_base_is_nan( x ) ||
43-
stdlib_base_is_nan( n ) ||
4443
stdlib_base_is_nan( p ) ||
4544
n < 0.0 ||
4645
p < 0.0 ||
47-
p > 1.0 ||
48-
!stdlib_base_is_nonnegative_integer( n ) ||
49-
n == STDLIB_CONSTANT_FLOAT64_PINF
46+
p > 1.0
5047
) {
5148
return 0.0 / 0.0;
5249
}
53-
if ( stdlib_base_is_nonnegative_integer( x ) ){
50+
if ( x >= 0 ){
5451
if ( x > n ) {
5552
return 0.0;
5653
}

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

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,14 @@ tape( 'main export is a function', function test( t ) {
5555
});
5656

5757
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
58-
var y = pmf( NaN, 20, 0.5 );
59-
t.equal( isnan( y ), true, 'returns NaN' );
60-
y = pmf( 0.0, NaN, 0.5 );
61-
t.equal( isnan( y ), true, 'returns NaN' );
58+
var y;
6259
y = pmf( 0.0, 20, NaN );
6360
t.equal( isnan( y ), true, 'returns NaN' );
6461
t.end();
6562
});
6663

6764
tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the function returns `0`', opts, function test( t ) {
68-
var y = pmf( NINF, 20, 0.5 );
69-
t.equal( y, 0.0, 'returns 0' );
65+
var y;
7066

7167
y = pmf( -20.0, 20, 0.5 );
7268
t.equal( y, 0.0, 'returns 0' );
@@ -80,37 +76,12 @@ tape( 'if provided a negative integer for `x` and a valid `n` and `p`, the funct
8076
t.end();
8177
});
8278

83-
tape( 'if provided a non-integer for `x` and a valid `n` and `p`, the function returns `0`', opts, function test( t ) {
84-
var y = pmf( -1.5, 20, 0.5 );
85-
t.equal( y, 0.0, 'returns 0' );
86-
87-
y = pmf( -0.5, 20, 0.5 );
88-
t.equal( y, 0.0, 'returns 0' );
89-
90-
y = pmf( 1.5, 20, 0.5 );
91-
t.equal( y, 0.0, 'returns 0' );
92-
93-
y = pmf( 2.5, 20, 0.5 );
94-
t.equal( y, 0.0, 'returns 0' );
95-
96-
t.end();
97-
});
98-
9979
tape( 'if provided `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) {
10080
var y;
10181

102-
y = pmf( 2.0, 1.5, 0.5 );
103-
t.equal( isnan( y ), true, 'returns NaN' );
104-
10582
y = pmf( 0.0, -1.0, 0.5 );
10683
t.equal( isnan( y ), true, 'returns NaN' );
10784

108-
y = pmf( 2.0, NINF, 0.5 );
109-
t.equal( isnan( y ), true, 'returns NaN' );
110-
111-
y = pmf( 2.0, PINF, 0.5 );
112-
t.equal( isnan( y ), true, 'returns NaN' );
113-
11485
t.end();
11586
});
11687

@@ -142,31 +113,13 @@ tape( 'if `p` or `n` equals `0`, the function evaluates a degenerate distributio
142113
y = pmf( 1.0, 8, 0.0 );
143114
t.equal( y, 0.0, 'returns 0' );
144115

145-
y = pmf( PINF, 8, 0.0 );
146-
t.equal( y, 0.0, 'returns 0' );
147-
148-
y = pmf( NINF, 8, 0.0 );
149-
t.equal( y, 0.0, 'returns 0' );
150-
151-
y = pmf( NaN, 8, 0.0 );
152-
t.equal( isnan( y ), true, 'returns NaN' );
153-
154116
// Case: n = 0, p = 0.5
155117
y = pmf( 0.0, 0, 0.5 );
156118
t.equal( y, 1.0, 'returns 1 for x equal to 0' );
157119

158120
y = pmf( 1.0, 0, 0.5 );
159121
t.equal( y, 0.0, 'returns 0' );
160122

161-
y = pmf( PINF, 0, 0.5 );
162-
t.equal( y, 0.0, 'returns 0' );
163-
164-
y = pmf( NINF, 0, 0.5 );
165-
t.equal( y, 0.0, 'returns 0' );
166-
167-
y = pmf( NaN, 0, 0.5 );
168-
t.equal( isnan( y ), true, 'returns NaN' );
169-
170123
t.end();
171124
});
172125

@@ -179,15 +132,6 @@ tape( 'if `p` equals `1.0`, the function evaluates a degenerate distribution cen
179132
y = pmf( 1.0, 8, 1.0 );
180133
t.equal( y, 0.0, 'returns 0' );
181134

182-
y = pmf( PINF, 8, 1.0 );
183-
t.equal( y, 0.0, 'returns 0' );
184-
185-
y = pmf( NINF, 8, 1.0 );
186-
t.equal( y, 0.0, 'returns 0' );
187-
188-
y = pmf( NaN, 8, 1.0 );
189-
t.equal( isnan( y ), true, 'returns NaN' );
190-
191135
t.end();
192136
});
193137

0 commit comments

Comments
 (0)