From 74d5f40f3b562cd6d265fbfa93e4c7debe4a8bd2 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:28:12 +0000 Subject: [PATCH 1/5] feat: add C ndarray API and refactor --- .../blas/ext/base/dnannsumors/README.md | 130 +++++++++++++++++- .../benchmark/c/benchmark.length.c | 57 +++++++- .../blas/ext/base/dnannsumors/docs/repl.txt | 7 +- .../ext/base/dnannsumors/examples/c/example.c | 14 +- .../stdlib/blas/ext/base/dnannsumors.h | 9 +- .../ext/base/dnannsumors/lib/dnannsumors.js | 40 +----- .../blas/ext/base/dnannsumors/lib/ndarray.js | 10 +- .../base/dnannsumors/lib/ndarray.native.js | 19 +-- .../blas/ext/base/dnannsumors/manifest.json | 30 ++-- .../blas/ext/base/dnannsumors/src/addon.c | 35 ++++- .../ext/base/dnannsumors/src/dnannsumors.c | 62 --------- .../blas/ext/base/dnannsumors/src/main.c | 75 ++++++++++ .../base/dnannsumors/test/test.dnannsumors.js | 4 +- .../test/test.dnannsumors.native.js | 4 +- .../ext/base/dnannsumors/test/test.ndarray.js | 4 +- .../dnannsumors/test/test.ndarray.native.js | 4 +- 16 files changed, 342 insertions(+), 162 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnannsumors/src/dnannsumors.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnannsumors/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumors/README.md index d7493979401..0942120a453 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumors/README.md @@ -58,7 +58,7 @@ The function has the following parameters: - **out**: output [`Float64Array`][@stdlib/array/float64] whose first element is the sum and whose second element is the number of non-NaN elements. - **strideOut**: index increment for `out`. -The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -106,7 +106,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -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, offset parameters support indexing semantics based on starting indices. For example, to calculate the sum of every other value in `x` starting from the second value: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -166,6 +166,132 @@ console.log( out ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnannsumors.h" +``` + +#### stdlib_strided_dnannsumors( N, \*X, strideX, \*n ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; +CBLAS_INT n = 0; + +double v = stdlib_strided_dnannsumors( 4, x, 1, &n ); +// 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` index increment for `X`. +- **n**: `[out] CBLAS_INT*` number of non-NaN elements. + +```c +double stdlib_strided_dnannsumors( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); +``` + +#### stdlib_strided_dnannsumors_ndarray( N, \*X, strideX, offsetX, \*n ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation and alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; +CBLAS_INT n = 0; + +double v = stdlib_strided_dnannsumors_ndarray( 4, x, 1, 0, &n ); +// 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` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **n**: `[out] CBLAS_INT*` number of non-NaN elements. + +```c +double stdlib_strided_dnannsumors_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnannsumors.h" +#include "stdlib/blase/base/shared.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; + + // Initialize a variable for storing the number of non-NaN elements: + CBLAS_INT n = 0; + + // Compute the sum: + double v = stdlib_strided_dnannsumors( N, x, strideX, &n ); + + // Print the result: + printf( "sum: %lf\n", v ); + printf( "n: %"CBLAS_IFMT"\n", n ); +} +``` + +
+ + + +
+ + +