diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md
index befddaa0ee67..78f29e0909ff 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md
@@ -36,7 +36,7 @@ limitations under the License.
var snansumkbn2 = require( '@stdlib/blas/ext/base/snansumkbn2' );
```
-#### snansumkbn2( N, x, stride )
+#### snansumkbn2( N, x, strideX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm.
@@ -45,7 +45,7 @@ var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
-var v = snansumkbn2( 4, x, 1 );
+var v = snansumkbn2( x.length, x, 1 );
// returns 1.0
```
@@ -53,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' );
@@ -80,7 +80,7 @@ var v = snansumkbn2( 4, x1, 2 );
// returns 5.0
```
-#### snansumkbn2.ndarray( N, x, stride, offset )
+#### snansumkbn2.ndarray( N, x, strideX, offsetX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
@@ -89,15 +89,15 @@ var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
-var v = snansumkbn2.ndarray( 4, x, 1, 0 );
+var v = snansumkbn2.ndarray( x.length, x, 1, 0 );
// returns 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' );
@@ -135,7 +135,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var snansumkbn2 = require( '@stdlib/blas/ext/base/snansumkbn2' );
function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
+ if ( bernoulli( 0.5 ) < 1 ) {
return discreteUniform( 0, 100 );
}
return NaN;
@@ -152,8 +152,123 @@ console.log( v );
+
+
* * *
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/snansumkbn2.h"
+```
+
+#### stdlib_strided_snansumkbn2( N, \*X, strideX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm.
+
+```c
+const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 4.0f };
+
+float v = stdlib_strided_snansumkbn2( 4, x, 1 );
+// returns 7.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_snansumkbn2( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
+```
+
+#### stdlib_strided_snansumkbn2_ndarray( N, \*X, strideX, offsetX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
+
+```c
+const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 4.0f };
+
+float v = stdlib_strided_snansumkbn2_ndarray( 4, x, 1, 0 );
+// returns 7.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_snansumkbn2_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/snansumkbn2.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_snansumkbn2( N, x, strideX );
+
+ // Print the result:
+ printf( "Sum: %f\n", v );
+}
+```
+
+
+
+
+
+
+
+
+
## References
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js
index 6f9a72b5f9f1..528ccacd2865 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js
@@ -32,6 +32,19 @@ var snansumkbn2 = require( './../lib/snansumkbn2.js' );
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.5 ) < 1 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -43,13 +56,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;
- function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
- return uniform( -10.0, 10.0 );
- }
- return NaN;
- }
-
function benchmark( b ) {
var v;
var i;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js
index 96130fbe2fa0..a522eb97bac1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js
@@ -41,6 +41,19 @@ var opts = {
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.5 ) < 1 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -52,13 +65,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;
- function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
- return uniform( -10.0, 10.0 );
- }
- return NaN;
- }
-
function benchmark( b ) {
var v;
var i;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js
index 081da3439465..52883c683098 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js
@@ -32,6 +32,19 @@ var snansumkbn2 = require( './../lib/ndarray.js' );
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.5 ) < 1 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -43,13 +56,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;
- function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
- return uniform( -10.0, 10.0 );
- }
- return NaN;
- }
-
function benchmark( b ) {
var v;
var i;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js
index f9a68f2913cb..358750f6681a 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js
@@ -41,6 +41,19 @@ var opts = {
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.5 ) < 1 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -52,13 +65,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;
- function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
- return uniform( -10.0, 10.0 );
- }
- return NaN;
- }
-
function benchmark( b ) {
var v;
var i;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/c/benchmark.length.c
index c41cbffea914..b3da1fcb1217 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/c/benchmark.length.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/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_snansumkbn2( 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_snansumkbn2_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/snansumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt
index d89d34da5c74..17cf28496f9a 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt
@@ -1,5 +1,5 @@
-{{alias}}( N, x, stride )
+{{alias}}( N, x, strideX )
Computes the sum of single-precision floating-point strided array elements,
ignoring `NaN` values and using a second-order iterative Kahan–Babuška
algorithm.
@@ -7,8 +7,8 @@
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.
+ Indexing is relative to the first index. To introduce an offset, use a typed
+ array view.
If `N <= 0`, the function returns `0.0`.
@@ -20,8 +20,8 @@
x: Float32Array
Input array.
- stride: integer
- Index increment.
+ strideX: integer
+ Stride length.
Returns
-------
@@ -37,26 +37,24 @@
// 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 ] );
- > var stride = 2;
- > {{alias}}( 4, x, stride )
+ > {{alias}}( 4, x, 2 )
1.0
// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] );
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
- > stride = 2;
- > {{alias}}( 4, x1, stride )
+ > {{alias}}( 4, x1, 2 )
-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 a second-order iterative Kahan–Babuška
algorithm 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
----------
@@ -66,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/snansumkbn2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/types/index.d.ts
index a88c3aec52c7..dd6e15dcb624 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/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 = snansumkbn2( 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 a second-order iterative Kahan–Babuška algorithm 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 = snansumkbn2.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/snansumkbn2/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/c/example.c
index be66dd955789..45bbc2336268 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/c/example.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/c/example.c
@@ -17,22 +17,21 @@
*/
#include "stdlib/blas/ext/base/snansumkbn2.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_snansumkbn2( N, x, stride );
+ float v = stdlib_strided_snansumkbn2( 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/snansumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js
index 217c933a1cf9..fa4205b2f3dd 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js
@@ -24,7 +24,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var snansumkbn2 = require( './../lib' );
function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
+ if ( bernoulli( 0.5 ) < 1 ) {
return discreteUniform( 0, 100 );
}
return NaN;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include/stdlib/blas/ext/base/snansumkbn2.h b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include/stdlib/blas/ext/base/snansumkbn2.h
index b1da1cb8308e..89437e913fb8 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include/stdlib/blas/ext/base/snansumkbn2.h
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include/stdlib/blas/ext/base/snansumkbn2.h
@@ -19,7 +19,7 @@
#ifndef STDLIB_BLAS_EXT_BASE_SNANSUMKBN2_H
#define STDLIB_BLAS_EXT_BASE_SNANSUMKBN2_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" {
/**
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm.
*/
-float stdlib_strided_snansumkbn2( const int64_t N, const float *X, const int64_t stride );
+float API_SUFFIX(stdlib_strided_snansumkbn2)( 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 a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
+*/
+float API_SUFFIX(stdlib_strided_snansumkbn2_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/snansumkbn2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.js
index d81a5ac8e93f..9435d4cb6a63 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.js
@@ -22,7 +22,7 @@
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
-var abs = require( '@stdlib/math/base/special/abs' );
+var absf = require( '@stdlib/math/base/special/absf' );
// MAIN //
@@ -40,8 +40,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @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
@@ -52,7 +52,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
* var v = snansumkbn2( 5, x, 2, 1 );
* // returns 5.0
*/
-function snansumkbn2( N, x, stride, offset ) {
+function snansumkbn2( N, x, strideX, offsetX ) {
var sum;
var ccs;
var ix;
@@ -66,13 +66,13 @@ function snansumkbn2( 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;
sum = 0.0;
ccs = 0.0; // second order correction term for lost low order bits
cs = 0.0; // first order correction term for lost low order bits
@@ -80,22 +80,22 @@ function snansumkbn2( N, x, stride, offset ) {
v = x[ ix ];
if ( isnanf( v ) === false ) {
t = float64ToFloat32( sum + v );
- if ( abs( sum ) >= abs( v ) ) {
+ if ( absf( sum ) >= absf( v ) ) {
c = float64ToFloat32( float64ToFloat32( sum-t ) + v );
} else {
c = float64ToFloat32( float64ToFloat32( v-t ) + sum );
}
sum = t;
t = float64ToFloat32( cs + c );
- if ( abs( cs ) >= abs( c ) ) {
- cc = float64ToFloat32( float64ToFloat32(cs-t) + c );
+ if ( absf( cs ) >= absf( c ) ) {
+ cc = float64ToFloat32( float64ToFloat32( cs-t ) + c );
} else {
- cc = float64ToFloat32( float64ToFloat32(c-t) + cs );
+ cc = float64ToFloat32( float64ToFloat32( c-t ) + cs );
}
cs = t;
ccs = float64ToFloat32( ccs + cc );
}
- ix += stride;
+ ix += strideX;
}
return float64ToFloat32( sum + float64ToFloat32( cs + ccs ) );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.native.js
index 4d25fbd11d41..7414ee62ccbb 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/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( './snansumkbn2.native.js' );
+var addon = require( './../src/addon.node' );
// MAIN //
@@ -32,8 +30,8 @@ var addon = require( './snansumkbn2.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
@@ -44,11 +42,8 @@ var addon = require( './snansumkbn2.native.js' );
* var v = snansumkbn2( 5, x, 2, 1 );
* // returns 5.0
*/
-function snansumkbn2( N, x, stride, offset ) {
- var view;
- offset = minViewBufferIndex( N, stride, offset );
- view = offsetView( x, offset );
- return addon( N, view, stride );
+function snansumkbn2( N, x, strideX, offsetX ) {
+ return addon.ndarray( N, x, strideX, offsetX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.js
index ed411023d91b..8267f376151c 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.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 abs = require( '@stdlib/math/base/special/abs' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
+var ndarray = require( './ndarray.js' );
// MAIN //
@@ -40,7 +39,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @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
@@ -48,59 +47,11 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
*
-* var v = snansumkbn2( 4, x, 1 );
+* var v = snansumkbn2( x.length, x, 1 );
* // returns 1.0
*/
-function snansumkbn2( N, x, stride ) {
- var sum;
- var ccs;
- var ix;
- var cs;
- var cc;
- var v;
- var t;
- var c;
- 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;
- }
- sum = 0.0;
- ccs = 0.0; // second order correction term for lost low order bits
- cs = 0.0; // first order correction term for lost low order bits
- for ( i = 0; i < N; i++ ) {
- v = x[ ix ];
- if ( isnanf( v ) === false ) {
- t = float64ToFloat32( sum + v );
- if ( abs( sum ) >= abs( v ) ) {
- c = float64ToFloat32( float64ToFloat32( sum-t ) + v );
- } else {
- c = float64ToFloat32( float64ToFloat32( v-t ) + sum );
- }
- sum = t;
- t = float64ToFloat32( cs + c );
- if ( abs( cs ) >= abs( c ) ) {
- cc = float64ToFloat32( float64ToFloat32(cs-t) + c );
- } else {
- cc = float64ToFloat32( float64ToFloat32(c-t) + cs );
- }
- cs = t;
- ccs = float64ToFloat32( ccs + cc );
- }
- ix += stride;
- }
- return float64ToFloat32( sum + float64ToFloat32( cs + ccs ) );
+function snansumkbn2( N, x, strideX ) {
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.native.js
index 351a30d924e5..7c877493f755 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/lib/snansumkbn2.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
@@ -38,11 +38,11 @@ var addon = require( './../src/addon.node' );
*
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
*
-* var v = snansumkbn2( 4, x, 1 );
+* var v = snansumkbn2( x.length, x, 1 );
* // returns 1.0
*/
-function snansumkbn2( N, x, stride ) {
- return addon( N, x, stride );
+function snansumkbn2( N, x, strideX ) {
+ return addon( N, x, strideX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/manifest.json
index 5b4023513376..7e6bbbd2753f 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/manifest.json
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/manifest.json
@@ -28,53 +28,57 @@
{
"task": "build",
"src": [
- "./src/snansumkbn2.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nanf",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
- "@stdlib/napi/argv-strided-float32array"
+ "@stdlib/napi/argv-strided-float32array",
+ "@stdlib/napi/create-double",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
]
},
{
"task": "benchmark",
"src": [
- "./src/snansumkbn2.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nanf"
+ "@stdlib/math/base/assert/is-nanf",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
]
},
{
"task": "examples",
"src": [
- "./src/snansumkbn2.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nanf"
+ "@stdlib/math/base/assert/is-nanf",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
]
}
]
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.c
index bfc22e76e834..6aa667c54c55 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.c
@@ -17,12 +17,13 @@
*/
#include "stdlib/blas/ext/base/snansumkbn2.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, stdlib_strided_snansumkbn2( 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_snansumkbn2)( 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_snansumkbn2_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/snansumkbn2/src/snansumkbn2.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/main.c
similarity index 51%
rename from lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/snansumkbn2.c
rename to lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/main.c
index e8b3d0fa5aae..91c88290fc12 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/snansumkbn2.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/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,8 +18,9 @@
#include "stdlib/blas/ext/base/snansumkbn2.h"
#include "stdlib/math/base/assert/is_nanf.h"
-#include
-#include
+#include "stdlib/strided/base/stride2offset.h"
+#include "stdlib/math/base/special/absf.h"
+#include "stdlib/blas/base/shared.h"
/**
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm.
@@ -32,14 +33,36 @@
*
* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x).
*
-* @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_snansumkbn2( const int64_t N, const float *X, const int64_t stride ) {
- int64_t ix;
- int64_t i;
+float API_SUFFIX(stdlib_strided_snansumkbn2)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
+ return API_SUFFIX(stdlib_strided_snansumkbn2_ndarray)( N, X, strideX, ox );
+}
+
+/**
+* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
+*
+* ## Method
+*
+* - This implementation uses a second-order iterative Kahan–Babuška algorithm, as described by Klein (2005).
+*
+* ## References
+*
+* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x).
+*
+* @param N number of indexed elements
+* @param X input array
+* @param strideX stride length
+* @param offsetX stride length
+* @return output value
+*/
+float API_SUFFIX(stdlib_strided_snansumkbn2_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
+ CBLAS_INT ix;
+ CBLAS_INT i;
float sum;
float ccs;
float cs;
@@ -52,16 +75,12 @@ float stdlib_strided_snansumkbn2( const int64_t N, const float *X, const int64_t
if ( N <= 0 ) {
return sum;
}
- 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 sum;
}
- return X[ 0 ];
- }
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
+ return N * X[ ix ];
}
ccs = 0.0f; // second order correction term for lost lower order bits
cs = 0.0f; // first order correction term for lost low order bits
@@ -69,14 +88,14 @@ float stdlib_strided_snansumkbn2( const int64_t N, const float *X, const int64_t
v = X[ ix ];
if ( !stdlib_base_is_nanf( v ) ) {
t = sum + v;
- if ( fabsf( sum ) >= fabsf( v ) ) {
+ if ( stdlib_base_absf( sum ) >= stdlib_base_absf( v ) ) {
c = (sum-t) + v;
} else {
c = (v-t) + sum;
}
sum = t;
t = cs + c;
- if ( fabsf( cs ) >= fabsf( c ) ) {
+ if ( stdlib_base_absf( cs ) >= stdlib_base_absf( c ) ) {
cc = (cs-t) + c;
} else {
cc = (c-t) + cs;
@@ -84,7 +103,7 @@ float stdlib_strided_snansumkbn2( const int64_t N, const float *X, const int64_t
cs = t;
ccs += cc;
}
- ix += stride;
+ ix += strideX;
}
return sum + cs + ccs;
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js
index add8a34c679f..c74493e723a1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js
@@ -150,14 +150,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 = snansumkbn2( 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', function test( t ) {
+ var x;
+ var v;
+
+ x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] );
+
+ v = snansumkbn2( 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/snansumkbn2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js
index 37d36862f1e8..656b1e6123c8 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js
@@ -159,14 +159,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 = snansumkbn2( 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', opts, function test( t ) {
+ var x;
+ var v;
+
+ x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] );
+
+ v = snansumkbn2( 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/snansumkbn2/test/test.snansumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js
index 757d4f4680d0..37d5d6cede8d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js
@@ -150,14 +150,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 = snansumkbn2( 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', function test( t ) {
+ var x;
+ var v;
+
+ x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] );
+
+ v = snansumkbn2( x.length, x, 0 );
+ t.strictEqual( v, 0.0, 'returns expected value' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js
index d04b0c4fc2d0..6457806eb7d8 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js
@@ -241,14 +241,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 = snansumkbn2( 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', opts, function test( t ) {
+ var x;
+ var v;
+
+ x = new Float32Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] );
+
+ v = snansumkbn2( x.length, x, 0 );
+ t.strictEqual( v, 0.0, 'returns expected value' );
t.end();
});