Skip to content

Commit 16d48af

Browse files
authored
refactor: update stride handling and function documentation for blas/ext/base/dapxsumkbn2
PR-URL: #3227 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 9c913e5 commit 16d48af

File tree

14 files changed

+41
-40
lines changed

14 files changed

+41
-40
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ var Float64Array = require( '@stdlib/array/float64' );
4545

4646
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
4747

48-
var v = dapxsumkbn2( 3, 5.0, x, 1 );
48+
var v = dapxsumkbn2( x.length, 5.0, x, 1 );
4949
// returns 16.0
5050
```
5151

5252
The function has the following parameters:
5353

5454
- **N**: number of indexed elements.
55+
- **alpha**: scalar constant.
5556
- **x**: input [`Float64Array`][@stdlib/array/float64].
56-
- **strideX**: index increment for `x`.
57+
- **strideX**: stride length for `x`.
5758

58-
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`,
59+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element:
5960

6061
```javascript
6162
var Float64Array = require( '@stdlib/array/float64' );
@@ -89,15 +90,15 @@ var Float64Array = require( '@stdlib/array/float64' );
8990

9091
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
9192

92-
var v = dapxsumkbn2.ndarray( 3, 5.0, x, 1, 0 );
93+
var v = dapxsumkbn2.ndarray( x.length, 5.0, x, 1, 0 );
9394
// returns 16.0
9495
```
9596

9697
The function has the following additional parameters:
9798

9899
- **offsetX**: starting index for `x`.
99100

100-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value
101+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access every other element starting from the second element:
101102

