Skip to content

Commit adfe97b

Browse files
committed
refactor: apply code review suggestions
1 parent 82c7b7f commit adfe97b

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ The function accepts the following arguments:
207207
- **N**: `[in] CBLAS_INT` number of indexed elements.
208208
- **X**: `[in] double*` input array.
209209
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
210-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
210+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
211211
212212
```c
213213
double stdlib_strided_dnannsumkbn( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n );
@@ -231,7 +231,7 @@ The function accepts the following arguments:
231231
- **X**: `[in] double*` input array.
232232
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
233233
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
234-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
234+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
235235
236236
```c
237237
double stdlib_strided_dnannsumkbn_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n );

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static double benchmark1( int iterations, int len ) {
114114
n = 0;
115115
t = tic();
116116
for ( i = 0; i < iterations; i++ ) {
117+
// cppcheck-suppress uninitvar
117118
v = stdlib_strided_dnannsumkbn( len, x, 1, &n );
118119
if ( v != v || n < 0 ) {
119120
printf( "should not return NaN\n" );
@@ -153,6 +154,7 @@ static double benchmark2( int iterations, int len ) {
153154
n = 0;
154155
t = tic();
155156
for ( i = 0; i < iterations; i++ ) {
157+
// cppcheck-suppress uninitvar
156158
v = stdlib_strided_dnannsumkbn_ndarray( len, x, 1, 0, &n );
157159
if ( v != v || n < 0 ) {
158160
printf( "should not return NaN\n" );

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ function dnannsumkbn( N, x, strideX, out, strideOut ) {
5858
var io;
5959

6060
ix = stride2offset( N, strideX );
61-
if ( strideOut < 0 ) {
62-
io = -strideOut;
63-
} else {
64-
io = 0;
65-
}
61+
io = stride2offset( 2, strideOut );
6662
return ndarray( N, x, strideX, ix, out, strideOut, io );
6763
}
6864

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,27 @@ var abs = require( '@stdlib/math/base/special/abs' );
5858
function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
5959
var sum;
6060
var ix;
61-
var io;
6261
var v;
6362
var t;
6463
var c;
6564
var n;
6665
var i;
6766

6867
sum = 0.0;
69-
io = offsetOut;
7068
if ( N <= 0 ) {
71-
out[ io ] = sum;
72-
out[ io+strideOut ] = 0;
69+
out[ offsetOut ] = sum;
70+
out[ offsetOut+strideOut ] = 0;
7371
return out;
7472
}
7573
ix = offsetX;
7674
if ( strideX === 0 ) {
7775
if ( isnan( x[ ix ] ) ) {
78-
out[ io ] = sum;
79-
out[ io+strideOut ] = 0;
76+
out[ offsetOut ] = sum;
77+
out[ offsetOut+strideOut ] = 0;
8078
return out;
8179
}
82-
out[ io ] = x[ ix ] * N;
83-
out[ io+strideOut ] = N;
80+
out[ offsetOut ] = x[ ix ] * N;
81+
out[ offsetOut+strideOut ] = N;
8482
return out;
8583
}
8684
c = 0.0;
@@ -99,8 +97,8 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
9997
}
10098
ix += strideX;
10199
}
102-
out[ io ] = sum + c;
103-
out[ io+strideOut ] = n;
100+
out[ offsetOut ] = sum + c;
101+
out[ offsetOut+strideOut ] = n;
104102
return out;
105103
}
106104

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "stdlib/napi/argv.h"
2323
#include "stdlib/napi/argv_int64.h"
2424
#include "stdlib/napi/argv_strided_float64array.h"
25+
#include "stdlib/strided/base/stride2offset.h"
26+
#include <stdint.h>
2527
#include <node_api.h>
2628

2729
/**
@@ -39,17 +41,10 @@ static napi_value addon( napi_env env, napi_callback_info info ) {
3941
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
4042
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 3 );
4143

42-
int io;
43-
if ( strideOut < 0 ) {
44-
io = -strideOut;
45-
} else {
46-
io = 0;
47-
}
48-
49-
double *out = Out;
44+
int64_t io = stdlib_strided_stride2offset( 2, strideOut );
5045
CBLAS_INT n;
51-
out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n );
52-
out[ io+strideOut ] = (double)n;
46+
Out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n );
47+
Out[ io+strideOut ] = (double)n;
5348

5449
return NULL;
5550
}
@@ -71,11 +66,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) {
7166
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
7267
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 );
7368

74-
int io = offsetOut;
75-
double *out = Out;
7669
CBLAS_INT n;
77-
out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n );
78-
out[ io+strideOut ] = (double)n;
70+
Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n );
71+
Out[ offsetOut+strideOut ] = (double)n;
7972

8073
return NULL;
8174
}

lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @param N number of indexed elements
3737
* @param X input array
3838
* @param strideX stride length
39-
* @param n number of non-NaN elements
39+
* @param n pointer for storing the number of non-NaN elements
4040
* @return output value
4141
*/
4242
double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) {
@@ -59,13 +59,13 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *
5959
* @param X input array
6060
* @param strideX stride length
6161
* @param offsetX starting index
62-
* @param n number of non-NaN elements
62+
* @param n pointer for storing the number of non-NaN elements
6363
* @return output value
6464
*/
6565
double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) {
66-
double sum;
6766
CBLAS_INT ix;
6867
CBLAS_INT i;
68+
double sum;
6969
double v;
7070
double t;
7171
double c;

0 commit comments

Comments
 (0)