Skip to content

Commit d5d2acb

Browse files
PlaneshifterLokeshranjan8
authored andcommitted
refactor: type n as an int32
--- 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: 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: 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 ---
1 parent 04dd93c commit d5d2acb

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ double out = stdlib_base_dists_signrank_pdf( 7.0, 9 );
164164
The function accepts the following arguments:
165165

166166
- **x**: `[in] double` input value.
167-
- **n**: `[in] double` number of observations.
167+
- **n**: `[in] int32_t` number of observations.
168168

169169
```c
170-
double stdlib_base_dists_signrank_pdf( double x, const double n );
170+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n );
171171
```
172172
173173
</section>
@@ -193,23 +193,24 @@ double stdlib_base_dists_signrank_pdf( double x, const double n );
193193
#include "stdlib/math/base/special/ceil.h"
194194
#include <stdlib.h>
195195
#include <stdio.h>
196+
#include <stdint.h>
196197
197198
static double random_uniform( const double min, const double max ) {
198199
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
199200
return min + ( v*(max-min) );
200201
}
201202
202203
int main( void ) {
203-
double n;
204+
int32_t n;
204205
double x;
205206
double y;
206207
int i;
207208
208209
for ( i = 0; i < 25; i++ ) {
209210
x = random_uniform( 0, 30.0 );
210-
n = stdlib_base_ceil(random_uniform( 1, 30.0 ));
211+
n = (int32_t)stdlib_base_ceil(random_uniform( 1.0, 30.0 ));
211212
y = stdlib_base_dists_signrank_pdf( x, n );
212-
printf( "x: %lf, n: %lf, F(x;n): %lf\n", x, n, y );
213+
printf( "x: %lf, n: %d, f(x;n): %lf\n", x, n, y );
213214
}
214215
}
215216
```

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/benchmark/c/benchmark.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <math.h>
2424
#include <time.h>
2525
#include <sys/time.h>
26+
#include <stdint.h>
2627

2728
#define NAME "signrank-pdf"
2829
#define ITERATIONS 1000000
@@ -95,14 +96,14 @@ static double random_uniform( const double min, const double max ) {
9596
static double benchmark( void ) {
9697
double elapsed;
9798
double x[ 100 ];
98-
double n[ 100 ];
99+
int32_t n[ 100 ];
99100
double y;
100101
double t;
101102
int i;
102103

103104
for ( i = 0; i < 100; i++ ) {
104105
x[ i ] = random_uniform( 0.0, 30.0 );
105-
n[ i ] = stdlib_base_ceil(random_uniform( 1.0, 30.0 ));
106+
n[ i ] = (int32_t)stdlib_base_ceil(random_uniform( 1.0, 30.0 ));
106107
}
107108

108109
t = tic();

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/examples/c/example.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@
2020
#include "stdlib/math/base/special/ceil.h"
2121
#include <stdlib.h>
2222
#include <stdio.h>
23+
#include <stdint.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 n;
31+
int32_t n;
3132
double x;
3233
double y;
3334
int i;
3435

3536
for ( i = 0; i < 25; i++ ) {
3637
x = random_uniform( 0, 30.0 );
37-
n = stdlib_base_ceil(random_uniform( 1, 30.0 ));
38+
n = (int32_t)stdlib_base_ceil(random_uniform( 1.0, 30.0 ));
3839
y = stdlib_base_dists_signrank_pdf( x, n );
39-
printf( "x: %lf, n: %lf, F(x;n): %lf\n", x, n, y );
40+
printf( "x: %lf, n: %d, f(x;n): %lf\n", x, n, y );
4041
}
4142
}

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/include/stdlib/stats/base/dists/signrank/pdf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef STDLIB_STATS_BASE_DISTS_SIGNRANK_PDF_H
2020
#define STDLIB_STATS_BASE_DISTS_SIGNRANK_PDF_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
*/
@@ -29,7 +31,7 @@ extern "C" {
2931
/**
3032
* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.
3133
*/
32-
double stdlib_base_dists_signrank_pdf( double x, const double n );
34+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n );
3335

3436
#ifdef __cplusplus
3537
}

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/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/binary.h"
2121

2222
// cppcheck-suppress shadowFunction
23-
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_signrank_pdf )
23+
STDLIB_MATH_BASE_NAPI_MODULE_DI_D( stdlib_base_dists_signrank_pdf )

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/src/main.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/signrank/pdf.h"
20-
#include "stdlib/math/base/assert/is_positive_integer.h"
2120
#include "stdlib/math/base/assert/is_integer.h"
22-
#include "stdlib/math/base/assert/is_finite.h"
2321
#include "stdlib/math/base/assert/is_nan.h"
2422
#include "stdlib/math/base/special/exp.h"
2523
#include "stdlib/constants/float64/ln_two.h"
2624
#include "stdlib/math/base/special/ln.h"
25+
#include <stdint.h>
2726

2827
/**
2928
* Calculates the weight for the `(x,n)` pair and memoizes the result.
@@ -33,20 +32,20 @@
3332
* @param {NonNegativeInteger} n - number of observations
3433
* @returns {number} weight
3534
*/
36-
static double weights( double x, const double n ) {
35+
static double weights( double x, const int32_t n ) {
3736
double mlim;
3837

3938
if ( n == 0 ) {
4039
return ( x == 0 ) ? 1 : 0;
4140
}
42-
mlim = n * ( n + 1 ) / 2;
41+
mlim = ( (double)n * ( (double)n + 1.0 ) ) / 2.0;
4342
if ( x < 0 || x > mlim ) {
4443
return 0;
4544
}
4645
if ( x > mlim / 2 ) {
4746
x = mlim - x;
4847
}
49-
return weights( x - n, n - 1 ) + weights( x, n - 1 );
48+
return weights( x - (double)n, n - 1 ) + weights( x, n - 1 );
5049
}
5150

5251
/**
@@ -84,21 +83,17 @@ static double weights( double x, const double n ) {
8483
* var y = pdf( 2.0, 1.8 );
8584
* // returns NaN
8685
*/
87-
double stdlib_base_dists_signrank_pdf( const double x, const double n ) {
86+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n ) {
8887
double mlim;
89-
if (
90-
stdlib_base_is_nan( x ) ||
91-
!stdlib_base_is_positive_integer( n ) ||
92-
!stdlib_base_is_finite( n )
93-
) {
88+
if ( stdlib_base_is_nan( x ) || n <= 0 ) {
9489
return 0.0/0.0;
9590
}
9691
if ( !stdlib_base_is_integer( x ) ) {
9792
return 0.0;
9893
}
99-
mlim = ( n * ( n + 1 ) ) / 2;
94+
mlim = ( (double)n * ( (double)n + 1.0 ) ) / 2.0;
10095
if ( x < 0.0 || x > mlim ) {
10196
return 0.0;
10297
}
103-
return stdlib_base_exp( stdlib_base_ln( weights( x, n ) ) - ( n * STDLIB_CONSTANT_FLOAT64_LN2 ) );
98+
return stdlib_base_exp( stdlib_base_ln( weights( x, n ) ) - ( (double)n * STDLIB_CONSTANT_FLOAT64_LN2 ) );
10499
}

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/test/test.native.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ tape( 'if not provided a positive integer for `n`, the function returns `NaN`',
7676
y = pdf( 2.0, NINF );
7777
t.equal( isnan( y ), true, 'returns NaN' );
7878

79-
y = pdf( 2.0, 6.9 );
80-
t.equal( isnan( y ), true, 'returns NaN' );
81-
8279
y = pdf( 2.0, PINF );
8380
t.equal( isnan( y ), true, 'returns NaN' );
8481

@@ -115,7 +112,7 @@ tape( 'the function evaluates the PDF for `x` given `n` observations', opts, fun
115112
t.equal( y, expected[i], 'x: '+x[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] );
116113
} else {
117114
delta = abs( y - expected[ i ] );
118-
tol = 20.0 * EPS * abs( expected[ i ] );
115+
tol = 80.0 * EPS * abs( expected[ i ] );
119116
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
120117
}
121118
}

0 commit comments

Comments
 (0)