diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/README.md
index 0a18eb319242..72adc940aa20 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/README.md
@@ -36,7 +36,7 @@ limitations under the License.
var dnansumkbn = require( '@stdlib/blas/ext/base/dnansumkbn' );
```
-#### dnansumkbn( N, x, stride )
+#### dnansumkbn( N, x, strideX )
Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
@@ -45,7 +45,7 @@ var Float64Array = require( '@stdlib/array/float64' );
var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
-var v = dnansumkbn( 4, x, 1 );
+var v = dnansumkbn( x.length, x, 1 );
// returns 1.0
```
@@ -53,7 +53,7 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **x**: input [`Float64Array`][@stdlib/array/float64].
-- **stride**: index increment for `x`.
+- **strideX**: stride length for `x`.
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the sum of every other element in `x`,
@@ -80,7 +80,7 @@ var v = dnansumkbn( 4, x1, 2 );
// returns 5.0
```
-#### dnansumkbn.ndarray( N, x, stride, offset )
+#### dnansumkbn.ndarray( N, x, strideX, offsetX )
Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
@@ -89,15 +89,15 @@ var Float64Array = require( '@stdlib/array/float64' );
var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
-var v = dnansumkbn.ndarray( 4, x, 1, 0 );
+var v = dnansumkbn.ndarray( x.length, x, 1, 0 );
// returns 1.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 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 Float64Array = require( '@stdlib/array/float64' );
@@ -152,8 +152,123 @@ console.log( v );
+
+
* * *
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/dnansumkbn.h"
+```
+
+#### stdlib_strided_dnansumkbn( N, \*X, strideX )
+
+Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
+
+```c
+const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 };
+
+double v = stdlib_strided_dnansumkbn( 4, x, 1 );
+// returns 7.0
+```
+
+The function accepts the following arguments:
+
+- **N**: `[in] CBLAS_INT` number of indexed elements.
+- **X**: `[in] double*` input array.
+- **strideX**: `[in] CBLAS_INT` stride length for `X`.
+
+```c
+double stdlib_strided_dnansumkbn( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
+```
+
+#### stdlib_strided_dnansumkbn_ndarray( N, \*X, strideX, offsetX )
+
+Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
+
+```c
+const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 };
+
+double v = stdlib_strided_dnansumkbn_ndarray( 4, x, 1, 0 );
+// returns 7.0
+```
+
+The function accepts the following arguments:
+
+- **N**: `[in] CBLAS_INT` number of indexed elements.
+- **X**: `[in] double*` input array.
+- **strideX**: `[in] CBLAS_INT` stride length for `X`.
+- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
+
+```c
+double stdlib_strided_dnansumkbn_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/dnansumkbn.h"
+#include
+
+int main( void ) {
+ // Create a strided array:
+ const double 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 };
+
+ // Specify the number of elements:
+ const int N = 5;
+
+ // Specify the stride length:
+ const int strideX = 2;
+
+ // Compute the sum:
+ double v = stdlib_strided_dnansumkbn( N, x, strideX );
+
+ // Print the result:
+ printf( "sum: %lf\n", v );
+}
+```
+
+
+
+
+
+
+
+
+
## References
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.js
index 6cd1f2cb7e34..a4b6e291787a 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.js
@@ -32,6 +32,19 @@ var dnansumkbn = require( './../lib/dnansumkbn.js' );
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) > 0 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -40,16 +53,9 @@ var dnansumkbn = require( './../lib/dnansumkbn.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x = filledarrayBy( len, 'float64', clbk );
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
- function clbk() {
- if ( bernoulli( 0.7 ) > 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/dnansumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.native.js
index add1384cbcfb..9c5c18dc85a0 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/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.8 ) > 0 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -49,16 +62,9 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x = filledarrayBy( len, 'float64', clbk );
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
- function clbk() {
- if ( bernoulli( 0.7 ) > 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/dnansumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.ndarray.js
index 9ca0964241c3..bd56fa57ca68 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.ndarray.js
@@ -32,6 +32,19 @@ var dnansumkbn = require( './../lib/ndarray.js' );
// FUNCTIONS //
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) > 0 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -40,16 +53,9 @@ var dnansumkbn = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x = filledarrayBy( len, 'float64', clbk );
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
- function clbk() {
- if ( bernoulli( 0.7 ) > 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/dnansumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.ndarray.native.js
index a94480e508c1..c759f63b47be 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/benchmark.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/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.8 ) > 0 ) {
+ return uniform( -10.0, 10.0 );
+ }
+ return NaN;
+}
+
/**
* Creates a benchmark function.
*
@@ -49,16 +62,9 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x = filledarrayBy( len, 'float64', clbk );
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
- function clbk() {
- if ( bernoulli( 0.7 ) > 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/dnansumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/c/benchmark.length.c
index f20739042d5a..e1c58649eb81 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/c/benchmark.length.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/benchmark/c/benchmark.length.c
@@ -94,7 +94,7 @@ static double rand_double( 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;
double x[ len ];
double v;
@@ -124,6 +124,43 @@ 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;
+ double x[ len ];
+ double v;
+ double t;
+ int i;
+
+ for ( i = 0; i < len; i++ ) {
+ if ( rand_double() < 0.2 ) {
+ x[ i ] = 0.0 / 0.0; // NaN
+ } else {
+ x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
+ }
+ }
+ v = 0.0;
+ t = tic();
+ for ( i = 0; i < iterations; i++ ) {
+ v = stdlib_strided_dnansumkbn_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 +183,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/dnansumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/docs/repl.txt
index a396def0a9c4..22d6062c4cef 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/docs/repl.txt
@@ -1,9 +1,9 @@
-{{alias}}( N, x, stride )
+{{alias}}( N, x, strideX )
Computes the sum of double-precision floating-point strided array elements,
ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
- The `N` and stride parameters determine which elements in the strided
+ 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
@@ -19,8 +19,8 @@
x: Float64Array
Input array.
- stride: integer
- Index increment.
+ strideX: integer
+ Stride length.
Returns
-------
@@ -34,7 +34,7 @@
> {{alias}}( x.length, x, 1 )
1.0
- // Using `N` and `stride` parameters:
+ // Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] );
> {{alias}}( 4, x, 2 )
1.0
@@ -46,13 +46,13 @@
-1.0
-{{alias}}.ndarray( N, x, stride, offset )
+{{alias}}.ndarray( N, x, strideX, offsetX )
Computes the sum of double-precision floating-point strided array elements,
ignoring `NaN` values and using an improved 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
+ buffer, the offset parameter supports indexing semantics based on a
starting index.
Parameters
@@ -63,10 +63,10 @@
x: Float64Array
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/dnansumkbn/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/docs/types/index.d.ts
index 5763eb66a357..af4932a4e128 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/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 = dnansumkbn( x.length, x, 1 );
* // returns 1.0
*/
- ( N: number, x: Float64Array, stride: number ): number;
+ ( N: number, x: Float64Array, strideX: number ): number;
/**
* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved 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 = dnansumkbn.ndarray( x.length, x, 1, 0 );
* // returns 1.0
*/
- ndarray( N: number, x: Float64Array, stride: number, offset: number ): number;
+ ndarray( N: number, x: Float64Array, 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/dnansumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/examples/c/example.c
index b94fa418f033..7eb2b084577d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/examples/c/example.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/examples/c/example.c
@@ -17,7 +17,6 @@
*/
#include "stdlib/blas/ext/base/dnansumkbn.h"
-#include
#include
int main( void ) {
@@ -25,13 +24,13 @@ int main( void ) {
const double 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 };
// 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:
- double v = stdlib_strided_dnansumkbn( N, x, stride );
+ double v = stdlib_strided_dnansumkbn( N, x, strideX );
// Print the result:
printf( "sum: %lf\n", v );
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/include/stdlib/blas/ext/base/dnansumkbn.h b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/include/stdlib/blas/ext/base/dnansumkbn.h
index 2f243eda59fb..54aa8b84b3fa 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/include/stdlib/blas/ext/base/dnansumkbn.h
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/include/stdlib/blas/ext/base/dnansumkbn.h
@@ -19,7 +19,7 @@
#ifndef STDLIB_BLAS_EXT_BASE_DNANSUMKBN_H
#define STDLIB_BLAS_EXT_BASE_DNANSUMKBN_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 double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
*/
-double stdlib_strided_dnansumkbn( const int64_t N, const double *X, const int64_t stride );
+double API_SUFFIX(stdlib_strided_dnansumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
+
+/**
+* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
+*/
+double API_SUFFIX(stdlib_strided_dnansumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
#ifdef __cplusplus
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.js
index 9f1d7660cca5..ef7e98a9da8b 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.js
@@ -20,8 +20,8 @@
// MODULES //
-var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var abs = require( '@stdlib/math/base/special/abs' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
+var ndarray = require( './ndarray.js' );
// MAIN //
@@ -39,56 +39,19 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} x - input array
-* @param {integer} stride - stride length
+* @param {integer} strideX - stride length
* @returns {number} sum
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
-* var N = x.length;
*
-* var v = dnansumkbn( N, x, 1 );
+* var v = dnansumkbn( x.length, x, 1 );
* // returns 1.0
*/
-function dnansumkbn( N, x, stride ) {
- var sum;
- var ix;
- var v;
- var t;
- var c;
- var i;
-
- if ( N <= 0 ) {
- return 0.0;
- }
- if ( N === 1 || stride === 0 ) {
- if ( isnan( x[ 0 ] ) ) {
- return 0.0;
- }
- return x[ 0 ];
- }
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
- }
- sum = 0.0;
- c = 0.0;
- for ( i = 0; i < N; i++ ) {
- v = x[ ix ];
- if ( isnan( v ) === false ) {
- t = sum + v;
- if ( abs( sum ) >= abs( v ) ) {
- c += (sum-t) + v;
- } else {
- c += (v-t) + sum;
- }
- sum = t;
- }
- ix += stride;
- }
- return sum + c;
+function dnansumkbn( N, x, strideX ) {
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.native.js
index 2ed47f9e56d2..fec1b1cadc16 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/dnansumkbn.native.js
@@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} x - input array
-* @param {integer} stride - stride length
+* @param {integer} strideX - stride length
* @returns {number} sum
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
-* var N = x.length;
*
-* var v = dnansumkbn( N, x, 1 );
+* var v = dnansumkbn( x.length, x, 1 );
* // returns 1.0
*/
-function dnansumkbn( N, x, stride ) {
- return addon( N, x, stride );
+function dnansumkbn( N, x, strideX ) {
+ return addon( N, x, strideX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.js
index 4d3efb663492..bc54ab5d5f84 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.js
@@ -39,8 +39,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} 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
@@ -51,7 +51,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
* var v = dnansumkbn( 5, x, 2, 1 );
* // returns 5.0
*/
-function dnansumkbn( N, x, stride, offset ) {
+function dnansumkbn( N, x, strideX, offsetX ) {
var sum;
var ix;
var v;
@@ -59,17 +59,17 @@ function dnansumkbn( N, x, stride, offset ) {
var c;
var i;
+ sum = 0.0;
if ( N <= 0 ) {
- return 0.0;
+ return sum;
}
- if ( N === 1 || stride === 0 ) {
- if ( isnan( x[ offset ] ) ) {
- return 0.0;
+ ix = offsetX;
+ if ( strideX === 0 ) {
+ if ( isnan( x[ ix ] ) ) {
+ return sum;
}
- return x[ offset ];
+ return x[ ix ] * N;
}
- ix = offset;
- sum = 0.0;
c = 0.0;
for ( i = 0; i < N; i++ ) {
v = x[ ix ];
@@ -82,7 +82,7 @@ function dnansumkbn( N, x, stride, offset ) {
}
sum = t;
}
- ix += stride;
+ ix += strideX;
}
return sum + c;
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.native.js
index 2ac51742d3df..13b19ae6edde 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/lib/ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/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( './dnansumkbn.native.js' );
+var addon = require( './../src/addon.node' );
// MAIN //
@@ -32,8 +30,8 @@ var addon = require( './dnansumkbn.native.js' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} 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,14 +42,8 @@ var addon = require( './dnansumkbn.native.js' );
* var v = dnansumkbn( 5, x, 2, 1 );
* // returns 5.0
*/
-function dnansumkbn( N, x, stride, offset ) {
- var view;
-
- offset = minViewBufferIndex( N, stride, offset );
-
- view = offsetView( x, offset );
-
- return addon( N, view, stride );
+function dnansumkbn( N, x, strideX, offsetX ) {
+ return addon.ndarray( N, x, strideX, offsetX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/manifest.json
index 095e73f25f3b..57e9af5c51e3 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/manifest.json
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/manifest.json
@@ -28,53 +28,57 @@
{
"task": "build",
"src": [
- "./src/dnansumkbn.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
- "@stdlib/napi/argv-strided-float64array"
+ "@stdlib/napi/argv-strided-float64array",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/napi/create-double"
]
},
{
"task": "benchmark",
"src": [
- "./src/dnansumkbn.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nan"
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/blas/base/shared",
+ "@stdlib/strided/base/stride2offset"
]
},
{
"task": "examples",
"src": [
- "./src/dnansumkbn.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nan"
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/special/abs",
+ "@stdlib/blas/base/shared",
+ "@stdlib/strided/base/stride2offset"
]
}
]
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/addon.c
index f5ada0bfd11d..0297f1f38ccd 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/addon.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/addon.c
@@ -17,12 +17,13 @@
*/
#include "stdlib/blas/ext/base/dnansumkbn.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_float64array.h"
+#include "stdlib/napi/create_double.h"
#include
-#include
/**
* Receives JavaScript callback invocation data.
@@ -32,16 +33,29 @@
* @return Node-API value
*/
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_FLOAT64ARRAY( env, X, N, stride, argv, 1 );
-
- napi_value v;
- napi_status status = napi_create_double( env, stdlib_strided_dnansumkbn( N, X, stride ), &v );
- assert( status == napi_ok );
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansumkbn)( N, X, strideX ), v );
+ return 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_FLOAT64ARRAY( env, X, N, strideX, argv, 1 );
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansumkbn_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/dnansumkbn/src/dnansumkbn.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/dnansumkbn.c
deleted file mode 100644
index 9821d1fb6304..000000000000
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/dnansumkbn.c
+++ /dev/null
@@ -1,78 +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/dnansumkbn.h"
-#include "stdlib/math/base/assert/is_nan.h"
-#include
-#include
-
-/**
-* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
-*
-* ## Method
-*
-* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974).
-*
-* ## References
-*
-* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
-*
-* @param N number of indexed elements
-* @param X input array
-* @param stride stride length
-* @return output value
-*/
-double stdlib_strided_dnansumkbn( const int64_t N, const double *X, const int64_t stride ) {
- double sum;
- int64_t ix;
- int64_t i;
- double v;
- double t;
- double c;
-
- if ( N <= 0 ) {
- return 0.0;
- }
- if ( N == 1 || stride == 0 ) {
- if ( stdlib_base_is_nan( X[ 0 ] ) ) {
- return 0.0;
- }
- return X[ 0 ];
- }
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
- }
- sum = 0.0;
- c = 0.0;
- for ( i = 0; i < N; i++ ) {
- v = X[ ix ];
- if ( !stdlib_base_is_nan( v ) ) {
- t = sum + v;
- if ( fabs( sum ) >= fabs( v ) ) {
- c += (sum-t) + v;
- } else {
- c += (v-t) + sum;
- }
- sum = t;
- }
- ix += stride;
- }
- return sum + c;
-}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/main.c
new file mode 100644
index 000000000000..1e2bc61399b8
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/src/main.c
@@ -0,0 +1,97 @@
+/**
+* @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/dnansumkbn.h"
+#include "stdlib/strided/base/stride2offset.h"
+#include "stdlib/math/base/assert/is_nan.h"
+#include "stdlib/math/base/special/abs.h"
+#include "stdlib/blas/base/shared.h"
+
+/**
+* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
+*
+* ## Method
+*
+* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974).
+*
+* ## References
+*
+* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
+*
+* @param N number of indexed elements
+* @param X input array
+* @param strideX stride length
+* @return output value
+*/
+double API_SUFFIX(stdlib_strided_dnansumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) {
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
+ return API_SUFFIX(stdlib_strided_dnansumkbn_ndarray)( N, X, strideX, ox );
+}
+
+/**
+* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
+*
+* ## Method
+*
+* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974).
+*
+* ## References
+*
+* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
+*
+* @param N number of indexed elements
+* @param X input array
+* @param strideX stride length
+* @param offsetX starting index
+* @return output value
+*/
+double API_SUFFIX(stdlib_strided_dnansumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
+ double sum;
+ CBLAS_INT ix;
+ CBLAS_INT i;
+ double v;
+ double t;
+ double c;
+
+ sum = 0.0;
+ if ( N <= 0 ) {
+ return sum;
+ }
+ ix = offsetX;
+ if ( strideX == 0 ) {
+ if ( stdlib_base_is_nan( X[ ix ] ) ) {
+ return sum;
+ }
+ return X[ ix ] * N;
+ }
+ c = 0.0;
+ for ( i = 0; i < N; i++ ) {
+ v = X[ ix ];
+ if ( !stdlib_base_is_nan( v ) ) {
+ t = sum + v;
+ if ( stdlib_base_abs( sum ) >= stdlib_base_abs( v ) ) {
+ c += (sum-t) + v;
+ } else {
+ c += (v-t) + sum;
+ }
+ sum = t;
+ }
+ ix += strideX;
+ }
+ return sum + c;
+}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.js
index e538d9c967ce..787847da5a38 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.js
@@ -150,14 +150,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', 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 Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
v = dnansumkbn( x.length, x, 0 );
- t.strictEqual( v, 1.0, 'returns expected value' );
+ t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.native.js
index f2f3f5d1db25..a50c347c3510 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.dnansumkbn.native.js
@@ -241,14 +241,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', 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 Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
v = dnansumkbn( x.length, x, 0 );
- t.strictEqual( v, 1.0, 'returns expected value' );
+ t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.js
index abda894269df..021dbcf0e93b 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.js
@@ -150,14 +150,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', 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 Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
v = dnansumkbn( x.length, x, 0, 0 );
- t.strictEqual( v, 1.0, 'returns expected value' );
+ t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.native.js
index ae940922013c..4bcafdbdb009 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumkbn/test/test.ndarray.native.js
@@ -159,14 +159,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', 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 Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
v = dnansumkbn( x.length, x, 0, 0 );
- t.strictEqual( v, 1.0, 'returns expected value' );
+ t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});