From 0a4b659ffe648ba49ab7cc47920f96e160a685ff Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 2 Oct 2024 17:57:46 +0530 Subject: [PATCH 1/2] feat: update Js implementation and add C implementation for idamax --- .../@stdlib/blas/base/idamax/README.md | 124 ++++++++++++++++++ .../idamax/benchmark/c/benchmark.length.c | 44 ++++++- .../blas/base/idamax/examples/c/example.c | 6 + .../idamax/include/stdlib/blas/base/idamax.h | 9 +- .../include/stdlib/blas/base/idamax_cblas.h | 4 +- .../@stdlib/blas/base/idamax/lib/idamax.js | 42 +----- .../blas/base/idamax/lib/ndarray.native.js | 12 +- .../@stdlib/blas/base/idamax/manifest.json | 102 ++++++++++++-- .../@stdlib/blas/base/idamax/src/addon.c | 25 +++- .../@stdlib/blas/base/idamax/src/idamax.c | 46 +------ .../blas/base/idamax/src/idamax_cblas.c | 65 ++++++++- .../@stdlib/blas/base/idamax/src/idamax_f.c | 69 +++++++++- .../blas/base/idamax/src/idamax_ndarray.c | 57 ++++++++ .../blas/base/idamax/test/test.idamax.js | 33 +++-- .../base/idamax/test/test.idamax.native.js | 33 +++-- 15 files changed, 523 insertions(+), 148 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/idamax/src/idamax_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/idamax/README.md b/lib/node_modules/@stdlib/blas/base/idamax/README.md index 56cf4f873cc..71a4dacd637 100644 --- a/lib/node_modules/@stdlib/blas/base/idamax/README.md +++ b/lib/node_modules/@stdlib/blas/base/idamax/README.md @@ -143,6 +143,130 @@ console.log( idx ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/idamax.h" +``` + +#### c_idamax( N, \*X, strideX ) + +Finds the index of the first element having the maximum absolute value. + +```c +const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 }; + +int idx = c_idamax( 5, x, 1 ); +// returns 3 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. + +```c +CBLAS_INT c_idamax( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### c_idamax_ndarray( N, \*X, strideX, offsetX ) + +Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + +```c +const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 }; + +int idx = c_idamax_ndarray( 5, x, 1, 0 ); +// returns 3 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +CBLAS_INT c_idamax_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/idamax.h" +#include + +int main( void ) { + // Create strided array: + const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of element: + const int N = 8; + + // Specify stride: + const int strideX = 1; + + // Compute the index of the maximum absolute value: + int idx = c_idamax( N, x, strideX ); + + // Print the result: + printf( "index value: %d\n", idx ); + + // Compute the index of the maximum absolute value: + idx = c_idamax_ndarray( N, x, -strideX, N-1 ); + + // Print the result: + printf( "index value: %d\n", idx ); +} +``` + +
+ + + +
+ + + +