From c2e7a9951ffd873edad1aba5f1283fa54fc3f8fd Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 24 Nov 2024 07:08:23 +0000 Subject: [PATCH] refactor: update stride handling and function documentation --- .../@stdlib/blas/ext/base/dapxsumpw/README.md | 16 +++++++--------- .../dapxsumpw/benchmark/c/benchmark.length.c | 2 ++ .../blas/ext/base/dapxsumpw/docs/repl.txt | 10 +++++----- .../ext/base/dapxsumpw/docs/types/index.d.ts | 6 +++--- .../blas/ext/base/dapxsumpw/lib/dapxsumpw.js | 5 ++--- .../ext/base/dapxsumpw/lib/dapxsumpw.native.js | 5 ++--- .../@stdlib/blas/ext/base/dapxsumpw/lib/index.js | 2 +- .../blas/ext/base/dapxsumpw/lib/ndarray.js | 8 ++++---- .../ext/base/dapxsumpw/lib/ndarray.native.js | 2 +- .../@stdlib/blas/ext/base/dapxsumpw/src/main.c | 10 +++++----- .../ext/base/dapxsumpw/test/test.dapxsumpw.js | 4 ++-- .../base/dapxsumpw/test/test.dapxsumpw.native.js | 4 ++-- .../blas/ext/base/dapxsumpw/test/test.ndarray.js | 4 ++-- .../base/dapxsumpw/test/test.ndarray.native.js | 4 ++-- 14 files changed, 40 insertions(+), 42 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/README.md index 5afec4d99f15..f59c2893983b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/README.md @@ -44,9 +44,8 @@ Adds a scalar constant to each double-precision floating-point strided array ele var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dapxsumpw( N, 5.0, x, 1 ); +var v = dapxsumpw( x.length, 5.0, x, 1 ); // returns 16.0 ``` @@ -54,9 +53,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **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 array are accessed at runtime. For example, to access every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -89,9 +88,8 @@ Adds a scalar constant to each double-precision floating-point strided array ele var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dapxsumpw.ndarray( N, 5.0, x, 1, 0 ); +var v = dapxsumpw.ndarray( x.length, 5.0, x, 1, 0 ); // returns 16.0 ``` @@ -99,7 +97,7 @@ 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' ); @@ -189,7 +187,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_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: - **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 diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/benchmark/c/benchmark.length.c index 93770cad183e..123c9ee70eda 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/benchmark/c/benchmark.length.c @@ -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_dapxsumpw( len, 5.0, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -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_dapxsumpw_ndarray( len, 5.0, x, 1, 0 ); if ( v != v ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/repl.txt index 34a5cc6a2af0..5797c3eac413 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/repl.txt @@ -17,13 +17,13 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Float64Array Input array. strideX: integer - Index increment. + Stride length. Returns ------- @@ -37,7 +37,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 @@ -64,13 +64,13 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Float64Array Input array. strideX: integer - Index increment. + Stride length. offsetX: integer Starting index. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/types/index.d.ts index 08db690f0d46..ec9d89f16e63 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/docs/types/index.d.ts @@ -26,7 +26,7 @@ interface Routine { * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using pairwise summation. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar constant * @param x - input array * @param strideX - stride length * @returns sum @@ -45,7 +45,7 @@ interface Routine { * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using pairwise summation 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 @@ -66,7 +66,7 @@ interface Routine { * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using pairwise summation. * * @param N - number of indexed elements -* @param alpha - constant +* @param alpha - scalar constant * @param x - input array * @param strideX - stride length * @returns sum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.js index a68624f37ebd..cf9044d9cd66 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.js @@ -38,7 +38,7 @@ var ndarray = require( './ndarray.js' ); * - 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). * * @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 @@ -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 = dapxsumpw( N, 5.0, x, 1 ); +* var v = dapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ function dapxsumpw( N, alpha, x, strideX ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.native.js index f0b23ea7bdb2..bde592a51a5b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/dapxsumpw.native.js @@ -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 pairwise summation. * * @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 @@ -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 = dapxsumpw( N, 5.0, x, 1 ); +* var v = dapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ function dapxsumpw( N, alpha, x, strideX ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/index.js index 2416dd2000f8..d77fec499540 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/index.js @@ -29,7 +29,7 @@ * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * -* var v = dapxsumpw( 3, 5.0, x, 1 ); +* var v = dapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.js index 730021624b51..f73faa635a9a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.js @@ -43,7 +43,7 @@ var BLOCKSIZE = 128; * - 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). * * @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 @@ -75,10 +75,10 @@ function dapxsumpw( 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 ] ); + } if ( N < 8 ) { // Use simple summation... s = 0.0; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.native.js index 87e24f26695d..e7156dce8590 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/lib/ndarray.native.js @@ -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 pairwise summation. * * @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 diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/src/main.c index 8966e002fc36..da7a4cbd2f77 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/src/main.c @@ -56,17 +56,17 @@ double API_SUFFIX(stdlib_strided_dapxsumpw)( const CBLAS_INT N, const double alp * @param N number of indexed elements * @param alpha scalar constant * @param X input array -* @param strideX index increment +* @param strideX stride length * @param offsetX starting index * @return output value * */ 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 ) { - double sum; CBLAS_INT ix; CBLAS_INT M; CBLAS_INT n; CBLAS_INT i; + double sum; double s0; double s1; double s2; @@ -79,10 +79,10 @@ double API_SUFFIX(stdlib_strided_dapxsumpw_ndarray)( const CBLAS_INT N, const do 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 ] ); + } if ( N < 8 ) { // Use simple summation... sum = 0.0; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.js index 3ecbc0a5a572..379b9b80a065 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.js @@ -152,14 +152,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 = dapxsumpw( 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(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.native.js index 6f7c206ec245..0b8e3216c508 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.dapxsumpw.native.js @@ -270,14 +270,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 = dapxsumpw( 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(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.js index 078c0dd3b263..5ddd47edc934 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.js @@ -152,14 +152,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 = dapxsumpw( 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(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.native.js index 76249e5b9787..7ddb3d74c471 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/test/test.ndarray.native.js @@ -161,14 +161,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 = dapxsumpw( 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(); });