diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/README.md index 40404308719d..91724df1e975 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/README.md @@ -36,7 +36,7 @@ limitations under the License. var sdsnansumpw = require( '@stdlib/blas/ext/base/sdsnansumpw' ); ``` -#### sdsnansumpw( N, x, stride ) +#### sdsnansumpw( N, x, strideX ) Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation. @@ -44,9 +44,8 @@ Computes the sum of single-precision floating-point strided array elements, igno var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = sdsnansumpw( N, x, 1 ); +var v = sdsnansumpw( x.length, x, 1 ); // returns 1.0 ``` @@ -54,9 +53,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **stride**: index increment for `x`. +- **strideX**: 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 `x`, +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,7 +80,7 @@ var v = sdsnansumpw( 4, x1, 2 ); // returns 5.0 ``` -#### sdsnansumpw.ndarray( N, x, stride, offset ) +#### sdsnansumpw.ndarray( N, x, strideX, offsetX ) Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation and alternative indexing semantics. @@ -96,9 +95,9 @@ var v = sdsnansumpw.ndarray( x.length, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of 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 calculate the sum of every other element starting from the second element: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -136,14 +135,14 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var sdsnansumpw = require( '@stdlib/blas/ext/base/sdsnansumpw' ); -function randOrNan() { - if ( bernoulli() < 0.2 ) { +function rand() { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } return discreteUniform( 0, 100 ); } -var x = filledarrayBy( 10, 'float32', randOrNan ); +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); var v = sdsnansumpw( x.length, x, 1 ); @@ -154,8 +153,123 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/sdsnansumpw.h" +``` + +#### stdlib_strided_sdsnansumpw( N, \*X, strideX ) + +Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation. + +```c +const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f }; + +float v = stdlib_strided_sdsnansumpw( 4, x, 1 ); +// returns 1.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. + +```c +float stdlib_strided_sdsnansumpw( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_sdsnansumpw_ndarray( N, \*X, strideX, offsetX ) + +Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation and alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f }; + +float v = stdlib_strided_sdsnansumpw_ndarray( 4, x, 1, 0 ); +// returns 1.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. +- **offsetX**: `[in] CBLAS_INT` starting index. + +```c +float stdlib_strided_sdsnansumpw_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/sdsnansumpw.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, 0.0f/0.0f, 0.0f/0.0f }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Compute the sum: + float v = stdlib_strided_sdsnansumpw( N, x, strideX ); + + // Print the result: + printf( "Sum: %f\n", v ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.js index 7a9ea8442aab..151a2c2189cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.js @@ -32,11 +32,17 @@ var sdsnansumpw = require( './../lib/sdsnansumpw.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ function rand() { - if ( bernoulli( 0.2 ) ) { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } - return uniform( -20.0, -10.0 ); + return uniform( -10, 10 ); } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.native.js index 6ad1e3a6c0b5..0d05eb97c099 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.native.js @@ -41,11 +41,17 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ function rand() { - if ( bernoulli( 0.2 ) ) { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } - return uniform( -20.0, -10.0 ); + return uniform( -10, 10 ); } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.js index ee99afc6c450..2a2f25c6d242 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.js @@ -32,11 +32,17 @@ var sdsnansumpw = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ function rand() { - if ( bernoulli( 0.2 ) ) { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } - return uniform( -20.0, -10.0 ); + return uniform( -10, 10 ); } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.native.js index a7dba5e27b1d..3cc403692ca0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/benchmark.ndarray.native.js @@ -41,11 +41,17 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ function rand() { - if ( bernoulli( 0.2 ) ) { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } - return uniform( -20.0, -10.0 ); + return uniform( -10, 10 ); } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/c/benchmark.length.c index c473647bbea6..19dfb2565266 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/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; @@ -111,6 +111,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_sdsnansumpw( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -124,6 +125,44 @@ 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++ ) { + if ( rand_float() < 0.2f ) { + x[ i ] = 0.0f / 0.0f; // NaN + } else { + 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_sdsnansumpw_ndarray( len, 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. */ @@ -146,7 +185,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/sdsnansumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/repl.txt index 6e2926e6d4d1..811e7f0d3b23 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/repl.txt @@ -1,11 +1,11 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation. - 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. @@ -20,8 +20,8 @@ x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -35,7 +35,7 @@ > {{alias}}( x.length, x, 1 ) 1.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, NaN, NaN ] ); > {{alias}}( 4, x, 2 ) 1.0 @@ -47,14 +47,14 @@ -1.0 -{{alias}}.ndarray( N, x, stride, offset ) +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and 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 ---------- @@ -64,10 +64,10 @@ 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/sdsnansumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/types/index.d.ts index 8faed3809021..6f0353ad1bd4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = sdsnansumpw( x.length, x, 1 ); * // returns 1.0 */ - ( N: number, x: Float32Array, stride: number ): number; + ( N: number, x: Float32Array, strideX: number ): number; /** * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation and alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = sdsnansumpw.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: Float32Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @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/sdsnansumpw/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/c/example.c index 972d4f1f692d..d3ed2b3e2379 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/c/example.c @@ -17,22 +17,21 @@ */ #include "stdlib/blas/ext/base/sdsnansumpw.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, 0.0/0.0, 0.0/0.0 }; + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f/0.0f, 0.0f/0.0f }; // Specify the number of elements: - const int64_t N = 5; + const int N = 5; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Compute the sum: - float v = stdlib_strided_sdsnansumpw( N, x, stride ); + float v = stdlib_strided_sdsnansumpw( N, 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/sdsnansumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/index.js index d5aa91c81429..c9325f830123 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/examples/index.js @@ -24,7 +24,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' ); var sdsnansumpw = require( './../lib' ); function rand() { - if ( bernoulli( 0.2 ) ) { + if ( bernoulli( 0.5 ) < 1 ) { return NaN; } return discreteUniform( 0, 100 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/include/stdlib/blas/ext/base/sdsnansumpw.h b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/include/stdlib/blas/ext/base/sdsnansumpw.h index b8e6fcdc52ac..a4f945202783 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/include/stdlib/blas/ext/base/sdsnansumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/include/stdlib/blas/ext/base/sdsnansumpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SDSNANSUMPW_H #define STDLIB_BLAS_EXT_BASE_SDSNANSUMPW_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. @@ -29,9 +29,14 @@ extern "C" { #endif /** -* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended summation. +* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation. */ -float stdlib_strided_sdsnansumpw( const int64_t N, const float *X, const int64_t stride ); +float API_SUFFIX(stdlib_strided_sdsnansumpw)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); + +/** +* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation and alternative indexing semnantics. +*/ +float API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.js index 4b9c01c728f4..8fa729ae3a81 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.js @@ -46,20 +46,19 @@ var BLOCKSIZE = 128; * * @param {PositiveInteger} N - number of indexed elements * @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 * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); * * var v = sdsnansumpw( 5, x, 2, 1 ); * // returns 5.0 */ -function sdsnansumpw( N, x, stride, offset ) { +function sdsnansumpw( N, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -77,13 +76,13 @@ function sdsnansumpw( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - if ( isnanf( x[ offset ] ) ) { + ix = offsetX; + if ( strideX === 0 ) { + if ( isnanf( x[ ix ] ) ) { return 0.0; } - return x[ offset ]; + return float64ToFloat32( N * x[ ix ] ); } - ix = offset; if ( N < 8 ) { // Use simple summation... s = 0.0; @@ -91,64 +90,64 @@ function sdsnansumpw( N, x, stride, offset ) { if ( isnanf( x[ ix ] ) === false ) { s += 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 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s1 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s2 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s3 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s4 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s5 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s6 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s7 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s1 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s2 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s3 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s4 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s5 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s6 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s7 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += 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++ ) { if ( isnanf( x[ ix ] ) === false ) { s += 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( sdsnansumpw( n, x, stride, ix ) + sdsnansumpw( N-n, x, stride, ix+(n*stride) ) ); // eslint-disable-line max-len + return float64ToFloat32( sdsnansumpw( n, x, strideX, ix ) + sdsnansumpw( N-n, x, strideX, ix+(n*strideX) ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.native.js index 07ae6112b38c..7f2f05c2e94f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/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( './sdsnansumpw.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,25 +30,20 @@ var addon = require( './sdsnansumpw.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @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 * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); * * var v = sdsnansumpw( 5, x, 2, 1 ); * // returns 5.0 */ -function sdsnansumpw( N, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - return addon( N, view, stride ); +function sdsnansumpw( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.js index 10b9020b1d9e..0405f0a623fe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.js @@ -20,9 +20,8 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -40,7 +39,7 @@ var sum = require( './ndarray.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -51,37 +50,8 @@ var sum = require( './ndarray.js' ); * var v = sdsnansumpw( x.length, x, 1 ); * // returns 1.0 */ -function sdsnansumpw( N, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - if ( isnanf( x[ 0 ] ) ) { - return 0.0; - } - return 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++ ) { - if ( isnanf( x[ ix ] ) === false ) { - s += x[ ix ]; - } - ix += stride; - } - return float64ToFloat32( s ); - } - return sum( N, x, stride, ix ); +function sdsnansumpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.native.js index 9bb9ed2fd912..4e76ed047525 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/lib/sdsnansumpw.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -41,8 +41,8 @@ var addon = require( './../src/addon.node' ); * var v = sdsnansumpw( x.length, x, 1 ); * // returns 1.0 */ -function sdsnansumpw( N, x, stride ) { - return addon( N, x, stride ); +function sdsnansumpw( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/manifest.json index 5610ca14e10a..74fb2fbc4d2f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/manifest.json @@ -28,61 +28,54 @@ { "task": "build", "src": [ - "./src/sdsnansumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float32array", - "@stdlib/math/base/assert/is-nanf" + "@stdlib/napi/create-double", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "benchmark", "src": [ - "./src/sdsnansumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/napi/export", - "@stdlib/napi/argv", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/math/base/assert/is-nanf" + "@stdlib/math/base/assert/is-nanf", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "examples", "src": [ - "./src/sdsnansumpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/napi/export", - "@stdlib/napi/argv", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/math/base/assert/is-nanf" + "@stdlib/math/base/assert/is-nanf", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/addon.c index 892e6569eb6d..4ca815afeb37 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/addon.c @@ -17,12 +17,13 @@ */ #include "stdlib/blas/ext/base/sdsnansumpw.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_strided_float32array.h" +#include "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -34,14 +35,27 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); - - napi_value v; - napi_status status = napi_create_double( env, (double)stdlib_strided_sdsnansumpw( N, X, stride ), &v ); - assert( status == napi_ok ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_sdsnansumpw)( N, 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, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( N, 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/sdsnansumpw/src/sdsnansumpw.c b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/main.c similarity index 60% rename from lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/sdsnansumpw.c rename to lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/main.c index 36e1c1cb8e13..1a99a4a4f851 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/sdsnansumpw.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -18,7 +18,8 @@ #include "stdlib/blas/ext/base/sdsnansumpw.h" #include "stdlib/math/base/assert/is_nanf.h" -#include +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation with extended accumulation. @@ -31,19 +32,39 @@ * * - 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 X input array -* @param stride stride length -* @return output value +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value */ -float stdlib_strided_sdsnansumpw( const int64_t N, const float *X, const int64_t stride ) { - float *xp1; - float *xp2; +float API_SUFFIX(stdlib_strided_sdsnansumpw)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and 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 X input array +* @param strideX stride length +* @param offsetX starting index +* @return output value +*/ +float API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( const CBLAS_INT N, 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; - int64_t ix; - int64_t M; - int64_t n; - int64_t i; double s0; double s1; double s2; @@ -56,16 +77,12 @@ float stdlib_strided_sdsnansumpw( const int64_t N, const float *X, const int64_t if ( N <= 0 ) { return 0.0f; } - if ( N == 1 || stride == 0 ) { - if ( stdlib_base_is_nanf( X[ 0 ] ) ) { + ix = offsetX; + if ( strideX == 0 ) { + if ( stdlib_base_is_nanf( X[ ix ] ) ) { return 0.0f; } - return X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; + return N * X[ ix ]; } if ( N < 8 ) { // Use simple summation... @@ -74,7 +91,7 @@ float stdlib_strided_sdsnansumpw( const int64_t N, const float *X, const int64_t if ( !stdlib_base_is_nanf( X[ ix ] ) ) { sum += X[ ix ]; } - ix += stride; + ix += strideX; } return sum; } @@ -82,62 +99,55 @@ float stdlib_strided_sdsnansumpw( const int64_t N, const float *X, const int64_t if ( N <= 128 ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s1 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s2 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s3 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s4 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s5 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s6 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s7 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s1 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s2 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s3 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s4 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s5 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s6 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s7 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; } // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + sum = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) ); // Clean-up loop... for (; i < N; i++ ) { if ( !stdlib_base_is_nanf( X[ ix ] ) ) { sum += X[ ix ]; } - ix += stride; + ix += strideX; } 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_sdsnansumpw( n, xp1, stride ) + stdlib_strided_sdsnansumpw( N-n, xp2, stride ); + return API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( n, X, strideX, ix ) + API_SUFFIX(stdlib_strided_sdsnansumpw_ndarray)( N-n, X, strideX, ix+(n*strideX) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.js index 3f57975740c1..fb6f7c7f2589 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.js @@ -178,14 +178,26 @@ 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', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsnansumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns 0.0', function test( t ) { + var x; + var v; + + x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = sdsnansumpw( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.native.js index 7eac585c845c..0510b5193f98 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.ndarray.native.js @@ -187,14 +187,26 @@ 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', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element 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 = sdsnansumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns 0.0', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = sdsnansumpw( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.js index 5e239e94d2d4..dc4754beac79 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.js @@ -178,14 +178,26 @@ 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', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = sdsnansumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns 0.0', function test( t ) { + var x; + var v; + + x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = sdsnansumpw( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.native.js index f20111e16b0f..92ec0341b1b4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sdsnansumpw/test/test.sdsnansumpw.native.js @@ -269,14 +269,26 @@ 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', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element 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 = sdsnansumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns 0.0', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = sdsnansumpw( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); });