From 2bedae91dbdd0080b38ae0413f5e8f26b88db95b Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Thu, 19 Sep 2024 03:14:18 +0530 Subject: [PATCH] feat: add C `ndarray` implementation for `blas/base/sdot` PR-URL: https://github.com/stdlib-js/stdlib/pull/2919 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines --- .../@stdlib/blas/base/sdot/README.md | 132 ++++++++++++++++++ .../base/sdot/benchmark/c/benchmark.length.c | 46 +++++- .../blas/base/sdot/examples/c/example.c | 6 + .../base/sdot/include/stdlib/blas/base/sdot.h | 9 +- .../include/stdlib/blas/base/sdot_cblas.h | 4 +- .../blas/base/sdot/lib/ndarray.native.js | 15 +- .../@stdlib/blas/base/sdot/manifest.json | 101 +++++++++++--- .../@stdlib/blas/base/sdot/src/addon.c | 25 +++- .../@stdlib/blas/base/sdot/src/sdot.c | 51 +------ .../@stdlib/blas/base/sdot/src/sdot_cblas.c | 24 +++- .../@stdlib/blas/base/sdot/src/sdot_f.c | 27 +++- .../@stdlib/blas/base/sdot/src/sdot_ndarray.c | 84 +++++++++++ 12 files changed, 436 insertions(+), 88 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/sdot/src/sdot_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/sdot/README.md b/lib/node_modules/@stdlib/blas/base/sdot/README.md index 9812103ade9..63bece13641 100644 --- a/lib/node_modules/@stdlib/blas/base/sdot/README.md +++ b/lib/node_modules/@stdlib/blas/base/sdot/README.md @@ -177,6 +177,138 @@ console.log( out ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/sdot.h" +``` + +#### c_sdot( N, \*X, strideX, \*Y, strideY ) + +Computes the dot product of two single-precision floating-point vectors. + +```c +const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f }; +const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f }; + +float d = c_sdot( 5, x, 1, y, 1 ); +// returns -5.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **Y**: `[in] float*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. + +```c +float c_sdot( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY ); +``` + +#### c_sdot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics. + +```c +const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f }; +const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f }; + +float d = c_sdot_ndarray( 3, x, 1, 2, y, 1, 2 ); +// returns -25.0f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[in] float*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +float c_sdot_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/sdot.h" +#include + +int main( void ) { + // Create strided arrays: + const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + const float y[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of indexed elements: + const int N = 8; + + // Specify strides: + const int strideX = 1; + const int strideY = -1; + + // Compute the dot product: + float d = c_sdot( N, x, strideX, y, strideY ); + + // Print the result: + printf( "dot product: %f\n", d ); + + // Compute the dot product: + d = c_sdot_ndarray( N, x, strideX, 0, y, strideY, 7 ); + + // Print the result: + printf( "dot product: %f\n", d ); +} +``` + +
+ + + +
+ + +