Skip to content

refactor: update docs and handling of zero stride of blas/ext/base/dapxsumkbn #3212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var Float64Array = require( '@stdlib/array/float64' );

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

var v = dapxsumkbn( 3, 5.0, x, 1 );
var v = dapxsumkbn( x.length, 5.0, x, 1 );
// returns 16.0
```

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

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down Expand Up @@ -90,15 +90,15 @@ var Float64Array = require( '@stdlib/array/float64' );

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

var v = dapxsumkbn.ndarray( 3, 5.0, x, 1, 0 );
var v = dapxsumkbn.ndarray( x.length, 5.0, x, 1, 0 );
// returns 16.0
```

The function has the following additional parameters:

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

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand Down Expand Up @@ -188,7 +188,7 @@ The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **alpha**: `[in] double` scalar constant.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.

```c
double stdlib_strided_dapxsumkbn( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX );
Expand All @@ -210,7 +210,7 @@ The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **alpha**: `[in] double` scalar constant.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.

```c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static double benchmark1( int iterations, int len ) {
v = 0.0;
t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
v = stdlib_strided_dapxsumkbn( len, 5.0, x, 1 );
if ( v != v ) {
printf( "should not return NaN\n" );
Expand Down Expand Up @@ -140,6 +141,7 @@ static double benchmark2( int iterations, int len ) {
v = 0.0;
t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
v = stdlib_strided_dapxsumkbn_ndarray( len, 5.0, x, 1, 0 );
if ( v != v ) {
printf( "should not return NaN\n" );
Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
Number of indexed elements.

alpha: number
Constant.
Scalar constant.

x: Float64Array
Input array.

strideX: integer
Index increment.
Stride length.

Returns
-------
Expand All @@ -38,7 +38,7 @@
> {{alias}}( x.length, 5.0, x, 1 )
16.0

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

alpha: number
Constant.
Scalar constant.

x: Float64Array
Input array.

strideX: integer
Index increment.
Stride length.

offsetX: integer
Starting index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface Routine {
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm.
*
* @param N - number of indexed elements
* @param alpha - constant
* @param alpha - scalar constant
* @param x - input array
* @param strideX - stride length
* @returns sum
Expand All @@ -45,7 +45,7 @@ interface Routine {
* 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.
*
* @param N - number of indexed elements
* @param alpha - constant
* @param alpha - scalar constant
* @param x - input array
* @param strideX - stride length
* @param offsetX - starting index
Expand All @@ -66,7 +66,7 @@ interface Routine {
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm.
*
* @param N - number of indexed elements
* @param alpha - constant
* @param alpha - scalar constant
* @param x - input array
* @param strideX - stride length
* @returns sum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var ndarray = require( './ndarray.js' );
* - 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).
*
* @param {PositiveInteger} N - number of indexed elements
* @param {number} alpha - constant
* @param {number} alpha - scalar constant
* @param {Float64Array} x - input array
* @param {integer} strideX - stride length
* @returns {number} sum
Expand All @@ -47,9 +47,8 @@ var ndarray = require( './ndarray.js' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var N = x.length;
*
* var v = dapxsumkbn( N, 5.0, x, 1 );
* var v = dapxsumkbn( x.length, 5.0, x, 1 );
* // returns 16.0
*/
function dapxsumkbn( N, alpha, x, strideX ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' );
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {number} alpha - constant
* @param {number} alpha - scalar constant
* @param {Float64Array} x - input array
* @param {integer} strideX - stride length
* @returns {number} sum
Expand All @@ -38,9 +38,8 @@ var addon = require( './../src/addon.node' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var N = x.length;
*
* var v = dapxsumkbn( N, 5.0, x, 1 );
* var v = dapxsumkbn( x.length, 5.0, x, 1 );
* // returns 16.0
*/
function dapxsumkbn( N, alpha, x, strideX ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
*
* var v = dapxsumkbn( 3, 5.0, x, 1 );
* var v = dapxsumkbn( x.length, 5.0, x, 1 );
* // returns 16.0
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
* - 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).
*
* @param {PositiveInteger} N - number of indexed elements
* @param {number} alpha - constant
* @param {number} alpha - scalar constant
* @param {Float64Array} x - input array
* @param {integer} strideX - stride length
* @param {NonNegativeInteger} offsetX - starting index
Expand All @@ -62,10 +62,10 @@ function dapxsumkbn( N, alpha, x, strideX, offsetX ) {
if ( N <= 0 ) {
return 0.0;
}
if ( N === 1 || strideX === 0 ) {
return alpha + x[ offsetX ];
}
ix = offsetX;
if ( strideX === 0 ) {
return N * ( alpha + x[ ix ] );
}
sum = 0.0;
c = 0.0;
for ( i = 0; i < N; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' );
* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using an improved Kahan–Babuška algorithm.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {number} alpha - constant
* @param {number} alpha - scalar constant
* @param {Float64Array} x - input array
* @param {integer} strideX - stride length
* @param {NonNegativeInteger} offsetX - starting index
Expand Down
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ double API_SUFFIX(stdlib_strided_dapxsumkbn)( const CBLAS_INT N, const double al
* 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.
*
* @param N number of indexed elements
* @param alpha scalar
* @param alpha scalar constant
* @param X input array
* @param strideX index increment
* @param strideX stride length
* @param offsetX starting index
*/
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 ) {
Expand All @@ -63,10 +63,10 @@ double API_SUFFIX(stdlib_strided_dapxsumkbn_ndarray)( const CBLAS_INT N, const d
if ( N <= 0 ) {
return 0.0;
}
if ( N == 1 || strideX == 0 ) {
return alpha + X[ offsetX ];
}
ix = offsetX;
if ( strideX == 0 ) {
return N * ( alpha + X[ ix ] );
}
sum = 0.0;
c = 0.0;
for ( i = 0; i < N; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});

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

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

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

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant', opts, function test( t ) {
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 ) {
var x;
var v;

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

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

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});

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

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

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

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element plus a constant', opts, function test( t ) {
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 ) {
var x;
var v;

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

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

t.end();
});
Expand Down
Loading