Skip to content

Commit 1b5ac87

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

File tree

14 files changed

+40
-42
lines changed

14 files changed

+40
-42
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ 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 = dapxsumors( N, 5.0, x, 1 );
48+
var v = dapxsumors( x.length, 5.0, x, 1 );
5049
// returns 16.0
5150
```
5251

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

60-
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:
6160

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

9291
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
93-
var N = x.length;
9492

95-
var v = dapxsumors.ndarray( N, 5.0, x, 1, 0 );
93+
var v = dapxsumors.ndarray( x.length, 5.0, x, 1, 0 );
9694
// returns 16.0
9795
```
9896

9997
The function has the following additional parameters:
10098

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

103-
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:
104102

105103
```javascript
106104
var Float64Array = require( '@stdlib/array/float64' );
@@ -191,7 +189,7 @@ The function accepts the following arguments:
191189
- **N**: `[in] CBLAS_INT` number of indexed elements.
192190
- **alpha**: `[in] double` scalar constant.
193191
- **X**: `[in] double*` input array.
194-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
192+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
195193
196194
```c
197195
double stdlib_strided_dapxsumors( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX );
@@ -213,7 +211,7 @@ The function accepts the following arguments:
213211
- **N**: `[in] CBLAS_INT` number of indexed elements.
214212
- **alpha**: `[in] double` scalar constant.
215213
- **X**: `[in] double*` input array.
216-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
214+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
217215
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
218216
219217
```c

lib/node_modules/@stdlib/blas/ext/base/dapxsumors/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_dapxsumors( 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_dapxsumors_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/dapxsumors/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/dapxsumors/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 ordinary recursive 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 ordinary recursive 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 ordinary recursive 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/dapxsumors/lib/dapxsumors.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var ndarray = require( './ndarray.js' );
3030
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using ordinary recursive summation.
3131
*
3232
* @param {PositiveInteger} N - number of indexed elements
33-
* @param {number} alpha - constant
33+
* @param {number} alpha - scalar constant
3434
* @param {Float64Array} x - input array
3535
* @param {integer} strideX - stride length
3636
* @returns {number} sum
@@ -39,9 +39,8 @@ var ndarray = require( './ndarray.js' );
3939
* var Float64Array = require( '@stdlib/array/float64' );
4040
*
4141
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
42-
* var N = x.length;
4342
*
44-
* var v = dapxsumors( N, 5.0, x, 1 );
43+
* var v = dapxsumors( x.length, 5.0, x, 1 );
4544
* // returns 16.0
4645
*/
4746
function dapxsumors( N, alpha, x, strideX ) {

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using ordinary recursive summation.
2525
*
2626
* @param {PositiveInteger} N - number of indexed elements
27-
* @param {number} alpha - constant
27+
* @param {number} alpha - scalar constant
2828
* @param {Float64Array} x - input array
2929
* @param {integer} strideX - stride length
3030
* @param {NonNegativeInteger} offsetX - starting index
@@ -46,10 +46,10 @@ function dapxsumors( N, alpha, x, strideX, offsetX ) {
4646
if ( N <= 0 ) {
4747
return 0.0;
4848
}
49-
if ( N === 1 || strideX === 0 ) {
50-
return alpha + x[ 0 ];
51-
}
5249
ix = offsetX;
50+
if ( strideX === 0 ) {
51+
return N * ( alpha + x[ ix ] );
52+
}
5353
sum = 0.0;
5454
for ( i = 0; i < N; i++ ) {
5555
sum += alpha + x[ ix ];

lib/node_modules/@stdlib/blas/ext/base/dapxsumors/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 ordinary recursive 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/dapxsumors/src/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ double API_SUFFIX(stdlib_strided_dapxsumors)( const CBLAS_INT N, const double al
4040
* @param N number of indexed elements
4141
* @param alpha scalar constant
4242
* @param X input array
43-
* @param strideX index increment
43+
* @param strideX stride length
4444
* @param offsetX starting index
4545
*/
4646
double API_SUFFIX(stdlib_strided_dapxsumors_ndarray)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
47-
double sum;
4847
CBLAS_INT ix;
4948
CBLAS_INT i;
49+
double sum;
5050

5151
if ( N <= 0 ) {
5252
return 0.0;
5353
}
54-
if ( N == 1 || strideX == 0 ) {
55-
return alpha + X[ 0 ];
56-
}
5754
ix = offsetX;
55+
if ( strideX == 0 ) {
56+
return N * ( alpha + X[ ix ] );
57+
}
5858
sum = 0.0;
5959
for ( i = 0; i < N; i++ ) {
6060
sum += alpha + X[ ix ];

0 commit comments

Comments
 (0)