Skip to content

Commit 22b7505

Browse files
refactor: update offset handling and function documentation for blas/ext/base/dsnannsumors
PR-URL: #3129 Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent 2d0ea39 commit 22b7505

File tree

8 files changed

+31
-44
lines changed

8 files changed

+31
-44
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var v = dsnannsumors( 4, x1, 2, out1, 1 );
9292

9393
#### dsnannsumors.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
9494

95-
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics and returning an extended precision result.
95+
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
9696

9797
```javascript
9898
var Float32Array = require( '@stdlib/array/float32' );
@@ -202,7 +202,7 @@ console.log( out );
202202
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
203203

204204
```c
205-
const float x[] = { 1.0f, -2.0f, 0.0/0.0, 2.0f };
205+
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
206206
CBLAS_INT n = 0;
207207

208208
double v = stdlib_strided_dsnannsumors( 4, x, 1, &n );
@@ -214,18 +214,18 @@ The function accepts the following arguments:
214214
- **N**: `[in] CBLAS_INT` number of indexed elements.
215215
- **X**: `[in] float*` input array.
216216
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
217-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
217+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
218218
219219
```c
220220
double stdlib_strided_dsnannsumors( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, CBLAS_INT *n );
221221
```
222222

223223
#### stdlib_strided_dsnannsumors_ndarray( N, \*X, strideX, offsetX, \*n )
224224

225-
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics and returning an extended precision result.
225+
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
226226

227227
```c
228-
const float x[] = { 1.0f, -2.0f, 0.0/0.0, 2.0f };
228+
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
229229
CBLAS_INT n = 0;
230230

231231
double v = stdlib_strided_dsnannsumors_ndarray( 4, x, 1, 0, &n );
@@ -238,7 +238,7 @@ The function accepts the following arguments:
238238
- **X**: `[in] float*` input array.
239239
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
240240
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
241-
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
241+
- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements.
242242
243243
```c
244244
double stdlib_strided_dsnannsumors_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n );
@@ -269,7 +269,7 @@ double stdlib_strided_dsnannsumors_ndarray( const CBLAS_INT N, const float *X, c
269269

270270
int main( void ) {
271271
// Create a strided array:
272-
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0/0.0, 0.0/0.0 };
272+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f/0.0f, 0.0f/0.0f };
273273

274274
// Specify the number of elements:
275275
const int N = 5;

lib/node_modules/@stdlib/blas/ext/base/dsnannsumors/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161
{{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
6262
Computes the sum of single-precision floating-point strided array elements,
63-
ignoring `NaN` values and using ordinary recursive summation with extended
64-
accumulation and alternative indexing semantics and returning an extended
63+
ignoring `NaN` values, using ordinary recursive summation with extended
64+
accumulation and alternative indexing semantics, and returning an extended
6565
precision result.
6666

6767
While typed array views mandate a view offset based on the underlying

lib/node_modules/@stdlib/blas/ext/base/dsnannsumors/examples/c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
int main( void ) {
2424
// Create a strided array:
25-
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0/0.0, 0.0/0.0 };
25+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f/0.0f, 0.0f/0.0f };
2626

2727
// Specify the number of elements:
2828
const int N = 5;

lib/node_modules/@stdlib/blas/ext/base/dsnannsumors/include/stdlib/blas/ext/base/dsnannsumors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
double API_SUFFIX(stdlib_strided_dsnannsumors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, CBLAS_INT *n );
3535

3636
/**
37-
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics and returning an extended precision result.
37+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
3838
*/
3939
double API_SUFFIX(stdlib_strided_dsnannsumors_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n );
4040

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ function dsnannsumors( N, x, strideX, out, strideOut ) {
5151
var io;
5252

5353
ix = stride2offset( N, strideX );
54-
if ( strideOut < 0 ) {
55-
io = -strideOut;
56-
} else {
57-
io = 0;
58-
}
54+
io = stride2offset( 2, strideOut );
5955
return ndarray( N, x, strideX, ix, out, strideOut, io );
6056
}
6157

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

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

5756
sum = 0.0;
58-
io = offsetOut;
5957
if ( N <= 0 ) {
60-
out[ io ] = sum;
61-
out[ io+strideOut ] = 0;
58+
out[ offsetOut ] = sum;
59+
out[ offsetOut+strideOut ] = 0;
6260
return out;
6361
}
6462
ix = offsetX;
6563
if ( strideX === 0 ) {
6664
if ( isnan( x[ ix ] ) ) {
67-
out[ io ] = sum;
68-
out[ io+strideOut ] = 0;
65+
out[ offsetOut ] = sum;
66+
out[ offsetOut+strideOut ] = 0;
6967
return out;
7068
}
71-
out[ io ] = x[ ix ] * N;
72-
out[ io+strideOut ] = N;
69+
out[ offsetOut ] = x[ ix ] * N;
70+
out[ offsetOut+strideOut ] = N;
7371
return out;
7472
}
7573
n = 0;
@@ -80,8 +78,8 @@ function dsnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
8078
}
8179
ix += strideX;
8280
}
83-
out[ io ] = sum;
84-
out[ io+strideOut ] = n;
81+
out[ offsetOut ] = sum;
82+
out[ offsetOut+strideOut ] = n;
8583
return out;
8684
}
8785

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

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

2830
/**
@@ -41,17 +43,10 @@ static napi_value addon( napi_env env, napi_callback_info info ) {
4143
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
4244
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 3 );
4345

44-
int io;
45-
if ( strideOut < 0 ) {
46-
io = -strideOut;
47-
} else {
48-
io = 0;
49-
}
50-
51-
double *out = Out;
46+
int64_t io = stdlib_strided_stride2offset( 2, strideOut );
5247
CBLAS_INT n;
53-
out[ io ] = API_SUFFIX(stdlib_strided_dsnannsumors)( N, X, strideX, &n );
54-
out[ io + strideOut ] = (double)n;
48+
Out[ io ] = API_SUFFIX(stdlib_strided_dsnannsumors)( N, X, strideX, &n );
49+
Out[ io + strideOut ] = (double)n;
5550

5651
return NULL;
5752
}
@@ -74,11 +69,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) {
7469
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
7570
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 );
7671

77-
int io = offsetOut;
78-
double *out = Out;
7972
CBLAS_INT n;
80-
out[ io ] = API_SUFFIX(stdlib_strided_dsnannsumors_ndarray)( N, X, strideX, offsetX, &n );
81-
out[ io + strideOut ] = (double)n;
73+
Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dsnannsumors_ndarray)( N, X, strideX, offsetX, &n );
74+
Out[ offsetOut + strideOut ] = (double)n;
8275

8376
return NULL;
8477
}

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

Lines changed: 4 additions & 4 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_dsnannsumors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, CBLAS_INT *n ) {
@@ -36,19 +36,19 @@ double API_SUFFIX(stdlib_strided_dsnannsumors)( const CBLAS_INT N, const float *
3636
}
3737

3838
/**
39-
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics and returning an extended precision result.
39+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
4040
*
4141
* @param N number of indexed elements
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_dsnannsumors_ndarray)( const CBLAS_INT N, const float *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)