From 1c4556a9c2ababf94b06fe3e3f50fc748b1c738c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 9 Nov 2024 14:57:13 +0500 Subject: [PATCH 1/9] feat: add C ndarray API and refactor --- .../blas/ext/base/dsapxsumpw/README.md | 143 ++++++++++++++++-- .../base/dsapxsumpw/benchmark/benchmark.js | 9 +- .../dsapxsumpw/benchmark/benchmark.native.js | 9 +- .../dsapxsumpw/benchmark/benchmark.ndarray.js | 9 +- .../benchmark/benchmark.ndarray.native.js | 9 +- .../dsapxsumpw/benchmark/c/benchmark.length.c | 48 +++++- .../blas/ext/base/dsapxsumpw/docs/repl.txt | 26 ++-- .../ext/base/dsapxsumpw/docs/types/index.d.ts | 12 +- .../ext/base/dsapxsumpw/examples/c/example.c | 11 +- .../ext/base/dsapxsumpw/examples/index.js | 7 +- .../include/stdlib/blas/ext/base/dsapxsumpw.h | 9 +- .../ext/base/dsapxsumpw/lib/dsapxsumpw.js | 36 +---- .../base/dsapxsumpw/lib/dsapxsumpw.native.js | 9 +- .../blas/ext/base/dsapxsumpw/lib/index.js | 2 +- .../blas/ext/base/dsapxsumpw/lib/ndarray.js | 52 +++---- .../ext/base/dsapxsumpw/lib/ndarray.native.js | 15 +- .../blas/ext/base/dsapxsumpw/manifest.json | 33 ++-- .../blas/ext/base/dsapxsumpw/src/addon.c | 31 +++- .../blas/ext/base/dsapxsumpw/src/dsapxsumpw.c | 124 --------------- .../blas/ext/base/dsapxsumpw/src/main.c | 135 +++++++++++++++++ 20 files changed, 449 insertions(+), 280 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/dsapxsumpw.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md index 01048e4dada5..3fdaea09d0dd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md @@ -36,7 +36,7 @@ limitations under the License. var dsapxsumpw = require( '@stdlib/blas/ext/base/dsapxsumpw' ); ``` -#### dsapxsumpw( N, alpha, x, stride ) +#### dsapxsumpw( N, alpha, x, strideX ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. @@ -44,19 +44,19 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsapxsumpw( N, 5.0, x, 1 ); +var v = dsapxsumpw( x.length, 5.0, x, 1 ); // returns 16.0 ``` The function has the following parameters: - **N**: number of indexed elements. +- **alpha**: scalar constant. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **stride**: 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 Float32Array = require( '@stdlib/array/float32' ); @@ -81,7 +81,7 @@ var v = dsapxsumpw( 4, 5.0, x1, 2 ); // returns 25.0 ``` -#### dsapxsumpw.ndarray( N, alpha, x, stride, offset ) +#### dsapxsumpw.ndarray( N, alpha, x, strideX, offsetX ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. @@ -89,17 +89,16 @@ Adds a constant to each single-precision floating-point strided array element an var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsapxsumpw.ndarray( N, 5.0, x, 1, 0 ); +var v = dsapxsumpw.ndarray( x.length, 5.0, x, 1, 0 ); // returns 16.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **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 Float32Array = require( '@stdlib/array/float32' ); @@ -132,11 +131,12 @@ var v = dsapxsumpw.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsapxsumpw = require( '@stdlib/blas/ext/base/dsapxsumpw' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x = discreteUniform( 10.0, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); var v = dsapxsumpw( x.length, 5.0, x, 1 ); @@ -147,8 +147,125 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dsapxsumpw.h" +``` + +#### stdlib_strided_dsapxsumpw( N, alpha, \*X, strideX ) + +Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +double v = stdlib_strided_dsapxsumpw( 3, 5.0, x, 1 ); +// returns 16.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] float` scalar constant. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dsapxsumpw( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dsapxsumpw_ndarray( N, alpha, \*X, strideX, offsetX ) + +Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +double v = stdlib_strided_dsapxsumpw_ndarray( 3, 5.0f, x, 1, 0 ); +// returns 16.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] float` scalar constant. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dsapxsumpw_ndarray( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dsapxsumpw.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of indexed elements: + const int N = 8; + + // Specify a stride: + const int strideX = 1; + + // Compute the sum: + double v = stdlib_strided_dsapxsumpw( N, 5.0f, x, strideX ); + + // Print the result: + printf( "sum: %lf\n", v ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.js index c59df6cb3717..37699ada5765 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -31,7 +30,9 @@ var dsapxsumpw = require( './../lib/dsapxsumpw.js' ); // VARIABLES // -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.native.js index 918d07f001c5..be17b36274a4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -36,7 +35,9 @@ var dsapxsumpw = tryRequire( resolve( __dirname, './../lib/dsapxsumpw.native.js' var opts = { 'skip': ( dsapxsumpw instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js index 6334702a3d99..c263429d4978 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -31,7 +30,9 @@ var dsapxsumpw = require( './../lib/ndarray.js' ); // VARIABLES // -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js index 52a7e54673ed..15d759f2b7ea 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/benchmark.ndarray.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -36,7 +35,9 @@ var dsapxsumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( dsapxsumpw instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c index 4cdf0eb2a044..98217d3e6445 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; float x[ len ]; double v; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dsapxsumpw_ndarray( len, 5.0f, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt index fccb48a65a4b..bdbc4f96d5b9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, alpha, x, stride ) +{{alias}}( N, alpha, x, strideX ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. - The `N` and `stride` parameters determine which elements in + The `N` and stride parameters determine which elements in the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -18,13 +18,13 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -38,8 +38,8 @@ > {{alias}}( x.length, 5.0, x, 1 ) 16.0 - // Using `N` and `stride` parameters: - > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ) + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > {{alias}}( 3, 5.0, x, 2 ) 16.0 @@ -50,14 +50,14 @@ 14.0 -{{alias}}.ndarray( N, alpha, x, stride, offset ) +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -66,15 +66,15 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts index ae2b5d0465ac..7df1b1d198f5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = dsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ - ( N: number, alpha: number, x: Float32Array, stride: number ): number; + ( N: number, alpha: number, x: Float32Array, strideX: number ): number; /** * Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and alternative indexing semantics and returning an extended precision result. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = dsapxsumpw.ndarray( x.length, 5.0, x, 1, 0 ); * // returns 16.0 */ - ndarray( N: number, alpha: number, x: Float32Array, stride: number, offset: number ): number; + ndarray( N: number, alpha: number, x: Float32Array, strideX: number, offsetX: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param alpha - constant * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/c/example.c index 0cada1535636..baa5c1bd1016 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/blas/ext/base/dsapxsumpw.h" -#include #include int main( void ) { // Create a strided array: - const float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; // Specify the number of elements: - const int64_t N = 4; + const int N = 8; - // Specify the stride length: - const int64_t stride = 2; + // Specify a stride: + const int strideX = 1; // Compute the sum: - double v = stdlib_strided_dsapxsumpw( N, 5.0f, x, stride ); + double v = stdlib_strided_dsapxsumpw( N, 5.0f, x, strideX ); // Print the result: printf( "sum: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/index.js index c35a255ecc9f..c108fcab9130 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/examples/index.js @@ -18,11 +18,12 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsapxsumpw = require( './../lib' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( -100.0, 100.0 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); var v = dsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h index ed447a6b0bf3..b05be6ba7629 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DSAPXSUMPW_H #define STDLIB_BLAS_EXT_BASE_DSAPXSUMPW_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. */ -double stdlib_strided_dsapxsumpw( const int64_t N, const float alpha, const float *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); + +/** +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +*/ +double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js index 19cd583fbc9e..a401d417a35f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js @@ -20,7 +20,8 @@ // MODULES // -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -39,44 +40,19 @@ var sum = require( './ndarray.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsapxsumpw( N, 5.0, x, 1 ); +* var v = dsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ -function dsapxsumpw( N, alpha, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return alpha + x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - s = 0.0; - for ( i = 0; i < N; i++ ) { - s += alpha + x[ ix ]; - ix += stride; - } - return s; - } - return sum( N, alpha, x, stride, ix ); +function dsapxsumpw( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js index fc3e3a7f7a1e..6ee4b5533d47 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js @@ -31,20 +31,19 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsapxsumpw( N, 5.0, x, 1 ); +* var v = dsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ -function dsapxsumpw( N, alpha, x, stride ) { - return addon( N, alpha, x, stride ); +function dsapxsumpw( N, alpha, x, strideX ) { + return addon( N, alpha, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js index a98445395b3d..93fa6796d6bd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js @@ -29,7 +29,7 @@ * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * -* var v = dsapxsumpw( 3, 5.0, x, 1 ); +* var v = dsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js index 6934f4e550ef..4d04b705f931 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js @@ -45,8 +45,8 @@ var BLOCKSIZE = 128; * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float32Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -57,7 +57,7 @@ var BLOCKSIZE = 128; * var v = dsapxsumpw( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dsapxsumpw( N, alpha, x, stride, offset ) { +function dsapxsumpw( N, alpha, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -75,57 +75,57 @@ function dsapxsumpw( N, alpha, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return alpha + x[ offset ]; + if ( N === 1 || strideX === 0 ) { + return alpha + x[ offsetX ]; } - ix = offset; + ix = offsetX; if ( N < 8 ) { // Use simple summation... s = 0.0; for ( i = 0; i < N; i++ ) { s += alpha + x[ ix ]; - ix += stride; + ix += strideX; } return s; } if ( N <= BLOCKSIZE ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = alpha + x[ ix ]; - s1 = alpha + x[ ix+stride ]; - s2 = alpha + x[ ix+(2*stride) ]; - s3 = alpha + x[ ix+(3*stride) ]; - s4 = alpha + x[ ix+(4*stride) ]; - s5 = alpha + x[ ix+(5*stride) ]; - s6 = alpha + x[ ix+(6*stride) ]; - s7 = alpha + x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 = alpha + x[ ix+strideX ]; + s2 = alpha + x[ ix+(2*strideX) ]; + s3 = alpha + x[ ix+(3*strideX) ]; + s4 = alpha + x[ ix+(4*strideX) ]; + s5 = alpha + x[ ix+(5*strideX) ]; + s6 = alpha + x[ ix+(6*strideX) ]; + s7 = alpha + x[ ix+(7*strideX) ]; + ix += 8 * strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += alpha + x[ ix ]; - s1 += alpha + x[ ix+stride ]; - s2 += alpha + x[ ix+(2*stride) ]; - s3 += alpha + x[ ix+(3*stride) ]; - s4 += alpha + x[ ix+(4*stride) ]; - s5 += alpha + x[ ix+(5*stride) ]; - s6 += alpha + x[ ix+(6*stride) ]; - s7 += alpha + x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 += alpha + x[ ix+strideX ]; + s2 += alpha + x[ ix+(2*strideX) ]; + s3 += alpha + x[ ix+(3*strideX) ]; + s4 += alpha + x[ ix+(4*strideX) ]; + s5 += alpha + x[ ix+(5*strideX) ]; + s6 += alpha + x[ ix+(6*strideX) ]; + s7 += alpha + x[ ix+(7*strideX) ]; + ix += 8 * strideX; } // Pairwise sum the accumulators: - s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + s = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) ); // Clean-up loop... for ( i; i < N; i++ ) { s += alpha + x[ ix ]; - ix += stride; + ix += strideX; } return s; } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return dsapxsumpw( n, alpha, x, stride, ix ) + dsapxsumpw( N-n, alpha, x, stride, ix+(n*stride) ); // eslint-disable-line max-len + return dsapxsumpw( n, alpha, x, strideX, ix ) + dsapxsumpw( N-n, alpha, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js index 92189fab677c..1bf233036375 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dsapxsumpw.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,8 +31,8 @@ var addon = require( './dsapxsumpw.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float32Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -45,11 +43,8 @@ var addon = require( './dsapxsumpw.native.js' ); * var v = dsapxsumpw( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dsapxsumpw( N, alpha, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - return addon( N, alpha, view, stride ); +function dsapxsumpw( N, alpha, x, strideX, offsetX ) { + return addon.ndarray( N, alpha, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/manifest.json index 409193a86768..fee160f42d76 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/manifest.json @@ -28,50 +28,53 @@ { "task": "build", "src": [ - "./src/dsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float32array" + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/create-double" ] }, { "task": "benchmark", "src": [ - "./src/dsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", "src": [ - "./src/dsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/addon.c index 0f22f7120fdb..0d17dcbe53f1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/addon.c @@ -18,13 +18,14 @@ */ #include "stdlib/blas/ext/base/dsapxsumpw.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_double.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -37,14 +38,28 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dsapxsumpw( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsapxsumpw)( N, alpha, X, strideX ), v ); + return v; +} +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( N, alpha, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/dsapxsumpw.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/dsapxsumpw.c deleted file mode 100644 index 932fab7d61f2..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/dsapxsumpw.c +++ /dev/null @@ -1,124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/blas/ext/base/dsapxsumpw.h" -#include - -/** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. -* -* ## Method -* -* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. -* -* ## References -* -* - 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 N number of indexed elements -* @param alpha constant -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dsapxsumpw( const int64_t N, const float alpha, const float *X, const int64_t stride ) { - float *xp1; - float *xp2; - double sum; - int64_t ix; - int64_t M; - int64_t n; - int64_t i; - double s0; - double s1; - double s2; - double s3; - double s4; - double s5; - double s6; - double s7; - double a; - - if ( N <= 0 ) { - return 0.0; - } - a = (double)alpha; - if ( N == 1 || stride == 0 ) { - return a + (double)X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - sum = 0.0; - for ( i = 0; i < N; i++ ) { - sum += a + (double)X[ ix ]; - ix += stride; - } - return sum; - } - // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) - if ( N <= 128 ) { - // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... - s0 = a + (double)X[ ix ]; - s1 = a + (double)X[ ix+stride ]; - s2 = a + (double)X[ ix+(2*stride) ]; - s3 = a + (double)X[ ix+(3*stride) ]; - s4 = a + (double)X[ ix+(4*stride) ]; - s5 = a + (double)X[ ix+(5*stride) ]; - s6 = a + (double)X[ ix+(6*stride) ]; - s7 = a + (double)X[ ix+(7*stride) ]; - ix += 8 * stride; - - M = N % 8; - for ( i = 8; i < N-M; i += 8 ) { - s0 += a + (double)X[ ix ]; - s1 += a + (double)X[ ix+stride ]; - s2 += a + (double)X[ ix+(2*stride) ]; - s3 += a + (double)X[ ix+(3*stride) ]; - s4 += a + (double)X[ ix+(4*stride) ]; - s5 += a + (double)X[ ix+(5*stride) ]; - s6 += a + (double)X[ ix+(6*stride) ]; - s7 += a + (double)X[ ix+(7*stride) ]; - ix += 8 * stride; - } - // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); - - // Clean-up loop... - for (; i < N; i++ ) { - sum += a + (double)X[ ix ]; - ix += stride; - } - return sum; - } - // Recurse by dividing by two, but avoiding non-multiples of unroll factor... - n = N / 2; - n -= n % 8; - if ( stride < 0 ) { - xp1 = (float *)X + ( (n-N)*stride ); - xp2 = (float *)X; - } else { - xp1 = (float *)X; - xp2 = (float *)X + ( n*stride ); - } - return stdlib_strided_dsapxsumpw( n, alpha, xp1, stride ) + stdlib_strided_dsapxsumpw( N-n, alpha, xp2, stride ); -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c new file mode 100644 index 000000000000..9b373d469332 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/dsapxsumpw.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* +* ## Method +* +* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. +* +* ## References +* +* - 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 N number of indexed elements +* @param alpha constant +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( N, alpha, X, strideX, ox ); +} + +/** +* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics and returning an extended precision result. +* +* ## Method +* +* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. +* +* ## References +* +* - 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 N number of indexed elements +* @param alpha constant +* @param X input array +* @param strideX stride length +* @param offsetX starting index +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + double sum; + CBLAS_INT ix; + CBLAS_INT M; + CBLAS_INT n; + CBLAS_INT i; + double s0; + double s1; + double s2; + double s3; + double s4; + double s5; + double s6; + double s7; + double a; + + if ( N <= 0 ) { + return 0.0; + } + a = (double)alpha; + if ( N == 1 || strideX == 0 ) { + return a + (double)X[ offsetX ]; + } + ix = offsetX; + if ( N < 8 ) { + // Use simple summation... + sum = 0.0; + for ( i = 0; i < N; i++ ) { + sum += a + (double)X[ ix ]; + ix += strideX; + } + return sum; + } + // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) + if ( N <= 128 ) { + // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... + s0 = a + (double)X[ ix ]; + s1 = a + (double)X[ ix+strideX ]; + s2 = a + (double)X[ ix+(2*strideX) ]; + s3 = a + (double)X[ ix+(3*strideX) ]; + s4 = a + (double)X[ ix+(4*strideX) ]; + s5 = a + (double)X[ ix+(5*strideX) ]; + s6 = a + (double)X[ ix+(6*strideX) ]; + s7 = a + (double)X[ ix+(7*strideX) ]; + ix += 8 * strideX; + + M = N % 8; + for ( i = 8; i < N-M; i += 8 ) { + s0 += a + (double)X[ ix ]; + s1 += a + (double)X[ ix+strideX ]; + s2 += a + (double)X[ ix+(2*strideX) ]; + s3 += a + (double)X[ ix+(3*strideX) ]; + s4 += a + (double)X[ ix+(4*strideX) ]; + s5 += a + (double)X[ ix+(5*strideX) ]; + s6 += a + (double)X[ ix+(6*strideX) ]; + s7 += a + (double)X[ ix+(7*strideX) ]; + ix += 8 * strideX; + } + // Pairwise sum the accumulators: + sum = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) ); + + // Clean-up loop... + for (; i < N; i++ ) { + sum += a + (double)X[ ix ]; + ix += strideX; + } + return sum; + } + // Recurse by dividing by two, but avoiding non-multiples of unroll factor... + n = N / 2; + n -= n % 8; + return API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( n, alpha, X, strideX, ix ) + API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( N-n, alpha, X, strideX, ix+(n*strideX) ); +} From ed3ef52f279493ecc0c71386aa00a4136d398136 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 9 Nov 2024 15:24:42 +0500 Subject: [PATCH 2/9] chore: apply review suggestions Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md index 3fdaea09d0dd..cc92ce706601 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md @@ -180,7 +180,7 @@ Adds a constant to each single-precision floating-point strided array element an ```c const float x[] = { 1.0f, -2.0f, 2.0f }; -double v = stdlib_strided_dsapxsumpw( 3, 5.0, x, 1 ); +double v = stdlib_strided_dsapxsumpw( 3, 5.0f, x, 1 ); // returns 16.0 ``` From fe3ba5d9e834f122e5003d479c598add12f4ba31 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:00:49 +0000 Subject: [PATCH 3/9] docs: apply review suggestions --- .../@stdlib/blas/ext/base/dsapxsumpw/README.md | 8 ++++---- .../@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt | 6 +++--- .../blas/ext/base/dsapxsumpw/docs/types/index.d.ts | 12 ++++++------ .../include/stdlib/blas/ext/base/dsapxsumpw.h | 4 ++-- .../blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js | 4 ++-- .../ext/base/dsapxsumpw/lib/dsapxsumpw.native.js | 4 ++-- .../@stdlib/blas/ext/base/dsapxsumpw/lib/index.js | 2 +- .../@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js | 4 ++-- .../blas/ext/base/dsapxsumpw/lib/ndarray.native.js | 4 ++-- .../@stdlib/blas/ext/base/dsapxsumpw/src/main.c | 10 +++++----- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md index cc92ce706601..574ac07fd00e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md @@ -38,7 +38,7 @@ var dsapxsumpw = require( '@stdlib/blas/ext/base/dsapxsumpw' ); #### dsapxsumpw( N, alpha, x, strideX ) -Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -83,7 +83,7 @@ var v = dsapxsumpw( 4, 5.0, x1, 2 ); #### dsapxsumpw.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -175,7 +175,7 @@ console.log( v ); #### stdlib_strided_dsapxsumpw( N, alpha, \*X, strideX ) -Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; @@ -197,7 +197,7 @@ double stdlib_strided_dsapxsumpw( const CBLAS_INT N, const float alpha, const fl #### stdlib_strided_dsapxsumpw_ndarray( N, alpha, \*X, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt index bdbc4f96d5b9..d60491490e04 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, alpha, x, strideX ) Adds a constant to each single-precision floating-point strided array - element and computes the sum using pairwise summation with extended + element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. The `N` and stride parameters determine which elements in @@ -52,8 +52,8 @@ {{alias}}.ndarray( N, alpha, x, strideX, offsetX ) Adds a constant to each single-precision floating-point strided array - element and computes the sum using pairwise summation with extended - accumulation and alternative indexing semantics and returning an extended + element, computes the sum using pairwise summation with extended + accumulation and alternative indexing semantics, and returning an extended precision result. While typed array views mandate a view offset based on the underlying diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts index 7df1b1d198f5..17f0dbe102c3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts @@ -23,10 +23,10 @@ */ interface Routine { /** - * Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. + * Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar constant * @param x - input array * @param strideX - stride length * @returns sum @@ -42,10 +42,10 @@ interface Routine { ( N: number, alpha: number, x: Float32Array, strideX: number ): number; /** - * Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and alternative indexing semantics and returning an extended precision result. + * Adds a constant to each single-precision floating-point strided array element, computes the sum using extended accumulation and alternative indexing semantics, and returning an extended precision result. * * @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 @@ -63,10 +63,10 @@ interface Routine { } /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @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/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h index b05be6ba7629..8c52ff67522b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h @@ -29,12 +29,12 @@ extern "C" { #endif /** -* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); /** -* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js index a401d417a35f..a342e4624888 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js @@ -27,7 +27,7 @@ var ndarray = require( './ndarray.js' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * @@ -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 {Float32Array} x - input array * @param {integer} strideX - stride length * @returns {number} sum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js index 6ee4b5533d47..955c9c99b82b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js @@ -26,10 +26,10 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar constant * @param {Float32Array} x - input array * @param {integer} strideX - stride length * @returns {number} sum diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js index 93fa6796d6bd..fca1234d04c8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Add a constant to each single-precision floating-point strided array element and compute the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Add a constant to each single-precision floating-point strided array element, compute the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @module @stdlib/blas/ext/base/dsapxsumpw * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js index 4d04b705f931..620498bcbc37 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js @@ -32,7 +32,7 @@ var BLOCKSIZE = 128; // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * @@ -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 {Float32Array} x - input array * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js index 1bf233036375..4ce41f1b711f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js @@ -26,10 +26,10 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar constant * @param {Float32Array} x - input array * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c index 9b373d469332..839206bd7393 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -21,7 +21,7 @@ #include "stdlib/strided/base/stride2offset.h" /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * @@ -32,7 +32,7 @@ * - 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 N number of indexed elements -* @param alpha constant +* @param alpha scalar constant * @param X input array * @param strideX stride length * @return output value @@ -43,7 +43,7 @@ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alp } /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics, and returning an extended precision result. * * ## Method * @@ -54,18 +54,18 @@ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alp * - 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 N number of indexed elements -* @param alpha constant +* @param alpha scalar constant * @param X input array * @param strideX stride length * @param offsetX starting index * @return output value */ double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *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; From 4ffced913d38a460253b291825b01da61eecb5c6 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 18 Nov 2024 00:10:08 -0800 Subject: [PATCH 4/9] docs: update copyright year Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c index 839206bd7393..ab9ad48c7fae 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 697897b06f0b2e540e8c3ed86c5abcd1e66dfa4c Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 18 Nov 2024 09:05:11 +0000 Subject: [PATCH 5/9] chore: suppress C lint warnings --- .../blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c index 98217d3e6445..c0fcd8c3aa88 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/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_dsapxsumpw( len, 5.0f, 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_dsapxsumpw_ndarray( len, 5.0f, x, 1, 0 ); if ( v != v ) { printf( "should not return NaN\n" ); From e06c712395b5b5f820864c773baf4d98e0d2f60c Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:26:55 +0000 Subject: [PATCH 6/9] docs: apply review suggestions --- .../@stdlib/blas/ext/base/dsapxsumpw/README.md | 10 +++++----- .../@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt | 4 ++-- .../blas/ext/base/dsapxsumpw/docs/types/index.d.ts | 6 +++--- .../@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js | 2 +- .../blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js | 2 +- .../@stdlib/blas/ext/base/dsapxsumpw/lib/index.js | 2 +- .../@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js | 2 +- .../blas/ext/base/dsapxsumpw/lib/ndarray.native.js | 2 +- .../@stdlib/blas/ext/base/dsapxsumpw/src/main.c | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md index 574ac07fd00e..16850033e25f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md @@ -20,7 +20,7 @@ limitations under the License. # dsapxsumpw -> Add a constant to each single-precision floating-point strided array element and compute the sum using pairwise summation with extended accumulation and returning an extended precision result. +> Add a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result.
@@ -38,7 +38,7 @@ var dsapxsumpw = require( '@stdlib/blas/ext/base/dsapxsumpw' ); #### dsapxsumpw( N, alpha, x, strideX ) -Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -83,7 +83,7 @@ var v = dsapxsumpw( 4, 5.0, x1, 2 ); #### dsapxsumpw.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -175,7 +175,7 @@ console.log( v ); #### stdlib_strided_dsapxsumpw( N, alpha, \*X, strideX ) -Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; @@ -197,7 +197,7 @@ double stdlib_strided_dsapxsumpw( const CBLAS_INT N, const float alpha, const fl #### stdlib_strided_dsapxsumpw_ndarray( N, alpha, \*X, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt index d60491490e04..f96a23d6b20c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, alpha, x, strideX ) Adds a constant to each single-precision floating-point strided array - element, computes the sum using pairwise summation with extended + element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. The `N` and stride parameters determine which elements in @@ -52,7 +52,7 @@ {{alias}}.ndarray( N, alpha, x, strideX, offsetX ) Adds a constant to each single-precision floating-point strided array - element, computes the sum using pairwise summation with extended + element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts index 17f0dbe102c3..f42e47bcc807 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts @@ -23,7 +23,7 @@ */ interface Routine { /** - * Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. + * Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param N - number of indexed elements * @param alpha - scalar constant @@ -42,7 +42,7 @@ interface Routine { ( N: number, alpha: number, x: Float32Array, strideX: number ): number; /** - * Adds a constant to each single-precision floating-point strided array element, computes the sum using extended accumulation and alternative indexing semantics, and returning an extended precision result. + * Adds a constant to each single-precision floating-point strided array element, and computes the sum using extended accumulation and alternative indexing semantics, and returning an extended precision result. * * @param N - number of indexed elements * @param alpha - scalar constant @@ -63,7 +63,7 @@ interface Routine { } /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param N - number of indexed elements * @param alpha - scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js index a342e4624888..f1278f3b1d92 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.js @@ -27,7 +27,7 @@ var ndarray = require( './ndarray.js' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js index 955c9c99b82b..7c3c54f7bff3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/dsapxsumpw.native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js index fca1234d04c8..c832e3e75c3a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Add a constant to each single-precision floating-point strided array element, compute the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Add a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @module @stdlib/blas/ext/base/dsapxsumpw * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js index 620498bcbc37..cae5c35c9de1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js @@ -32,7 +32,7 @@ var BLOCKSIZE = 128; // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js index 4ce41f1b711f..d62f41a3ffca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c index ab9ad48c7fae..e17a32d3256d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -21,7 +21,7 @@ #include "stdlib/strided/base/stride2offset.h" /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. * * ## Method * @@ -43,7 +43,7 @@ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alp } /** -* Adds a constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics, and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics, and returning an extended precision result. * * ## Method * From e56f84f7ba43db5e59f9af30d7850e96b3c023eb Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:13:19 +0000 Subject: [PATCH 7/9] docs: apply review suggestions --- lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md | 6 +++--- .../@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt | 6 +++--- .../@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts | 2 +- .../dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h | 2 +- .../@stdlib/blas/ext/base/dsapxsumpw/src/main.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md index 16850033e25f..5157f89aae5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/README.md @@ -20,7 +20,7 @@ limitations under the License. # dsapxsumpw -> Add a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +> Add a constant to each single-precision floating-point strided array element, and compute the sum using pairwise summation with extended accumulation and returning an extended precision result.
@@ -83,7 +83,7 @@ var v = dsapxsumpw( 4, 5.0, x1, 2 ); #### dsapxsumpw.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -197,7 +197,7 @@ double stdlib_strided_dsapxsumpw( const CBLAS_INT N, const float alpha, const fl #### stdlib_strided_dsapxsumpw_ndarray( N, alpha, \*X, strideX, offsetX ) -Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. +Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt index f96a23d6b20c..18d102a6d4ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/repl.txt @@ -4,8 +4,8 @@ element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. - The `N` and stride parameters determine which elements in - the strided array are accessed at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -53,7 +53,7 @@ {{alias}}.ndarray( N, alpha, x, strideX, offsetX ) Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended - accumulation and alternative indexing semantics, and returning an extended + accumulation and alternative indexing semantics and returning an extended precision result. While typed array views mandate a view offset based on the underlying diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts index f42e47bcc807..b233d3d212e3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/docs/types/index.d.ts @@ -42,7 +42,7 @@ interface Routine { ( N: number, alpha: number, x: Float32Array, strideX: number ): number; /** - * Adds a constant to each single-precision floating-point strided array element, and computes the sum using extended accumulation and alternative indexing semantics, and returning an extended precision result. + * Adds a constant to each single-precision floating-point strided array element, and computes the sum using extended accumulation and alternative indexing semantics and returning an extended precision result. * * @param N - number of indexed elements * @param alpha - scalar constant diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h index 8c52ff67522b..f6a02c1bf6bc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h @@ -34,7 +34,7 @@ extern "C" { double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); /** -* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result. +* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c index e17a32d3256d..94d358a482b5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -43,7 +43,7 @@ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alp } /** -* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics, and returning an extended precision result. +* Adds a constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and using alternative indexing semantics and returning an extended precision result. * * ## Method * From 3b81d9166000c81ed8e932ca8309d3df6bf3f570 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:50:46 +0000 Subject: [PATCH 8/9] fix: apply code review suggestions --- .../@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js | 6 +++--- .../@stdlib/blas/ext/base/dsapxsumpw/src/main.c | 6 +++--- .../blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.js | 4 ++-- .../blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js | 4 ++-- .../@stdlib/blas/ext/base/dsapxsumpw/test/test.ndarray.js | 4 ++-- .../blas/ext/base/dsapxsumpw/test/test.ndarray.native.js | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js index cae5c35c9de1..c41a120b8375 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/lib/ndarray.js @@ -75,10 +75,10 @@ function dsapxsumpw( 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/dsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c index 94d358a482b5..9ec74b16d411 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/src/main.c @@ -80,10 +80,10 @@ double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const f return 0.0; } a = (double)alpha; - if ( N == 1 || strideX == 0 ) { - return a + (double)X[ offsetX ]; - } ix = offsetX; + if ( strideX == 0 ) { + return (double)N * ( a + (double)X[ ix ] ); + } if ( N < 8 ) { // Use simple summation... sum = 0.0; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.js index f69376f0c42a..f9a6a7fec01a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.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 sum of the first element plus a constant repeated N times', function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dsapxsumpw( 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/dsapxsumpw/test/test.dsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js index 1c7f5c6dae4d..14fd7cc0f538 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.dsapxsumpw.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 sum of the first element plus a constant repeated N times', opts, function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dsapxsumpw( 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/dsapxsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.ndarray.js index 0bff2d21e577..7436061d57e5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/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 sum of the first element plus a constant repeated N times', function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dsapxsumpw( 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/dsapxsumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.ndarray.native.js index 5357b08671b6..deeab22ef2c7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/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 sum of the first element plus a constant repeated N times', opts, function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dsapxsumpw( 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(); }); From d835ece5ac4d50ffce2ffb89f282ab1384a307f5 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 19 Nov 2024 15:40:45 -0800 Subject: [PATCH 9/9] Apply suggestions from code review Signed-off-by: Athan --- .../base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h index f6a02c1bf6bc..33e8639a2714 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsapxsumpw/include/stdlib/blas/ext/base/dsapxsumpw.h @@ -29,12 +29,12 @@ extern "C" { #endif /** -* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and returning an extended precision result. +* Adds a scalar constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); /** -* Adds a scalar constant to each single-precision floating-point strided array element, computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +* Adds a scalar constant to each single-precision floating-point strided array element, and computes the sum using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );