From 3e07586981d984c157afbfaa95c224aa009eb40d Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Sun, 24 Nov 2024 06:31:24 +0000
Subject: [PATCH] feat: add C ndarray API and refactor
---
.../blas/ext/base/dsnansumors/README.md | 135 ++++++++++++++++--
.../base/dsnansumors/benchmark/benchmark.js | 20 ++-
.../dsnansumors/benchmark/benchmark.native.js | 20 ++-
.../benchmark/benchmark.ndarray.js | 20 ++-
.../benchmark/benchmark.ndarray.native.js | 20 ++-
.../benchmark/c/benchmark.length.c | 54 ++++++-
.../blas/ext/base/dsnansumors/docs/repl.txt | 35 +++--
.../base/dsnansumors/docs/types/index.d.ts | 14 +-
.../ext/base/dsnansumors/examples/c/example.c | 10 +-
.../stdlib/blas/ext/base/dsnansumors.h | 9 +-
.../ext/base/dsnansumors/lib/dsnansumors.js | 37 +----
.../dsnansumors/lib/dsnansumors.native.js | 9 +-
.../blas/ext/base/dsnansumors/lib/index.js | 3 +-
.../blas/ext/base/dsnansumors/lib/ndarray.js | 16 +--
.../base/dsnansumors/lib/ndarray.native.js | 15 +-
.../blas/ext/base/dsnansumors/manifest.json | 31 ++--
.../blas/ext/base/dsnansumors/src/addon.c | 26 +++-
.../ext/base/dsnansumors/src/dsnansumors.c | 58 --------
.../blas/ext/base/dsnansumors/src/main.c | 69 +++++++++
.../base/dsnansumors/test/test.dsnansumors.js | 16 ++-
.../test/test.dsnansumors.native.js | 16 ++-
.../ext/base/dsnansumors/test/test.ndarray.js | 16 ++-
.../dsnansumors/test/test.ndarray.native.js | 16 ++-
23 files changed, 450 insertions(+), 215 deletions(-)
delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsnansumors/src/dsnansumors.c
create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsnansumors/src/main.c
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsnansumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsnansumors/README.md
index 477f900f3292..85df5e6862d9 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsnansumors/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsnansumors/README.md
@@ -36,7 +36,7 @@ limitations under the License.
var dsnansumors = require( '@stdlib/blas/ext/base/dsnansumors' );
```
-#### dsnansumors( N, x, stride )
+#### dsnansumors( N, x, strideX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
@@ -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 = dsnansumors( N, x, 1 );
+var v = dsnansumors( 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 for `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 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 = dsnansumors( 4, x1, 2 );
// returns 5.0
```
-#### dsnansumors.ndarray( N, x, stride, offset )
+#### dsnansumors.ndarray( N, x, strideX, offsetX )
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics.
@@ -90,15 +89,15 @@ var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
-var v = dsnansumors.ndarray( 4, x, 1, 0 );
+var v = dsnansumors.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 Float32Array = require( '@stdlib/array/float32' );
@@ -154,6 +153,124 @@ console.log( v );
+
+
+* * *
+
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/dsnansumors.h"
+```
+
+#### stdlib_strided_dsnansumors( N, \*X, strideX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
+
+```c
+const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
+
+double v = stdlib_strided_dsnansumors( 4, x, 1 );
+// returns 1.0
+```
+
+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 for `X`.
+
+```c
+double stdlib_strided_dsnansumors( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
+```
+
+#### stdlib_strided_dsnansumors_ndarray( N, \*X, strideX, offsetX )
+
+Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
+
+```c
+const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
+
+double v = stdlib_strided_dsnansumors_ndarray( 4, x, 1, 0 );
+// returns 1.0
+```
+
+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 for `X`.
+- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
+
+```c
+double stdlib_strided_dsnansumors_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/dsnansumors.h"
+#include "stdlib/blas/base/shared.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:
+ double v = stdlib_strided_dsnansumors( N, x, strideX );
+
+ // Print the result:
+ printf( "sum: %lf\n", v );
+}
+```
+
+
+
+
+
+
+
+
+