Skip to content

Commit a39d0f3

Browse files
authored
refactor: update offset handling and function documentation for blas/ext/base/dnannsumors
PR-URL: #3252 Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
1 parent 4458c49 commit a39d0f3

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ The function accepts the following arguments:
209209
- **N**: `[in] CBLAS_INT` number of indexed elements.
210210
- **X**: `[in] double*` input array.
211211
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
212-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
212+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
213213
214214
```c
215215
double stdlib_strided_dnannsumors( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n );
@@ -233,7 +233,7 @@ The function accepts the following arguments:
233233
- **X**: `[in] double*` input array.
234234
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
235235
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
236-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
236+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
237237
238238
```c
239239
double stdlib_strided_dnannsumors_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/dnannsumors/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_dnannsumors( 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_dnannsumors_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/dnannsumors/lib/ndarray.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,24 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
4949
function dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
5050
var sum;
5151
var ix;
52-
var io;
5352
var n;
5453
var i;
5554

5655
sum = 0.0;
57-
io = offsetOut;
5856
if ( N <= 0 ) {
59-
out[ io ] = sum;
60-
out[ io+strideOut ] = 0;
57+
out[ offsetOut ] = sum;
58+
out[ offsetOut+strideOut ] = 0;
6159
return out;
6260
}
6361
ix = offsetX;
6462
if ( strideX === 0 ) {
6563
if ( isnan( x[ ix ] ) ) {
66-
out[ io ] = sum;
67-
out[ io+strideOut ] = 0;
64+
out[ offsetOut ] = sum;
65+
out[ offsetOut+strideOut ] = 0;
6866
return out;
6967
}
70-
out[ io ] = x[ ix ] * N;
71-
out[ io+strideOut ] = N;
68+
out[ offsetOut ] = x[ ix ] * N;
69+
out[ offsetOut+strideOut ] = N;
7270
return out;
7371
}
7472
n = 0;
@@ -79,8 +77,8 @@ function dnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
7977
}
8078
ix += strideX;
8179
}
82-
out[ io ] = sum;
83-
out[ io+strideOut ] = n;
80+
out[ offsetOut ] = sum;
81+
out[ offsetOut+strideOut ] = n;
8482
return out;
8583
}
8684

lib/node_modules/@stdlib/blas/ext/base/dnannsumors/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_dnannsumors)( N, X, strideX, &n );
52-
out[ io + strideOut ] = (double)n;
46+
Out[ io ] = API_SUFFIX(stdlib_strided_dnannsumors)( 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_dnannsumors_ndarray)( N, X, strideX, offsetX, &n );
78-
out[ io+strideOut ] = (double)n;
70+
Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dnannsumors_ndarray)( N, X, strideX, offsetX, &n );
71+
Out[ offsetOut+strideOut ] = (double)n;
7972

8073
return NULL;
8174
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @param N number of indexed elements
2828
* @param X input array
2929
* @param strideX stride length
30-
* @param n number of non-NaN elements
30+
* @param n pointer for storing the number of non-NaN elements
3131
* @return output value
3232
*/
3333
double API_SUFFIX(stdlib_strided_dnannsumors)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) {
@@ -42,13 +42,13 @@ double API_SUFFIX(stdlib_strided_dnannsumors)( const CBLAS_INT N, const double *
4242
* @param X input array
4343
* @param strideX stride length
4444
* @param offsetX starting index
45-
* @param n number of non-NaN elements
45+
* @param n pointer for storing the number of non-NaN elements
4646
* @return output value
4747
*/
4848
double API_SUFFIX(stdlib_strided_dnannsumors_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) {
49-
double sum;
5049
CBLAS_INT ix;
5150
CBLAS_INT i;
51+
double sum;
5252

5353
sum = 0.0;
5454
*n = 0;

0 commit comments

Comments
 (0)