Skip to content

Commit ff80d7d

Browse files
authored
refactor: update stride handling and function documentation for blas/ext/base/dasumpw
PR-URL: #3362 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 6783f51 commit ff80d7d

File tree

11 files changed

+34
-39
lines changed

11 files changed

+34
-39
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,18 @@ Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision fl
5959
var Float64Array = require( '@stdlib/array/float64' );
6060

6161
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
62-
var N = x.length;
6362

64-
var v = dasumpw( N, x, 1 );
63+
var v = dasumpw( x.length, x, 1 );
6564
// returns 5.0
6665
```
6766

6867
The function has the following parameters:
6968

7069
- **N**: number of indexed elements.
7170
- **x**: input [`Float64Array`][@stdlib/array/float64].
72-
- **strideX**: index increment for `x`.
71+
- **strideX**: stride length for `x`.
7372

74-
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values of every other element in `x`,
73+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values of every other element:
7574

7675
```javascript
7776
var Float64Array = require( '@stdlib/array/float64' );
@@ -104,17 +103,16 @@ Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision fl
104103
var Float64Array = require( '@stdlib/array/float64' );
105104

106105
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
107-
var N = x.length;
108106

109-
var v = dasumpw.ndarray( N, x, 1, 0 );
107+
var v = dasumpw.ndarray( x.length, x, 1, 0 );
110108
// returns 5.0
111109
```
112110

113111
The function has the following additional parameters:
114112

115113
- **offsetX**: starting index for `x`.
116114

117-
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 calculate the sum of absolute values of every other value in `x` starting from the second value
115+
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 calculate the sum of absolute values of every other element starting from the second element:
118116

119117
```javascript
120118
var Float64Array = require( '@stdlib/array/float64' );
@@ -204,7 +202,7 @@ The function accepts the following arguments:
204202
205203
- **N**: `[in] CBLAS_INT` number of indexed elements.
206204
- **X**: `[in] double*` input array.
207-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
205+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
208206
209207
```c
210208
double stdlib_strided_dasumpw( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
@@ -225,7 +223,7 @@ The function accepts the following arguments:
225223
226224
- **N**: `[in] CBLAS_INT` number of indexed elements.
227225
- **X**: `[in] double*` input array.
228-
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
226+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
229227
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
230228
231229
```c

lib/node_modules/@stdlib/blas/ext/base/dasumpw/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_dasumpw( len, 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_dasumpw_ndarray( len, x, 1, 0 );
144146
if ( v != v ) {
145147
printf( "should not return NaN\n" );

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Input array.
2121

2222
strideX: integer
23-
Index increment.
23+
Stride length.
2424

2525
Returns
2626
-------
@@ -34,19 +34,17 @@
3434
> {{alias}}( x.length, x, 1 )
3535
5.0
3636

37-
// Using `N` and `stride` parameters:
37+
// Using `N` and stride parameters:
3838
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
39-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
4039
> var stride = 2;
41-
> {{alias}}( N, x, stride )
40+
> {{alias}}( 3, x, stride )
4241
5.0
4342

4443
// Using view offsets:
4544
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
4645
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
47-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
4846
> stride = 2;
49-
> {{alias}}( N, x1, stride )
47+
> {{alias}}( 3, x1, stride )
5048
5.0
5149

5250

@@ -68,7 +66,7 @@
6866
Input array.
6967

7068
strideX: integer
71-
Index increment.
69+
Stride length.
7270

7371
offsetX: integer
7472
Starting index.
@@ -87,8 +85,7 @@
8785

8886
// Using offset parameter:
8987
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
90-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
91-
> {{alias}}.ndarray( N, x, 2, 1 )
88+
> {{alias}}.ndarray( 3, x, 2, 1 )
9289
5.0
9390

9491
See Also

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ var ndarray = require( './ndarray.js' );
4646
* var Float64Array = require( '@stdlib/array/float64' );
4747
*
4848
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
49-
* var N = x.length;
5049
*
51-
* var v = dasumpw( N, x, 1 );
50+
* var v = dasumpw( x.length, x, 1 );
5251
* // returns 5.0
5352
*/
5453
function dasumpw( N, x, strideX ) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
* var dasumpw = require( '@stdlib/blas/ext/base/dasumpw' );
2929
*
3030
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
31-
* var N = x.length;
3231
*
33-
* var v = dasumpw( N, x, 1 );
32+
* var v = dasumpw( x.length, x, 1 );
3433
* // returns 5.0
3534
*
3635
* @example

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ function dasumpw( N, x, strideX, offsetX ) {
7575
if ( N <= 0 ) {
7676
return 0.0;
7777
}
78-
if ( N === 1 || strideX === 0 ) {
79-
return abs( x[ offsetX ] );
80-
}
8178
ix = offsetX;
79+
if ( strideX === 0 ) {
80+
return N * abs( x[ ix ] );
81+
}
8282
if ( N < 8 ) {
8383
// Use simple summation...
8484
s = 0.0;
@@ -113,7 +113,7 @@ function dasumpw( N, x, strideX, offsetX ) {
113113
ix += 8 * strideX;
114114
}
115115
// Pairwise sum the accumulators:
116-
s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7));
116+
s = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) );
117117

