From 53c8046c99a4c8377f8f24a2f564d38f5b40ab1c Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sat, 9 Nov 2024 11:54:00 +0530 Subject: [PATCH 1/3] feat: add C ndarray API for zswap --- .../@stdlib/blas/base/zswap/README.md | 136 ++++++++++++++++++ .../base/zswap/benchmark/c/benchmark.length.c | 51 ++++++- .../blas/base/zswap/examples/c/example.c | 9 ++ .../zswap/include/stdlib/blas/base/zswap.h | 9 +- .../include/stdlib/blas/base/zswap_cblas.h | 4 +- .../blas/base/zswap/lib/ndarray.native.js | 13 +- .../@stdlib/blas/base/zswap/lib/zswap.js | 59 +------- .../@stdlib/blas/base/zswap/manifest.json | 125 ++++++++++++---- .../@stdlib/blas/base/zswap/src/addon.c | 25 +++- .../@stdlib/blas/base/zswap/src/zswap.c | 52 +------ .../@stdlib/blas/base/zswap/src/zswap_cblas.c | 27 +++- .../@stdlib/blas/base/zswap/src/zswap_f.c | 25 +++- .../blas/base/zswap/src/zswap_ndarray.c | 63 ++++++++ 13 files changed, 452 insertions(+), 146 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/zswap/src/zswap_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/zswap/README.md b/lib/node_modules/@stdlib/blas/base/zswap/README.md index 7570adfe7aec..2592342cfb1a 100644 --- a/lib/node_modules/@stdlib/blas/base/zswap/README.md +++ b/lib/node_modules/@stdlib/blas/base/zswap/README.md @@ -265,6 +265,142 @@ console.log( y.get( y.length-1 ).toString() ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/zswap.h" +``` + +#### c_zswap( N, \*X, strideX, \*Y, strideY ) + +Interchanges two complex double-precision floating-point vectors. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0 }; // interleaved real and imaginary components +double y[] = { 5.0, 6.0, 7.0, 8.0 }; + +c_zswap( 2, (void *)x, 1, (void *)Y, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] void*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **Y**: `[inout] void*` first input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. + +```c +void c_zswap( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ); +``` + +#### c_zswap_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Interchanges two complex double-precision floating-point vectors using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0 }; // interleaved real and imaginary components +double y[] = { 5.0, 6.0, 7.0, 8.0 }; + +c_zswap_ndarray( 2, (void *)x, 1, 0, (void *)Y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] void*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] void*` first input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +void c_zswap_ndarray( const CBLAS_INT N, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/zswap.h" +#include + +int main( void ) { + // Create strided arrays: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify stride lengths: + const int strideX = 1; + const int strideY = -1; + + // Swap elements: + c_zswap( N, (void *)x, strideX, (void *)y, strideY ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + printf( "y[ %i ] = %lf + %lfj\n", i, y[ i*2 ], y[ (i*2)+1 ] ); + } + + // Swap elements using alternative indexing semantics: + c_zswap_ndarray( N, (void *)x, -strideX, N-1, (void *)y, strideY, N-1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + printf( "y[ %i ] = %lf + %lfj\n", i, y[ i*2 ], y[ (i*2)+1 ] ); + } +} +``` + +
+ + + +
+ + +