102103
```javascript
103104
var Float64Array = require( '@stdlib/array/float64' );
@@ -187,7 +188,7 @@ The function accepts the following arguments:
187188
- **N**: `[in] CBLAS_INT` number of indexed elements.
188189
- **alpha**: `[in] double` scalar constant.
189190
- **X**: `[in] double*` input array.
190-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
191+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
191192
192193
```c
193194
double stdlib_strided_dapxsumkbn2( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX );
@@ -209,7 +210,7 @@ The function accepts the following arguments:
209210
- **N**: `[in] CBLAS_INT` number of indexed elements.
210211
- **alpha**: `[in] double` scalar constant.
211212
- **X**: `[in] double*` input array.
212-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
213+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
213214
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
214215
215216
```c

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static double benchmark1( int iterations, int len ) {
107107
v = 0.0;
108108
t = tic();
109109
for ( i = 0; i < iterations; i++ ) {
110+
// cppcheck-suppress uninitvar
110111
v = stdlib_strided_dapxsumkbn2( len, 5.0, x, 1 );
111112
if ( v != v ) {
112113
printf( "should not return NaN\n" );
@@ -140,6 +141,7 @@ static double benchmark2( int iterations, int len ) {
140141
v = 0.0;
141142
t = tic();
142143
for ( i = 0; i < iterations; i++ ) {
144+
// cppcheck-suppress uninitvar
143145
v = stdlib_strided_dapxsumkbn2_ndarray( len, 5.0, x, 1, 0 );
144146
if ( v != v ) {
145147
printf( "should not return NaN\n" );

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
Number of indexed elements.
1919

2020
alpha: number
21-
Constant.
21+
Scalar constant.
2222

2323
x: Float64Array
2424
Input array.
2525

2626
strideX: integer
27-
Index increment.
27+
Stride length.
2828

2929
Returns
3030
-------
@@ -38,7 +38,7 @@
3838
> {{alias}}( x.length, 5.0, x, 1 )
3939
16.0
4040

41-
// Using `N` and `stride` parameters:
41+
// Using `N` and stride parameters:
4242
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
4343
> {{alias}}( 3, 5.0, x, 2 )
4444
16.0
@@ -65,13 +65,13 @@
6565
Number of indexed elements.
6666

6767
alpha: number
68-
Constant.
68+
Scalar constant.
6969

7070
x: Float64Array
7171
Input array.
7272

7373
strideX: integer
74-
Index increment.
74+
Stride length.
7575

7676
offsetX: integer
7777
Starting index.

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface Routine {
2626
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm.
2727
*
2828
* @param N - number of indexed elements
29-
* @param alpha - constant
29+
* @param alpha - scalar constant
3030
* @param x - input array
3131
* @param strideX - stride length
3232
* @returns sum
@@ -45,7 +45,7 @@ interface Routine {
4545
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
4646
*
4747
* @param N - number of indexed elements
48-
* @param alpha - constant
48+
* @param alpha - scalar constant
4949
* @param x - input array
5050
* @param strideX - stride length
5151
* @param offsetX - starting index
@@ -66,7 +66,7 @@ interface Routine {
6666
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm.
6767
*
6868
* @param N - number of indexed elements
69-
* @param alpha - constant
69+
* @param alpha - scalar constant
7070
* @param x - input array
7171
* @param strideX - stride length
7272
* @returns sum

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var ndarray = require( './ndarray.js' );
3838
* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x).
3939
*
4040
* @param {PositiveInteger} N - number of indexed elements
41-
* @param {number} alpha - constant
41+
* @param {number} alpha - scalar constant
4242
* @param {Float64Array} x - input array
4343
* @param {integer} strideX - stride length
4444
* @returns {number} sum
@@ -47,9 +47,8 @@ var ndarray = require( './ndarray.js' );
4747
* var Float64Array = require( '@stdlib/array/float64' );
4848
*
4949
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
50-
* var N = x.length;
5150
*
52-
* var v = dapxsumkbn2( N, 5.0, x, 1 );
51+
* var v = dapxsumkbn2( x.length, 5.0, x, 1 );
5352
* // returns 16.0
5453
*/
5554
function dapxsumkbn2( N, alpha, x, strideX ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.native.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' );
2929
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm.
3030
*
3131
* @param {PositiveInteger} N - number of indexed elements
32-
* @param {number} alpha - constant
32+
* @param {number} alpha - scalar constant
3333
* @param {Float64Array} x - input array
3434
* @param {integer} strideX - stride length
3535
* @returns {number} sum
@@ -38,9 +38,8 @@ var addon = require( './../src/addon.node' );
3838
* var Float64Array = require( '@stdlib/array/float64' );
3939
*
4040
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
41-
* var N = x.length;
4241
*
43-
* var v = dapxsumkbn2( N, 5.0, x, 1 );
42+
* var v = dapxsumkbn2( x.length, 5.0, x, 1 );
4443
* // returns 16.0
4544
*/
4645
function dapxsumkbn2( N, alpha, x, strideX ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
3131
*
32-
* var v = dapxsumkbn2( 3, 5.0, x, 1 );
32+
* var v = dapxsumkbn2( x.length, 5.0, x, 1 );
3333
* // returns 16.0
3434
*
3535
* @example

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
3737
* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x).
3838
*
3939
* @param {PositiveInteger} N - number of indexed elements
40-
* @param {number} alpha - constant
40+
* @param {number} alpha - scalar constant
4141
* @param {Float64Array} x - input array
4242
* @param {integer} strideX - stride length
4343
* @param {NonNegativeInteger} offsetX - starting index
@@ -65,10 +65,10 @@ function dapxsumkbn2( N, alpha, x, strideX, offsetX ) {
6565
if ( N <= 0 ) {
6666
return 0.0;
6767
}
68-
if ( N === 1 || strideX === 0 ) {
69-
return alpha + x[ 0 ];
70-
}
7168
ix = offsetX;
69+
if ( strideX === 0 ) {
70+
return N * ( alpha + x[ ix ] );
71+
}
7272
sum = 0.0;
7373
ccs = 0.0; // second order correction term for lost low order bits
7474
cs = 0.0; // first order correction term for lost low order bits

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' );
2929
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm.
3030
*
3131
* @param {PositiveInteger} N - number of indexed elements
32-
* @param {number} alpha - constant
32+
* @param {number} alpha - scalar constant
3333
* @param {Float64Array} x - input array
3434
* @param {integer} strideX - stride length
3535
* @param {NonNegativeInteger} offsetX - starting index

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ double API_SUFFIX(stdlib_strided_dapxsumkbn2)( const CBLAS_INT N, const double a
6262
* @return output value
6363
*/
6464
double stdlib_strided_dapxsumkbn2_ndarray( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
65-
double sum;
66-
double ccs;
6765
CBLAS_INT ix;
6866
CBLAS_INT i;
67+
double sum;
68+
double ccs;
6969
double cs;
7070
double cc;
7171
double v;
@@ -75,10 +75,10 @@ double stdlib_strided_dapxsumkbn2_ndarray( const CBLAS_INT N, const double alpha
7575
if ( N <= 0 ) {
7676
return 0.0;
7777
}
78-
if ( N == 1 || strideX == 0 ) {
79-
return alpha + X[ 0 ];
80-
}
8178
ix = offsetX;
79+
if ( strideX == 0 ) {
80+
return N * ( alpha + X[ ix ] );
81+
}
8282
sum = 0.0;
8383
ccs = 0.0; // second order correction term for lost low order bits
8484
cs = 0.0; // first order correction term for lost low order bits

0 commit comments

Comments
 (0)