Skip to content

Commit 3e53e85

Browse files
committed
fix: address review comments
--- 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: 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: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 117c9d1 commit 3e53e85

7 files changed

Lines changed: 28 additions & 21 deletions

File tree

lib/node_modules/@stdlib/stats/strided/dnancount/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var dnancount = require( '@stdlib/stats/strided/dnancount' );
3838

3939
#### dnancount( N, x, strideX )
4040

41-
Computes the number of non-`NaN` elements in a double-precision floating-point strided array `x`.
41+
Computes the number of non-`NaN` elements in a double-precision floating-point strided array.
4242

4343
```javascript
4444
var Float64Array = require( '@stdlib/array/float64' );
@@ -135,7 +135,7 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' );
135135
var dnancount = require( '@stdlib/stats/strided/dnancount' );
136136

137137
function rand() {
138-
if ( bernoulli( 0.2 ) < 1 ) {
138+
if ( bernoulli( 0.8 ) < 1 ) {
139139
return NaN;
140140
}
141141
return uniform( -50.0, 50.0 );
@@ -179,7 +179,7 @@ Computes the number of non-`NaN` elements in a double-precision floating-point s
179179
```c
180180
const double x[] = { 1.0, 2.0, NaN, 4.0, 5.0, 6.0, NaN, 8.0 };
181181

182-
CBLAS_INT v = stdlib_strided_dnancount( 4, x, 2 );
182+
int v = stdlib_strided_dnancount( 4, x, 2 );
183183
// returns 2
184184
```
185185
@@ -200,12 +200,15 @@ Computes the number of non-`NaN` elements in a double-precision floating-point s
200200
```c
201201
const double x[] = { 2.0, 1.0, NaN, -2.0, 3.0, 4.0, NaN, NaN };
202202

203-
CBLAS_INT v = stdlib_strided_dnancount_ndarray( 4, x, 2, 1 );
203+
int v = stdlib_strided_dnancount_ndarray( 4, x, 2, 1 );
204204
// returns 3
205205
```
206206
207-
The function accepts the following additional argument:
207+
The function accepts the following arguments:
208208
209+
- **N**: `[in] CBLAS_INT` number of indexed elements.
210+
- **X**: `[in] double*` input array.
211+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
209212
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
210213
211214
```c

