Skip to content

Commit e6d4d6c

Browse files
committed
refactor: apply review changes
1 parent ec105ce commit e6d4d6c

File tree

6 files changed

+26
-38
lines changed

6 files changed

+26
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ The function accepts the following arguments:
208208
- **N**: `[in] CBLAS_INT` number of indexed elements.
209209
- **X**: `[in] double*` input array.
210210
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
211-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
211+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
212212
213213
```c
214214
double stdlib_strided_dnannsumpw( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n );
@@ -232,7 +232,7 @@ The function accepts the following arguments:
232232
- **X**: `[in] double*` input array.
233233
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
234234
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
235-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
235+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
236236
237237
```c
238238
double stdlib_strided_dnannsumpw_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/dnannsumpw/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_dnannsumpw( 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_dnannsumpw_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/dnannsumpw/lib/dnannsumpw.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ function dnannsumpw( 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/dnannsumpw/lib/sumpw.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ var BLOCKSIZE = 128;
6565
*/
6666
function sumpw( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
6767
var ix;
68-
var io;
6968
var s0;
7069
var s1;
7170
var s2;
@@ -84,13 +83,12 @@ function sumpw( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
8483
return out;
8584
}
8685
ix = offsetX;
87-
io = offsetOut;
8886
if ( strideX === 0 ) {
8987
if ( isnan( x[ ix ] ) ) {
9088
return out;
9189
}
92-
out[ io ] += x[ ix ] * N;
93-
out[ io+strideOut ] += N;
90+
out[ offsetOut ] += x[ ix ] * N;
91+
out[ offsetOut+strideOut ] += N;
9492
return out;
9593
}
9694
if ( N < 8 ) {
@@ -105,8 +103,8 @@ function sumpw( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
105103
}
106104
ix += strideX;
107105
}
108-
out[ io ] += s;
109-
out[ io+strideOut ] += n;
106+
out[ offsetOut ] += s;
107+
out[ offsetOut+strideOut ] += n;
110108
return out;
111109
}
112110
if ( N <= BLOCKSIZE ) {
@@ -184,8 +182,8 @@ function sumpw( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
184182
}
185183
ix += strideX;
186184
}
187-
out[ io ] += s;
188-
out[ io+strideOut ] += n;
185+
out[ offsetOut ] += s;
186+
out[ offsetOut+strideOut ] += n;
189187
return out;
190188
}
191189
// Recurse by dividing by two, but avoiding non-multiples of unroll factor...

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

Lines changed: 7 additions & 15 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,18 +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-
}
46-
else {
47-
io = 0;
48-
}
49-
50-
double *out = Out;
44+
int64_t io = stdlib_strided_stride2offset( 2, strideOut );
5145
CBLAS_INT n;
52-
out[ io ] = API_SUFFIX(stdlib_strided_dnannsumpw)( N, X, strideX, &n );
53-
out[ io + strideOut ] = (double)n;
46+
Out[ io ] = API_SUFFIX(stdlib_strided_dnannsumpw)( N, X, strideX, &n );
47+
Out[ io + strideOut ] = (double)n;
5448

5549
return NULL;
5650
}
@@ -72,11 +66,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) {
7266
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
7367
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 );
7468

75-
int io = offsetOut;
76-
double *out = Out;
7769
CBLAS_INT n;
78-
out[ io ] = API_SUFFIX(stdlib_strided_dnannsumpw_ndarray)( N, X, strideX, offsetX, &n );
79-
out[ io+strideOut ] = (double)n;
70+
Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dnannsumpw_ndarray)( N, X, strideX, offsetX, &n );
71+
Out[ offsetOut+strideOut ] = (double)n;
8072

8173
return NULL;
8274
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828
* @param X input array
2929
* @param strideX stride length
3030
* @param offsetX starting index
31-
* @param n number of non-NaN elements
31+
* @param n pointer for storing the number of non-NaN elements
3232
* @return output value
3333
*/
3434
static double API_SUFFIX(stdlib_strided_sumpw)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) {
35-
double sum1;
36-
double sum2;
37-
double sum;
3835
CBLAS_INT ix;
36+
CBLAS_INT n1;
37+
CBLAS_INT n2;
3938
CBLAS_INT M;
4039
CBLAS_INT m;
4140
CBLAS_INT i;
41+
double sum1;
42+
double sum2;
43+
double sum;
4244
double s0;
4345
double s1;
4446
double s2;
@@ -47,8 +49,6 @@ static double API_SUFFIX(stdlib_strided_sumpw)( const CBLAS_INT N, const double
4749
double s5;
4850
double s6;
4951
double s7;
50-
CBLAS_INT n1;
51-
CBLAS_INT n2;
5252
double v;
5353

5454
sum = 0.0;
@@ -180,7 +180,7 @@ static double API_SUFFIX(stdlib_strided_sumpw)( const CBLAS_INT N, const double
180180
* @param N number of indexed elements
181181
* @param X input array
182182
* @param strideX stride length
183-
* @param n number of non-NaN elements
183+
* @param n pointer for storing the number of non-NaN elements
184184
* @return output value
185185
*/
186186
double API_SUFFIX(stdlib_strided_dnannsumpw)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) {
@@ -203,7 +203,7 @@ double API_SUFFIX(stdlib_strided_dnannsumpw)( const CBLAS_INT N, const double *X
203203
* @param X input array
204204
* @param strideX stride length
205205
* @param offsetX starting index
206-
* @param n number of non-NaN elements
206+
* @param n pointer for storing the number of non-NaN elements
207207
* @return output value
208208
*/
209209
double API_SUFFIX(stdlib_strided_dnannsumpw_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) {

0 commit comments

Comments
 (0)