diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md index 2e81b95e5a86..69fb7f27c9b9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/README.md @@ -20,7 +20,7 @@ limitations under the License. # sdsapxsumpw -> Add a constant to each single-precision floating-point strided array element and compute the sum using pairwise summation with extended accumulation. +> Add a scalar constant to each single-precision floating-point strided array element and compute the sum using pairwise summation with extended accumulation.
@@ -36,16 +36,16 @@ limitations under the License. var sdsapxsumpw = require( '@stdlib/blas/ext/base/sdsapxsumpw' ); ``` -#### sdsapxsumpw( N, alpha, x, stride ) +#### sdsapxsumpw( 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. +Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. ```javascript var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var v = sdsapxsumpw( 3, 5.0, x, 1 ); +var v = sdsapxsumpw( x.length, 5.0, x, 1 ); // returns 16.0 ``` @@ -54,9 +54,9 @@ 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`. +- **stride**: stride length. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -81,24 +81,24 @@ var v = sdsapxsumpw( 4, 5.0, x1, 2 ); // returns 25.0 ``` -#### sdsapxsumpw.ndarray( N, alpha, x, stride, offset ) +#### sdsapxsumpw.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. +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. ```javascript var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var v = sdsapxsumpw.ndarray( 3, 5.0, x, 1, 0 ); +var v = sdsapxsumpw.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 the strided array 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' ); @@ -131,11 +131,12 @@ var v = sdsapxsumpw.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 sdsapxsumpw = require( '@stdlib/blas/ext/base/sdsapxsumpw' ); -var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); var v = sdsapxsumpw( x.length, 5.0, x, 1 ); @@ -146,8 +147,125 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/sdsapxsumpw.h" +``` + +#### stdlib_strided_sdsapxsumpw( N, alpha, \*X, strideX ) + +Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + +float v = stdlib_strided_sdsapxsumpw( 4, 5.0f, x, 1 ); +// returns 30.0f +``` + +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. + +```c +float stdlib_strided_sdsapxsumpw( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_sdsapxsumpw_ndarray( N, alpha, \*X, strideX, offsetX ) + +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. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + +float v = stdlib_strided_sdsapxsumpw_ndarray( 4, 5.0f, x, 1, 0 ); +// returns 30.0f +``` + +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. +- **offsetX**: `[in] CBLAS_INT` starting index. + +```c +float stdlib_strided_sdsapxsumpw_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/sdsapxsumpw.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: + float v = stdlib_strided_sdsapxsumpw( N, 5.0f, x, strideX ); + + // Print the result: + printf( "Sum: %f\n", v ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js index 628e2e1b421c..4fe65a0b0cf3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 sdsapxsumpw = require( './../lib/sdsapxsumpw.js' ); // VARIABLES // -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js index e74c78320c40..fecb4dc6c4c0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 sdsapxsumpw = tryRequire( resolve( __dirname, './../lib/sdsapxsumpw.native.j var opts = { 'skip': ( sdsapxsumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js index 12ad6958b2ed..603330b947b2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 sdsapxsumpw = require( './../lib/ndarray.js' ); // VARIABLES // -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js index 9cfd9de3a1a1..4aa8b0cf1554 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 sdsapxsumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( sdsapxsumpw instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -10.0, 10.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float32', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/c/benchmark.length.c index e19321229e40..52476a38f4ff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 ]; float v; @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_sdsapxsumpw( len, 5.0f, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,40 @@ 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 ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_sdsapxsumpw_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 +177,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/sdsapxsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt index 8159c3b7a159..334a740a65f5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/repl.txt @@ -1,6 +1,6 @@ -{{alias}}( N, alpha, x, stride ) - Adds a constant to each single-precision floating-point strided array +{{alias}}( N, alpha, x, strideX ) + Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. @@ -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,7 +38,7 @@ > {{alias}}( x.length, 5.0, x, 1 ) 16.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/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 ) - Adds a constant to each single-precision floating-point strided array +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) + 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. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. + buffer, the offset parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -65,15 +65,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/sdsapxsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/types/index.d.ts index e45eed501e5e..28497108c2b7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/docs/types/index.d.ts @@ -23,12 +23,12 @@ */ interface Routine { /** - * Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. + * Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar constant * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -39,16 +39,16 @@ interface Routine { * var v = sdsapxsumpw( 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 pairwise summation with extended accumulation and alternative indexing semantics. + * 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. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar 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,16 +59,16 @@ interface Routine { * var v = sdsapxsumpw.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; } /** -* Adds a constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * @param N - number of indexed elements -* @param alpha - constant +* @param alpha - scalar 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/sdsapxsumpw/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c index cb3499d52896..444b24117666 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/c/example.c @@ -17,22 +17,21 @@ */ #include "stdlib/blas/ext/base/sdsapxsumpw.h" -#include #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 }; + 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; + // Specify the number of indexed elements: + const int N = 8; - // Specify the stride length: - const int64_t stride = 2; + // Specify a stride: + const int strideX = 1; // Compute the sum: - float v = stdlib_strided_sdsapxsumpw( N, 5.0f, x, stride ); + float v = stdlib_strided_sdsapxsumpw( N, 5.0f, x, strideX ); // Print the result: - printf( "sum: %f\n", v ); + printf( "Sum: %f\n", v ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js index 3557cd7adbd9..cb415805f839 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 sdsapxsumpw = 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 = sdsapxsumpw( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include/stdlib/blas/ext/base/sdsapxsumpw.h b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include/stdlib/blas/ext/base/sdsapxsumpw.h index 68d21a87e320..819ef864a820 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include/stdlib/blas/ext/base/sdsapxsumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/include/stdlib/blas/ext/base/sdsapxsumpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SDSAPXSUMPW_H #define STDLIB_BLAS_EXT_BASE_SDSAPXSUMPW_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. */ -float stdlib_strided_sdsapxsumpw( const int64_t N, const float alpha, const float *X, const int64_t stride ); +float API_SUFFIX(stdlib_strided_sdsapxsumpw)( 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. +*/ +float API_SUFFIX(stdlib_strided_sdsapxsumpw_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/sdsapxsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/index.js index 82f712630621..23e8edb2d0ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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. +* Add a scalar constant to each single-precision floating-point strided array element and compute the sum using pairwise summation with extended accumulation. * * @module @stdlib/blas/ext/base/sdsapxsumpw * @@ -29,7 +29,7 @@ * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * -* var v = sdsapxsumpw( 3, 5.0, x, 1 ); +* var v = sdsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.js index f0a112e6c379..f92ea188e9e4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.js @@ -33,7 +33,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. +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * ## Method * @@ -44,10 +44,10 @@ 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} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -58,7 +58,7 @@ var BLOCKSIZE = 128; * var v = sdsapxsumpw( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function sdsapxsumpw( N, alpha, x, stride, offset ) { +function sdsapxsumpw( N, alpha, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -76,57 +76,57 @@ function sdsapxsumpw( N, alpha, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return float64ToFloat32( alpha + x[ offset ] ); + ix = offsetX; + if ( strideX === 0 ) { + return float64ToFloat32( N * float64ToFloat32( alpha + x[ ix ] ) ); } - ix = offset; if ( N < 8 ) { // Use simple summation... s = 0.0; for ( i = 0; i < N; i++ ) { s += alpha + x[ ix ]; - ix += stride; + ix += strideX; } return float64ToFloat32( 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 float64ToFloat32( s ); } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return float64ToFloat32( sdsapxsumpw( n, alpha, x, stride, ix ) + sdsapxsumpw( N-n, alpha, x, stride, ix+(n*stride) ) ); // eslint-disable-line max-len + return float64ToFloat32( sdsapxsumpw( n, alpha, x, strideX, ix ) + sdsapxsumpw( N-n, alpha, x, strideX, ix+(n*strideX) ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.native.js index f224df09a8d6..e3aa87d383b0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/ndarray.native.js @@ -20,21 +20,19 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './sdsapxsumpw.native.js' ); +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. +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar 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,13 +43,8 @@ var addon = require( './sdsapxsumpw.native.js' ); * var v = sdsapxsumpw( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function sdsapxsumpw( N, alpha, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - return addon( N, alpha, view, stride ); +function sdsapxsumpw( N, alpha, x, strideX, offsetX ) { + return addon.ndarray( N, alpha, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.js index b8a60e31c26e..11a99173117c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.js @@ -20,14 +20,14 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +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. +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * ## Method * @@ -38,9 +38,9 @@ var sum = 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} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -51,32 +51,8 @@ var sum = require( './ndarray.js' ); * var v = sdsapxsumpw( 3, 5.0, x, 1 ); * // returns 16.0 */ -function sdsapxsumpw( N, alpha, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return float64ToFloat32( 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 float64ToFloat32( s ); - } - return sum( N, alpha, x, stride, ix ); +function sdsapxsumpw( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.native.js index 87529b203ed4..2fff7083b144 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/lib/sdsapxsumpw.native.js @@ -26,12 +26,12 @@ 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. +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar constant * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -39,11 +39,11 @@ var addon = require( './../src/addon.node' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * -* var v = sdsapxsumpw( N, 5.0, x, 1 ); +* var v = sdsapxsumpw( x.length, 5.0, x, 1 ); * // returns 16.0 */ -function sdsapxsumpw( N, alpha, x, stride ) { - return addon( N, alpha, x, stride ); +function sdsapxsumpw( N, alpha, x, strideX ) { + return addon( N, alpha, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/manifest.json index a9ab5dd7fcd4..bdecb363835f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/manifest.json @@ -28,50 +28,53 @@ { "task": "build", "src": [ - "./src/sdsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array" + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/create-double", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "benchmark", "src": [ - "./src/sdsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] }, { "task": "examples", "src": [ - "./src/sdsapxsumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.c index 898a21c4655b..b20f30f78a75 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/addon.c @@ -17,13 +17,14 @@ */ #include "stdlib/blas/ext/base/sdsapxsumpw.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_float.h" #include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -36,14 +37,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_FLOAT( 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, (double)stdlib_strided_sdsapxsumpw( 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, (double)API_SUFFIX(stdlib_strided_sdsapxsumpw)( 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_FLOAT( 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, (double)API_SUFFIX(stdlib_strided_sdsapxsumpw_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/sdsapxsumpw/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/main.c new file mode 100644 index 000000000000..1a8ac3145947 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/main.c @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/sdsapxsumpw.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" + +/** +* Adds a scalar constant to each single-precision floating-point strided array element and computes the sum using pairwise summation with extended accumulation. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX stride length +* @return output value +*/ +float API_SUFFIX(stdlib_strided_sdsapxsumpw)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_sdsapxsumpw_ndarray)( N, alpha, X, strideX, ox ); +} + +/** +* 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. +* +* ## 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 scalar constant +* @param X input array +* @param strideX stride length +* @param offsetX starting index +* @return output value +*/ +float API_SUFFIX(stdlib_strided_sdsapxsumpw_ndarray)( const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT M; + CBLAS_INT n; + CBLAS_INT i; + double sum; + double s0; + double s1; + double s2; + double s3; + double s4; + double s5; + double s6; + double s7; + + if ( N <= 0 ) { + return 0.0; + } + ix = offsetX; + if ( strideX == 0 ) { + return N * ( alpha + X[ ix ] ); + } + if ( N < 8 ) { + // Use simple summation... + sum = 0.0; + for ( i = 0; i < N; i++ ) { + sum += alpha + 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 = alpha + X[ ix ]; + 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+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: + sum = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) ); + + // Clean-up loop... + for (; i < N; i++ ) { + sum += alpha + 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_sdsapxsumpw_ndarray)( n, alpha, X, strideX, ix ) + API_SUFFIX(stdlib_strided_sdsapxsumpw_ndarray)( N-n, alpha, X, strideX, ix+(n*strideX) ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/sdsapxsumpw.c b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/sdsapxsumpw.c deleted file mode 100644 index 60e370384f87..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/src/sdsapxsumpw.c +++ /dev/null @@ -1,122 +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/sdsapxsumpw.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 -*/ -float stdlib_strided_sdsapxsumpw( 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; - - 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... - sum = 0.0; - for ( i = 0; i < N; i++ ) { - sum += alpha + 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 = 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; - - 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; - } - // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); - - // Clean-up loop... - for (; i < N; i++ ) { - sum += alpha + 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_sdsapxsumpw( n, alpha, xp1, stride ) + stdlib_strided_sdsapxsumpw( N-n, alpha, xp2, stride ); -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js index b4b46f9bc3aa..c6fff1a196d1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsapxsumpw( 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/sdsapxsumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js index f16fc008f44a..618773b2ff85 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/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 Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsapxsumpw( 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/sdsapxsumpw/test/test.sdsapxsumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js index 0d9f9d1f3555..d2d3f77e6527 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.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 Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsapxsumpw( 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/sdsapxsumpw/test/test.sdsapxsumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js index 29a8b8fec72c..0602b1648da3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsapxsumpw/test/test.sdsapxsumpw.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 Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsapxsumpw( 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(); });