Skip to content

Commit 5364192

Browse files
authored
refactor: update stride handling and function documentation for blas/ext/base/dapxsumpw
PR-URL: #3248 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent a8a5679 commit 5364192

File tree

14 files changed

+40
-42
lines changed

14 files changed

+40
-42
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,18 @@ Adds a scalar constant to each double-precision floating-point strided array ele
4444
var Float64Array = require( '@stdlib/array/float64' );
4545

4646
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
47-
var N = x.length;
4847

49-
var v = dapxsumpw( N, 5.0, x, 1 );
48+
var v = dapxsumpw( x.length, 5.0, x, 1 );
5049
// returns 16.0
5150
```
5251

5352
The function has the following parameters:
5453

5554
- **N**: number of indexed elements.
5655
- **x**: input [`Float64Array`][@stdlib/array/float64].
57-
- **strideX**: index increment for `x`.
56+
- **strideX**: stride length for `x`.
5857

59-
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`,
58+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element:
6059

6160
```javascript
6261
var Float64Array = require( '@stdlib/array/float64' );
@@ -89,17 +88,16 @@ Adds a scalar constant to each double-precision floating-point strided array ele
8988
var Float64Array = require( '@stdlib/array/float64' );
9089

9190
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
92-
var N = x.length;
9391

94-
var v = dapxsumpw.ndarray( N, 5.0, x, 1, 0 );
92+
var v = dapxsumpw.ndarray( x.length, 5.0, x, 1, 0 );
9593
// returns 16.0
9694
```
9795

9896
The function has the following additional parameters:
9997

10098
- **offsetX**: starting index for `x`.
10199

102-
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
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 element starting from the second element:
103101

104102
```javascript
105103
var Float64Array = require( '@stdlib/array/float64' );
@@ -189,7 +187,7 @@ The function accepts the following arguments:
189187
- **N**: `[in] CBLAS_INT` number of indexed elements.
190188
- **alpha**: `[in] double` scalar constant.
191189
- **X**: `[in] double*` input array.
192-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
190+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
193191
194192
```c
195193
double stdlib_strided_dapxsumpw( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX );
@@ -211,7 +209,7 @@ The function accepts the following arguments:
211209
- **N**: `[in] CBLAS_INT` number of indexed elements.
212210
- **alpha**: `[in] double` scalar constant.
213211
- **X**: `[in] double*` input array.
214-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
212+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
215213
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
216214
217215
```c

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/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_dapxsumpw( 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_dapxsumpw_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/dapxsumpw/docs/repl.txt

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

1919
alpha: number
20-
Constant.
20+
Scalar constant.
2121

2222
x: Float64Array
2323
Input array.
2424

2525
strideX: integer
26-
Index increment.
26+
Stride length.
2727

2828
Returns
2929
-------
@@ -37,7 +37,7 @@
3737
> {{alias}}( x.length, 5.0, x, 1 )
3838
16.0
3939

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

6666
alpha: number
67-
Constant.
67+
Scalar constant.
6868

6969
x: Float64Array
7070
Input array.
7171

7272
strideX: integer
73-
Index increment.
73+
Stride length.
7474

7575
offsetX: integer
7676
Starting index.

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/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 pairwise summation.
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 pairwise summation 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 pairwise summation.
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/dapxsumpw/lib/dapxsumpw.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
* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).
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 = dapxsumpw( N, 5.0, x, 1 );
51+
* var v = dapxsumpw( x.length, 5.0, x, 1 );
5352
* // returns 16.0
5453
*/
5554
function dapxsumpw( N, alpha, x, strideX ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.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 pairwise summation.
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 = dapxsumpw( N, 5.0, x, 1 );
42+
* var v = dapxsumpw( x.length, 5.0, x, 1 );
4443
* // returns 16.0
4544
*/
4645
function dapxsumpw( N, alpha, x, strideX ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/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 = dapxsumpw( 3, 5.0, x, 1 );
32+
* var v = dapxsumpw( x.length, 5.0, x, 1 );
3333
* // returns 16.0
3434
*
3535
* @example

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var BLOCKSIZE = 128;
4343
* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).
4444
*
4545
* @param {PositiveInteger} N - number of indexed elements
46-
* @param {number} alpha - constant
46+
* @param {number} alpha - scalar constant
4747
* @param {Float64Array} x - input array
4848
* @param {integer} strideX - stride length
4949
* @param {NonNegativeInteger} offsetX - starting index
@@ -75,10 +75,10 @@ function dapxsumpw( N, alpha, x, strideX, offsetX ) {
7575
if ( N <= 0 ) {
7676
return 0.0;
7777
}
78-
if ( N === 1 || strideX === 0 ) {
79-
return alpha + x[ offsetX ];
80-
}
8178
ix = offsetX;
79+
if ( strideX === 0 ) {
80+
return N * ( alpha + x[ ix ] );
81+
}
8282
if ( N < 8 ) {
8383
// Use simple summation...
8484
s = 0.0;

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/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 pairwise summation.
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/dapxsumpw/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ double API_SUFFIX(stdlib_strided_dapxsumpw)( const CBLAS_INT N, const double alp
5656
* @param N number of indexed elements
5757
* @param alpha scalar constant
5858
* @param X input array
59-
* @param strideX index increment
59+
* @param strideX stride length
6060
* @param offsetX starting index
6161
* @return output value
6262
*
6363
*/
6464
double API_SUFFIX(stdlib_strided_dapxsumpw_ndarray)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
65-
double sum;
6665
CBLAS_INT ix;
6766
CBLAS_INT M;
6867
CBLAS_INT n;
6968
CBLAS_INT i;
69+
double sum;
7070
double s0;
7171
double s1;
7272
double s2;
@@ -79,10 +79,10 @@ double API_SUFFIX(stdlib_strided_dapxsumpw_ndarray)( const CBLAS_INT N, const do
7979
if ( N <= 0 ) {
8080
return 0.0;
8181
}
82-
if ( N == 1 || strideX == 0 ) {
83-
return alpha + X[ offsetX ];
84-
}
8582
ix = offsetX;
83+
if ( strideX == 0 ) {
84+
return N * ( alpha + X[ ix ] );
85+
}
8686
if ( N < 8 ) {
8787
// Use simple summation...
8888
sum = 0.0;

0 commit comments

Comments
 (0)