From 981daf878cb47931246b97c1734924cf04338370 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Tue, 21 Jan 2025 09:05:46 +0000
Subject: [PATCH 1/4] feat: add C ndarray API and refactor
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: na
- task: lint_repl_help
status: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: missing_dependencies
- task: lint_c_examples
status: missing_dependencies
- task: lint_c_benchmarks
status: missing_dependencies
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
.../blas/ext/base/snansumkbn/README.md | 132 ++++++++++++++++--
.../base/snansumkbn/benchmark/benchmark.js | 20 ++-
.../snansumkbn/benchmark/benchmark.native.js | 20 ++-
.../snansumkbn/benchmark/benchmark.ndarray.js | 20 ++-
.../benchmark/benchmark.ndarray.native.js | 20 ++-
.../snansumkbn/benchmark/c/benchmark.length.c | 54 ++++++-
.../blas/ext/base/snansumkbn/docs/repl.txt | 32 ++---
.../ext/base/snansumkbn/docs/types/index.d.ts | 12 +-
.../ext/base/snansumkbn/examples/c/example.c | 11 +-
.../ext/base/snansumkbn/examples/index.js | 2 +-
.../include/stdlib/blas/ext/base/snansumkbn.h | 9 +-
.../blas/ext/base/snansumkbn/lib/ndarray.js | 20 +--
.../ext/base/snansumkbn/lib/ndarray.native.js | 15 +-
.../ext/base/snansumkbn/lib/snansumkbn.js | 50 +------
.../base/snansumkbn/lib/snansumkbn.native.js | 9 +-
.../blas/ext/base/snansumkbn/manifest.json | 34 +++--
.../blas/ext/base/snansumkbn/src/addon.c | 30 ++--
.../blas/ext/base/snansumkbn/src/main.c | 97 +++++++++++++
.../blas/ext/base/snansumkbn/src/snansumkbn.c | 78 -----------
.../ext/base/snansumkbn/test/test.ndarray.js | 16 ++-
.../snansumkbn/test/test.ndarray.native.js | 16 ++-
.../base/snansumkbn/test/test.snansumkbn.js | 16 ++-
.../snansumkbn/test/test.snansumkbn.native.js | 16 ++-
23 files changed, 480 insertions(+), 249 deletions(-)
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/snansumkbn.c
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
index 8d60e302b975..1936115c8d76 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
@@ -36,7 +36,7 @@ limitations under the License.
var snansumkbn = require( '@stdlib/blas/ext/base/snansumkbn' );
```
-#### snansumkbn( N, x, stride )
+#### snansumkbn( N, x, strideX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
@@ -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 = snansumkbn( N, x, 1 );
+var v = snansumkbn( 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`.
+- **stride**: stride length.
-The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in `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 = snansumkbn( 4, x1, 2 );
// returns 5.0
```
-#### snansumkbn.ndarray( N, x, stride, offset )
+#### snansumkbn.ndarray( N, x, strideX, offsetX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
@@ -96,9 +95,9 @@ var v = snansumkbn.ndarray( 4, 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,7 +135,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var snansumkbn = require( '@stdlib/blas/ext/base/snansumkbn' );
function rand() {
- if ( bernoulli( 0.8 ) > 0 ) {
+ if ( bernoulli( 0.5 ) < 1 ) {
return discreteUniform( 0, 100 );
}
return NaN;
@@ -153,8 +152,123 @@ console.log( v );
+
+
* * *
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/snansumkbn.h"
+```
+
+#### stdlib_strided_snansumkbn( N, \*X, strideX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
+
+```c
+const float x[] = { 1.0f, 2.0f, 0.0f/0.0f, 4.0f };
+
+float v = stdlib_strided_snansumkbn( 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_snansumkbn( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
+```
+
+#### stdlib_strided_snansumkbn_ndarray( N, \*X, strideX, offsetX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using an improved 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_snansumkbn_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_snansumkbn_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/snansumkbn.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_snansumkbn( N, x, strideX );
+
+ // Print the result:
+ printf( "Sum: %lf\n", v );
+}
+```
+
+
+
+
+
+
+
+
+
## References
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.js
index 645d25817133..959f9bafb950 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.js
@@ -32,6 +32,19 @@ var snansumkbn = require( './../lib/snansumkbn.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/snansumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.native.js
index d3e9ba6d5d40..2abffddd1faa 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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/snansumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.ndarray.js
index d3d6ab9423a4..c1695c3e99ab 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.ndarray.js
@@ -32,6 +32,19 @@ var snansumkbn = 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/snansumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.ndarray.native.js
index 9002e8f64f77..3b70ac34f1ce 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/benchmark.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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/snansumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/c/benchmark.length.c
index 3c29ab09e3ee..8b9e65efd393 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/benchmark/c/benchmark.length.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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_snansumkbn( 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_snansumkbn_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/snansumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/docs/repl.txt
index ff197b63f812..f19b98962de0 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/docs/repl.txt
@@ -1,13 +1,13 @@
-{{alias}}( N, x, stride )
+{{alias}}( N, x, strideX )
Computes the sum of single-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
- 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.
+ Indexing is relative to the first index. To introduce an offset, use a typed
+ array view.
If `N <= 0`, the function returns `0.0`.
@@ -19,8 +19,8 @@
x: Float32Array
Input array.
- stride: integer
- Index increment.
+ strideX: integer
+ Stride length.
Returns
-------
@@ -36,26 +36,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 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
- starting index.
+ buffer, the offset parameter supports indexing semantics based on a starting
+ index.
Parameters
----------
@@ -65,10 +63,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/snansumkbn/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/docs/types/index.d.ts
index f17d4c4fd861..0a193cc8b216 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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 = snansumkbn( 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 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 = snansumkbn.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/snansumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
index e9ddbaad876d..0c18142de852 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
@@ -17,22 +17,21 @@
*/
#include "stdlib/blas/ext/base/snansumkbn.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_snansumkbn( N, x, stride );
+ float v = stdlib_strided_snansumkbn( N, x, strideX );
// Print the result:
- printf( "sum: %f\n", v );
+ printf( "Sum: %lf\n", v );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/index.js
index 0ddabe33fc5c..91d4585d56f9 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/index.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/index.js
@@ -24,7 +24,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var snansumkbn = 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/snansumkbn/include/stdlib/blas/ext/base/snansumkbn.h b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/include/stdlib/blas/ext/base/snansumkbn.h
index d20d1de23e1d..bd24191b9c85 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/include/stdlib/blas/ext/base/snansumkbn.h
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/include/stdlib/blas/ext/base/snansumkbn.h
@@ -19,7 +19,7 @@
#ifndef STDLIB_BLAS_EXT_BASE_SNANSUMKBN_H
#define STDLIB_BLAS_EXT_BASE_SNANSUMKBN_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 an improved Kahan–Babuška algorithm.
*/
-float stdlib_strided_snansumkbn( const int64_t N, const float *X, const int64_t stride );
+float API_SUFFIX(stdlib_strided_snansumkbn)( 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 an improved Kahan–Babuška algorithm and alternative indexing semantics.
+*/
+float API_SUFFIX(stdlib_strided_snansumkbn_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/snansumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/ndarray.js
index d6e076ec4c58..8ac211f7bd90 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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 = snansumkbn( 5, x, 2, 1 );
* // returns 5.0
*/
-function snansumkbn( N, x, stride, offset ) {
+function snansumkbn( N, x, strideX, offsetX ) {
var sum;
var ix;
var v;
@@ -63,27 +63,27 @@ function snansumkbn( 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;
c = 0.0;
for ( i = 0; i < N; i++ ) {
v = x[ ix ];
if ( isnanf( v ) === false ) {
t = sum + v;
- if ( abs( sum ) >= abs( v ) ) {
+ if ( absf( sum ) >= absf( v ) ) {
c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( sum-t ) + v ) ); // eslint-disable-line max-len
} else {
c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( v-t ) + sum ) ); // eslint-disable-line max-len
}
sum = t;
}
- ix += stride;
+ ix += strideX;
}
return float64ToFloat32( sum + c );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/ndarray.native.js
index 0903fa7a5a9f..80a2ef0a1b61 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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( './snansumkbn.native.js' );
+var addon = require( './../src/addon.node' );
// MAIN //
@@ -32,8 +30,8 @@ var addon = require( './snansumkbn.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( './snansumkbn.native.js' );
* var v = snansumkbn( 5, x, 2, 1 );
* // returns 5.0
*/
-function snansumkbn( N, x, stride, offset ) {
- var view;
- offset = minViewBufferIndex( N, stride, offset );
- view = offsetView( x, offset );
- return addon( N, view, stride );
+function snansumkbn( N, x, strideX, offsetX ) {
+ return addon.ndarray( N, x, strideX, offsetX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.js
index 6550ccf90389..0eeb3dba0cb8 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.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,56 +39,19 @@ 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
* var Float32Array = require( '@stdlib/array/float32' );
*
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
-* var N = x.length;
*
-* var v = snansumkbn( N, x, 1 );
+* var v = snansumkbn( x.length, x, 1 );
* // returns 1.0
*/
-function snansumkbn( 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 ( isnanf( 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 ( isnanf( v ) === false ) {
- t = sum + v;
- if ( abs( sum ) >= abs( v ) ) {
- c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( sum-t ) + v ) ); // eslint-disable-line max-len
- } else {
- c = float64ToFloat32( c + float64ToFloat32( float64ToFloat32( v-t ) + sum ) ); // eslint-disable-line max-len
- }
- sum = t;
- }
- ix += stride;
- }
- return float64ToFloat32( sum + c );
+function snansumkbn( N, x, strideX ) {
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.native.js
index 78880b0fa501..96d3784d33b1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/lib/snansumkbn.native.js
@@ -30,20 +30,19 @@ 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
* var Float32Array = require( '@stdlib/array/float32' );
*
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
-* var N = x.length;
*
-* var v = snansumkbn( N, x, 1 );
+* var v = snansumkbn( x.length, x, 1 );
* // returns 1.0
*/
-function snansumkbn( N, x, stride ) {
- return addon( N, x, stride );
+function snansumkbn( N, x, strideX ) {
+ return addon( N, x, strideX );
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/manifest.json
index 23a37f0ec8cb..56f8a7c30837 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/manifest.json
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/manifest.json
@@ -28,53 +28,57 @@
{
"task": "build",
"src": [
- "./src/snansumkbn.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/strided/base/stride2offset",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/blas/base/shared"
]
},
{
"task": "benchmark",
"src": [
- "./src/snansumkbn.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nanf"
+ "@stdlib/math/base/assert/is-nanf",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/blas/base/shared"
]
},
{
"task": "examples",
"src": [
- "./src/snansumkbn.c"
+ "./src/main.c"
],
"include": [
"./include"
],
- "libraries": [
- "-lm"
- ],
+ "libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nanf"
+ "@stdlib/math/base/assert/is-nanf",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/math/base/special/absf",
+ "@stdlib/blas/base/shared"
]
}
]
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/addon.c
index a209caf0b32a..14afa8cbc5ae 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/addon.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/addon.c
@@ -17,12 +17,13 @@
*/
#include "stdlib/blas/ext/base/snansumkbn.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_snansumkbn( 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_snansumkbn)( 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_snansumkbn_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/snansumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
new file mode 100644
index 000000000000..69442f148218
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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/snansumkbn.h"
+#include "stdlib/math/base/assert/is_nanf.h"
+#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 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
+*/
+float API_SUFFIX(stdlib_strided_snansumkbn)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
+ return API_SUFFIX(stdlib_strided_snansumkbn_ndarray)( N, X, strideX, ox );
+}
+
+/**
+* Computes the sum of single-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
+*/
+float API_SUFFIX(stdlib_strided_snansumkbn_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 v;
+ float t;
+ float c;
+
+ sum = 0.0f;
+ if ( N <= 0 ) {
+ return sum;
+ }
+ ix = offsetX;
+ if ( strideX == 0 ) {
+ if ( stdlib_base_is_nanf( X[ ix ] ) ) {
+ return sum;
+ }
+ return N * X[ ix ];
+ }
+ c = 0.0f;
+ for ( i = 0; i < N; i++ ) {
+ v = X[ ix ];
+ if ( !stdlib_base_is_nanf( v ) ) {
+ t = sum + v;
+ if ( stdlib_base_absf( sum ) >= stdlib_base_absf( 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/snansumkbn/src/snansumkbn.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/snansumkbn.c
deleted file mode 100644
index ab06285e448c..000000000000
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/snansumkbn.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/snansumkbn.h"
-#include "stdlib/math/base/assert/is_nanf.h"
-#include
-#include
-
-/**
-* Computes the sum of single-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
-*/
-float stdlib_strided_snansumkbn( const int64_t N, const float *X, const int64_t stride ) {
- int64_t ix;
- int64_t i;
- float sum;
- float v;
- float t;
- float c;
-
- sum = 0.0f;
- if ( N <= 0 ) {
- return sum;
- }
- if ( N == 1 || stride == 0 ) {
- if ( stdlib_base_is_nanf( X[ 0 ] ) ) {
- return sum;
- }
- return X[ 0 ];
- }
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
- }
- c = 0.0f;
- for ( i = 0; i < N; i++ ) {
- v = X[ ix ];
- if ( !stdlib_base_is_nanf( v ) ) {
- t = sum + v;
- if ( fabsf( sum ) >= fabsf( 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/snansumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.ndarray.js
index de0b39ac408f..43710492778b 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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 = snansumkbn( 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 = snansumkbn( 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/snansumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.ndarray.native.js
index 937f7831f178..93e52a0d4712 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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 = snansumkbn( 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 = snansumkbn( 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/snansumkbn/test/test.snansumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.js
index 46b62935923c..6721cd974da6 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.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 = snansumkbn( 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 = snansumkbn( x.length, x, 0 );
+ t.strictEqual( v, 0.0, 'returns expected value' );
t.end();
});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.native.js
index d170eb9c95cb..7c21893f934d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/test/test.snansumkbn.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 = snansumkbn( 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 = snansumkbn( x.length, x, 0 );
+ t.strictEqual( v, 0.0, 'returns expected value' );
t.end();
});
From 3268361859f47b5b95abbca0c4e16b077cc1a579 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Tue, 21 Jan 2025 14:11:50 +0500
Subject: [PATCH 2/4] docs: fix copyright year
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
index 69442f148218..a1960ea4c4a1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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.
From 3ee4dd335da75632fa53489539dbd6222c80369f Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Tue, 21 Jan 2025 20:22:48 +0500
Subject: [PATCH 3/4] fix: apply suggestions from code review
Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
---
lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md | 2 +-
.../@stdlib/blas/ext/base/snansumkbn/examples/c/example.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
index 1936115c8d76..36444870b510 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/README.md
@@ -257,7 +257,7 @@ int main( void ) {
float v = stdlib_strided_snansumkbn( N, x, strideX );
// Print the result:
- printf( "Sum: %lf\n", v );
+ printf( "Sum: %f\n", v );
}
```
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
index 0c18142de852..7393a09dab06 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/examples/c/example.c
@@ -33,5 +33,5 @@ int main( void ) {
float v = stdlib_strided_snansumkbn( N, x, strideX );
// Print the result:
- printf( "Sum: %lf\n", v );
+ printf( "Sum: %f\n", v );
}
From d8d864139d4aeca936eaee0d09cd1b8f17cdda1b Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Wed, 22 Jan 2025 18:47:03 +0000
Subject: [PATCH 4/4] fix: copyright year
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: na
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: na
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: missing_dependencies
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
index 69442f148218..a1960ea4c4a1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/src/main.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn/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.