lib/node_modules/@stdlib/stats/strided/dnancount/benchmark/c/benchmark.length.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ static double rand_double( void ) {
9797
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
double *x;
100-
CBLAS_INT v;
101100
double t;
101+
int v;
102102
int i;
103103

104104
x = (double *) malloc( len * sizeof( double ) );
@@ -109,16 +109,20 @@ static double benchmark1( int iterations, int len ) {
109109
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
110110
}
111111
}
112+
v = 0.0;
112113
t = tic();
113114
for ( i = 0; i < iterations; i++ ) {
114115
// cppcheck-suppress uninitvar
115116
v = stdlib_strided_dnancount( len, x, 1 );
116-
if ( v != v ) {
117-
printf( "should not return NaN\n" );
117+
if ( v < 0 ) {
118+
printf( "should return a non-negative integer\n" );
118119
break;
119120
}
120121
}
121122
elapsed = tic() - t;
123+
if ( v < 0 ) {
124+
printf( "should return a non-negative integer\n" );
125+
}
122126
free( x );
123127
return elapsed;
124128
}
@@ -133,8 +137,8 @@ static double benchmark1( int iterations, int len ) {
133137
static double benchmark2( int iterations, int len ) {
134138
double elapsed;
135139
double *x;
136-
CBLAS_INT v;
137140
double t;
141+
int v;
138142
int i;
139143

140144
x = (double *) malloc( len * sizeof( double ) );
@@ -145,16 +149,20 @@ static double benchmark2( int iterations, int len ) {
145149
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
146150
}
147151
}
152+
v = 0.0;
148153
t = tic();
149154
for ( i = 0; i < iterations; i++ ) {
150155
// cppcheck-suppress uninitvar
151156
v = stdlib_strided_dnancount_ndarray( len, x, 1, 0 );
152-
if ( v != v ) {
153-
printf( "should not return NaN\n" );
157+
if ( v < 0 ) {
158+
printf( "should return a non-negative integer\n" );
154159
break;
155160
}
156161
}
157162
elapsed = tic() - t;
163+
if ( v < 0 ) {
164+
printf( "should return a non-negative integer\n" );
165+
}
158166
free( x );
159167
return elapsed;
160168
}

lib/node_modules/@stdlib/stats/strided/dnancount/lib/dnancount.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var ndarray = require( './ndarray.js' );
3232
* @param {PositiveInteger} N - number of indexed elements
3333
* @param {Float64Array} x - input array
3434
* @param {integer} strideX - stride length
35-
* @returns {integer} number of non-`NaN` elements
35+
* @returns {NonNegativeInteger} number of non-`NaN` elements
3636
*
3737
* @example
3838
* var Float64Array = require( '@stdlib/array/float64' );

lib/node_modules/@stdlib/stats/strided/dnancount/lib/dnancount.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' );
3131
* @param {PositiveInteger} N - number of indexed elements
3232
* @param {Float64Array} x - input array
3333
* @param {integer} strideX - stride length
34-
* @returns {integer} number of non-`NaN` elements
34+
* @returns {NonNegativeInteger} number of non-`NaN` elements
3535
*
3636
* @example
3737
* var Float64Array = require( '@stdlib/array/float64' );

lib/node_modules/@stdlib/stats/strided/dnancount/lib/ndarray.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
3232
* @param {Float64Array} x - input array
3333
* @param {integer} strideX - stride length
3434
* @param {NonNegativeInteger} offsetX - starting index
35-
* @returns {integer} number of non-`NaN` elements
35+
* @returns {NonNegativeInteger} number of non-`NaN` elements
3636
*
3737
* @example
3838
* var Float64Array = require( '@stdlib/array/float64' );
@@ -45,7 +45,6 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
4545
function dnancount( N, x, strideX, offsetX ) {
4646
var count;
4747
var ix;
48-
var v;
4948
var i;
5049

5150
if ( N <= 0 ) {
@@ -54,8 +53,7 @@ function dnancount( N, x, strideX, offsetX ) {
5453
count = 0;
5554
ix = offsetX;
5655
for ( i = 0; i < N; i++ ) {
57-
v = x[ ix ];
58-
if ( !isnan( v ) ) {
56+
if ( !isnan( x[ ix ] ) ) {
5957
count += 1;
6058
}
6159
ix += strideX;

lib/node_modules/@stdlib/stats/strided/dnancount/lib/ndarray.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var addon = require( './../src/addon.node' );
3232
* @param {Float64Array} x - input array
3333
* @param {integer} strideX - stride length
3434
* @param {NonNegativeInteger} offsetX - starting index
35-
* @returns {integer} number of non-`NaN` elements
35+
* @returns {NonNegativeInteger} number of non-`NaN` elements
3636
*
3737
* @example
3838
* var Float64Array = require( '@stdlib/array/float64' );

lib/node_modules/@stdlib/stats/strided/dnancount/src/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ CBLAS_INT API_SUFFIX(stdlib_strided_dnancount_ndarray)( const CBLAS_INT N, const
4747
CBLAS_INT count;
4848
CBLAS_INT ix;
4949
CBLAS_INT i;
50-
double v;
5150

5251
if ( N <= 0 ) {
5352
return 0;
5453
}
5554
count = 0;
5655
ix = offsetX;
5756
for ( i = 0; i < N; i++ ) {
58-
v = X[ ix ];
59-
if ( !stdlib_base_is_nan( v ) ) {
57+
if ( !stdlib_base_is_nan( X[ ix ] ) ) {
6058
count += 1;
6159
}
6260
ix += strideX;

0 commit comments

Comments
 (0)