118118
// Clean-up loop...
119119
for ( i; i < N; i++ ) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ double API_SUFFIX(stdlib_strided_dasumpw)( const CBLAS_INT N, const double *X, c
5555
*
5656
* @param N number of indexed elements
5757
* @param X input array
58-
* @param strideX index increment
58+
* @param strideX stride length
5959
* @param offsetX starting index
6060
* @return output value
6161
*/
6262
double API_SUFFIX(stdlib_strided_dasumpw_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
63-
double sum;
6463
CBLAS_INT ix;
6564
CBLAS_INT M;
6665
CBLAS_INT n;
6766
CBLAS_INT i;
67+
double sum;
6868
double s0;
6969
double s1;
7070
double s2;
@@ -77,10 +77,10 @@ double API_SUFFIX(stdlib_strided_dasumpw_ndarray)( const CBLAS_INT N, const doub
7777
if ( N <= 0 ) {
7878
return 0.0;
7979
}
80-
if ( N == 1 || strideX == 0 ) {
81-
return stdlib_base_abs( X[ 0 ] );
82-
}
8380
ix = offsetX;
81+
if ( strideX == 0 ) {
82+
return N * stdlib_base_abs( X[ ix ] );
83+
}
8484
if ( N < 8 ) {
8585
// Use simple summation...
8686
sum = 0.0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
156156
t.end();
157157
});
158158

159-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) {
159+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of first element repeated N times', function test( t ) {
160160
var x;
161161
var v;
162162

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

165165
v = dasumpw( x.length, x, 0 );
166-
t.strictEqual( v, 1.0, 'returns expected value' );
166+
t.strictEqual( v, 5.0, 'returns expected value' );
167167

168168
t.end();
169169
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
247247
t.end();
248248
});
249249

250-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', opts, function test( t ) {
250+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of first element repeated N times', opts, function test( t ) {
251251
var x;
252252
var v;
253253

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

256256
v = dasumpw( x.length, x, 0 );
257-
t.strictEqual( v, 1.0, 'returns expected value' );
257+
t.strictEqual( v, 5.0, 'returns expected value' );
258258

259259
t.end();
260260
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
156156
t.end();
157157
});
158158

159-
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) {
159+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of first element repeated N times', function test( t ) {
160160
var x;
161161
var v;
162162

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

165165
v = dasumpw( x.length, x, 0, 0 );
166-
t.strictEqual( v, 1.0, 'returns expected value' );
166+
t.strictEqual( v, 5.0, 'returns expected value' );
167167

168168
t.end();
169169
});

0 commit comments

Comments
 (0)