From 0e281b3043f9f8fb23e157f82b2a61e23f323e8a Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Fri, 22 Nov 2024 04:35:43 +0530 Subject: [PATCH] feat: add C `ndarray` implementation for `blas/base/sscal` PR-URL: https://github.com/stdlib-js/stdlib/pull/3030 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- .../@stdlib/blas/base/sscal/README.md | 127 ++++++++++++++++++ .../base/sscal/benchmark/c/benchmark.length.c | 35 ++++- .../@stdlib/blas/base/sscal/docs/repl.txt | 2 +- .../blas/base/sscal/docs/types/index.d.ts | 6 +- .../blas/base/sscal/examples/c/example.c | 8 ++ .../sscal/include/stdlib/blas/base/sscal.h | 11 +- .../include/stdlib/blas/base/sscal_cblas.h | 8 +- .../include/stdlib/blas/base/sscal_fortran.h | 6 +- .../@stdlib/blas/base/sscal/lib/ndarray.js | 17 ++- .../blas/base/sscal/lib/ndarray.native.js | 15 +-- .../@stdlib/blas/base/sscal/lib/sscal.js | 44 +----- .../blas/base/sscal/lib/sscal.native.js | 2 +- .../@stdlib/blas/base/sscal/manifest.json | 113 ++++++++++++---- .../@stdlib/blas/base/sscal/package.json | 2 - .../@stdlib/blas/base/sscal/src/addon.c | 29 +++- .../@stdlib/blas/base/sscal/src/sscal.c | 40 +----- .../@stdlib/blas/base/sscal/src/sscal_cblas.c | 28 +++- .../@stdlib/blas/base/sscal/src/sscal_f.c | 28 +++- .../blas/base/sscal/src/sscal_ndarray.c | 72 ++++++++++ .../base/sscal/test/test.ndarray.native.js | 2 +- .../blas/base/sscal/test/test.sscal.js | 29 ++-- .../blas/base/sscal/test/test.sscal.native.js | 26 ++-- 22 files changed, 486 insertions(+), 164 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/sscal/src/sscal_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/sscal/README.md b/lib/node_modules/@stdlib/blas/base/sscal/README.md index 162125ea8420..11290c779b53 100644 --- a/lib/node_modules/@stdlib/blas/base/sscal/README.md +++ b/lib/node_modules/@stdlib/blas/base/sscal/README.md @@ -146,6 +146,133 @@ console.log( x ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/sscal.h" +``` + +#### c_sscal( N, alpha, \*X, stride ) + +Multiplies each element of a single-precision floating-point vector by a constant. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + +c_sscal( 4, 5.0f, x, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] float` scalar constant. +- **X**: `[inout] float*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. + +```c +void c_sscal( const CBLAS_INT N, const float alpha, float *X, const CBLAS_INT stride ); +``` + +#### c_sscal_ndarray( N, alpha, \*X, stride, offset ) + +Multiplies each element of a single-precision floating-point vector by a constant using alternative indexing semantics. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + +c_sscal_ndarray( 4, 5.0f, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] float` scalar constant. +- **X**: `[inout] float*` input array. +- **stride**: `[in] CBLAS_INT` index increment for `X`. +- **offset**: `[in] CBLAS_INT` starting index for `X`. + +```c +void c_sscal_ndarray( const CBLAS_INT N, const float alpha, float *X, const CBLAS_INT stride, const CBLAS_INT offset ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/sscal.h" +#include + +int main( void ) { + // Create a strided array: + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of elements: + const int N = 8; + + // Specify a stride: + const int stride = 1; + + // Scale the vector: + c_sscal( N, 5.0f, x, stride ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + } + + // Scale the vector using alternative indexing semantics: + c_sscal_ndarray( N, 5.0f, x, -stride, N-1 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + } +} +``` + +
+ + + +
+ + +