Skip to content

Commit f4009fd

Browse files
authored
refactor: update docs and handling of zero stride in blas/ext/base/dapxsumkbn
PR-URL: #3212 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 14021a5 commit f4009fd

File tree

14 files changed

+40
-40
lines changed

14 files changed

+40
-40
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var Float64Array = require( '@stdlib/array/float64' );
4545

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

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

@@ -54,9 +54,9 @@ The function has the following parameters:
5454
- **N**: number of indexed elements.
5555
- **alpha**: scalar constant.
5656
- **x**: input [`Float64Array`][@stdlib/array/float64].
57-
- **strideX**: index increment for `x`.
57+
- **strideX**: stride length for `x`.
5858

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

6161
```javascript
6262
var Float64Array = require( '@stdlib/array/float64' );
@@ -90,15 +90,15 @@ var Float64Array = require( '@stdlib/array/float64' );
9090

9191
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
9292

93-
var v = dapxsumkbn.ndarray( 3, 5.0, x, 1, 0 );
93+
var v = dapxsumkbn.ndarray( x.length, 5.0, x, 1, 0 );
9494
// returns 16.0
9595
```
9696

9797
The function has the following additional parameters:
9898

9999
- **offsetX**: starting index for `x`.
100100

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 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:
102102

103103
```javascript
104104
var Float64Array = require( '@stdlib/array/float64' );
@@ -188,7 +188,7 @@ The function accepts the following arguments:
188188
- **N**: `[in] CBLAS_INT` number of indexed elements.
189189
- **alpha**: `[in] double` scalar constant.
190190
- **X**: `[in] double*` input array.
191-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
191+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
192192
193193
```c
194194
double stdlib_strided_dapxsumkbn( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX );
@@ -210,7 +210,7 @@ The function accepts the following arguments:
210210
- **N**: `[in] CBLAS_INT` number of indexed elements.
211211
- **alpha**: `[in] double` scalar constant.
212212
- **X**: `[in] double*` input array.
213-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
213+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
214214
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
215215
216216
```c

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

+2
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_dapxsumkbn( 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_dapxsumkbn_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/dapxsumkbn/docs/repl.txt

+5-5
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/dapxsumkbn/docs/types/index.d.ts

+3-3
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 an improved 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 an improved 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 an improved 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/dapxsumkbn/lib/dapxsumkbn.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var ndarray = require( './ndarray.js' );
3838
* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
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 = dapxsumkbn( N, 5.0, x, 1 );
51+
* var v = dapxsumkbn( x.length, 5.0, x, 1 );
5352
* // returns 16.0
5453
*/
5554
function dapxsumkbn( N, alpha, x, strideX ) {

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

+2-3
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 an improved 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 = dapxsumkbn( N, 5.0, x, 1 );
42+
* var v = dapxsumkbn( x.length, 5.0, x, 1 );
4443
* // returns 16.0
4544
*/
4645
function dapxsumkbn( N, alpha, x, strideX ) {

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

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
3737
* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
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
@@ -62,10 +62,10 @@ function dapxsumkbn( N, alpha, x, strideX, offsetX ) {
6262
if ( N <= 0 ) {
6363
return 0.0;
6464
}
65-
if ( N === 1 || strideX === 0 ) {
66-
return alpha + x[ offsetX ];
67-
}
6865
ix = offsetX;
66+
if ( strideX === 0 ) {
67+
return N * ( alpha + x[ ix ] );
68+
}
6969
sum = 0.0;
7070
c = 0.0;
7171
for ( i = 0; i < N; i++ ) {

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

+1-1
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 an improved 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/dapxsumkbn/src/main.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ double API_SUFFIX(stdlib_strided_dapxsumkbn)( const CBLAS_INT N, const double al
4747
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm and alternative indexing semantics.
4848
*
4949
* @param N number of indexed elements
50-
* @param alpha scalar
50+
* @param alpha scalar constant
5151
* @param X input array
52-
* @param strideX index increment
52+
* @param strideX stride length
5353
* @param offsetX starting index
5454
*/
5555
double API_SUFFIX(stdlib_strided_dapxsumkbn_ndarray)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
@@ -63,10 +63,10 @@ double API_SUFFIX(stdlib_strided_dapxsumkbn_ndarray)( const CBLAS_INT N, const d
6363
if ( N <= 0 ) {
6464
return 0.0;
6565
}
66-
if ( N == 1 || strideX == 0 ) {
67-
return alpha + X[ offsetX ];
68-
}
6966
ix = offsetX;
67+
if ( strideX == 0 ) {
68+
return N * ( alpha + X[ ix ] );
69+
}
7070
sum = 0.0;
7171
c = 0.0;
7272
for ( i = 0; i < N; i++ ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
135135
t.end();
136136
});
137137

138-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant', function test( t ) {
138+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', function test( t ) {
139139
var x;
140140
var v;
141141

142142
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
143143

144144
v = dapxsumkbn( x.length, 5.0, x, 0 );
145-
t.strictEqual( v, 6.0, 'returns expected value' );
145+
t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' );
146146

147147
t.end();
148148
});

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.dapxsumkbn.native.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
253253
t.end();
254254
});
255255

256-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant', opts, function test( t ) {
256+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', opts, function test( t ) {
257257
var x;
258258
var v;
259259

260260
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
261261

262262
v = dapxsumkbn( x.length, 5.0, x, 0 );
263-
t.strictEqual( v, 6.0, 'returns expected value' );
263+
t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' );
264264

265265
t.end();
266266
});

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/test/test.ndarray.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
135135
t.end();
136136
});
137137

138-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element plus a constant', function test( t ) {
138+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', function test( t ) {
139139
var x;
140140
var v;
141141

142142
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
143143

144144
v = dapxsumkbn( x.length, 5.0, x, 0, 0 );
145-
t.strictEqual( v, 6.0, 'returns expected value' );
145+
t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' );
146146

147147
t.end();
148148
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
144144
t.end();
145145
});
146146

147-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element plus a constant', opts, function test( t ) {
147+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', opts, function test( t ) {
148148
var x;
149149
var v;
150150

151151
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
152152

153153
v = dapxsumkbn( x.length, 5.0, x, 0, 0 );
154-
t.strictEqual( v, 6.0, 'returns expected value' );
154+
t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' );
155155

156156
t.end();
157157
});

0 commit comments

Comments
 (0)