From 43c5f800549a32177cefd55e7d76fac3cd4ae835 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Wed, 6 Nov 2024 18:37:49 +0530 Subject: [PATCH] feat: update Js and add C ndarray implementation for cswap --- .../@stdlib/blas/base/cswap/README.md | 25 ++++++ .../base/cswap/benchmark/c/benchmark.length.c | 46 +++++++++- .../blas/base/cswap/examples/c/example.c | 11 ++- .../cswap/include/stdlib/blas/base/cswap.h | 5 ++ .../@stdlib/blas/base/cswap/lib/cswap.js | 59 ++---------- .../blas/base/cswap/lib/ndarray.native.js | 14 +-- .../@stdlib/blas/base/cswap/manifest.json | 90 +++++++++++++------ .../@stdlib/blas/base/cswap/src/addon.c | 22 ++++- .../@stdlib/blas/base/cswap/src/cswap.c | 51 +---------- .../@stdlib/blas/base/cswap/src/cswap_cblas.c | 22 +++++ .../@stdlib/blas/base/cswap/src/cswap_f.c | 22 +++++ .../blas/base/cswap/src/cswap_ndarray.c | 63 +++++++++++++ 12 files changed, 288 insertions(+), 142 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/cswap/src/cswap_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/cswap/README.md b/lib/node_modules/@stdlib/blas/base/cswap/README.md index 6f7e4664326c..bb46d5bc69f4 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/README.md +++ b/lib/node_modules/@stdlib/blas/base/cswap/README.md @@ -306,6 +306,31 @@ The function accepts the following arguments: void c_cswap( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ); ``` +#### c_cswap_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Interchanges two complex single-precision floating-point vectors using alternative indexing semantics. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; // interleaved real and imaginary components +float y[] = { 5.0f, 6.0f, 7.0f, 8.0f }; + +c_cswap_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_cswap_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 ); +``` + diff --git a/lib/node_modules/@stdlib/blas/base/cswap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/cswap/benchmark/c/benchmark.length.c index 1ef5e85456bb..5c56f7e311eb 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; float x[ len*2 ]; float y[ len*2 ]; @@ -122,6 +122,41 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len*2 ]; + float y[ len*2 ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*10000.0f ) - 5000.0f; + x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f; + y[ i ] = 0.0f; + y[ i+1 ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_cswap_ndarray( len, (void *)x, 1, 0, (void *)y, 1, 0 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +179,14 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/base/cswap/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/cswap/examples/c/example.c index a238680dd6e7..58ed15b3c03a 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/examples/c/example.c @@ -31,7 +31,7 @@ int main( void ) { const int strideX = 1; const int strideY = -1; - // Copy elements: + // Swap elements: c_cswap( N, (void *)x, strideX, (void *)y, strideY ); // Print the result: @@ -39,4 +39,13 @@ int main( void ) { printf( "x[ %i ] = %f + %fj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] ); } + + // Swap elements using alternative indexing semantics: + c_cswap_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 ] = %f + %fj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/cswap/include/stdlib/blas/base/cswap.h b/lib/node_modules/@stdlib/blas/base/cswap/include/stdlib/blas/base/cswap.h index 0e6456210eaf..7af1e4136276 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/include/stdlib/blas/base/cswap.h +++ b/lib/node_modules/@stdlib/blas/base/cswap/include/stdlib/blas/base/cswap.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_cswap)( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ); +/** +* Interchanges two complex single-precision floating-point vectors. +*/ +void API_SUFFIX(c_cswap_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 ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/cswap/lib/cswap.js b/lib/node_modules/@stdlib/blas/base/cswap/lib/cswap.js index 30a75c88f71f..fc91ccbb70fe 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/lib/cswap.js +++ b/lib/node_modules/@stdlib/blas/base/cswap/lib/cswap.js @@ -20,7 +20,8 @@ // MODULES // -var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -64,59 +65,9 @@ var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); * // returns 8.0 */ function cswap( N, x, strideX, y, strideY ) { - var viewX; - var viewY; - var tmp; - var sx; - var sy; - var ix; - var iy; - var i; - var j; - - if ( N <= 0 ) { - return y; - } - viewX = reinterpret( x, 0 ); - viewY = reinterpret( y, 0 ); - if ( strideX === 1 && strideY === 1 ) { - for ( i = 0; i < N*2; i += 2 ) { - tmp = viewX[ i ]; - viewX[ i ] = viewY[ i ]; - viewY[ i ] = tmp; - - j = i + 1; - tmp = viewX[ j ]; - viewX[ j ] = viewY[ j ]; - viewY[ j ] = tmp; - } - return y; - } - if ( strideX < 0 ) { - ix = 2 * (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = 2 * (1-N) * strideY; - } else { - iy = 0; - } - sx = strideX * 2; - sy = strideY * 2; - for ( i = 0; i < N; i++ ) { - tmp = viewX[ ix ]; - viewX[ ix ] = viewY[ iy ]; - viewY[ iy ] = tmp; - - tmp = viewX[ ix+1 ]; - viewX[ ix+1 ] = viewY[ iy+1 ]; - viewY[ iy+1 ] = tmp; - - ix += sx; - iy += sy; - } - return y; + var ox = stride2offset( N, strideX ); + var oy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ox, y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/blas/base/cswap/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cswap/lib/ndarray.native.js index 9d92d2254281..8a3f3d3b6039 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/cswap/lib/ndarray.native.js @@ -21,7 +21,6 @@ // MODULES // var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); var addon = require( './../src/addon.node' ); @@ -68,16 +67,9 @@ var addon = require( './../src/addon.node' ); * // returns 8.0 */ function cswap( N, x, strideX, offsetX, y, strideY, offsetY ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = reinterpret( x, offsetX ); - viewY = reinterpret( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY ); + var viewCX = reinterpret( x, 0 ); + var viewCY = reinterpret( y, 0 ); + addon.ndarray( N, viewCX, strideX, offsetX, viewCY, strideY, offsetY ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/cswap/manifest.json b/lib/node_modules/@stdlib/blas/base/cswap/manifest.json index 28e85ebf3306..59af88253f9c 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/cswap/manifest.json @@ -45,9 +45,11 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" ] }, { @@ -56,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -64,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -73,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -81,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,9 +110,11 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" ] }, { @@ -126,7 +134,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, { @@ -146,7 +156,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, @@ -167,9 +179,11 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" ] }, { @@ -178,7 +192,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -186,7 +201,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -195,7 +211,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -203,7 +220,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -225,9 +243,11 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" ] }, { @@ -246,7 +266,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, { @@ -265,7 +287,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, @@ -288,9 +312,11 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/complex/float32/ctor" ] }, { @@ -310,7 +336,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, { @@ -330,7 +358,9 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", + "@stdlib/complex/float32/ctor" ] }, @@ -340,7 +370,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -350,6 +381,7 @@ "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", "@stdlib/blas/base/shared" @@ -361,7 +393,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -369,7 +402,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -378,7 +412,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -386,7 +421,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -396,7 +432,8 @@ "blas": "", "wasm": true, "src": [ - "./src/cswap.c" + "./src/cswap.c", + "./src/cswap_ndarray.c" ], "include": [ "./include" @@ -404,7 +441,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/base/cswap/src/addon.c b/lib/node_modules/@stdlib/blas/base/cswap/src/addon.c index b4460d1b50c1..93a634fdb0a2 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/src/addon.c @@ -42,4 +42,24 @@ static napi_value addon( napi_env env, napi_callback_info info ) { return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_cswap_ndarray)( N, (void *)X, strideX, offsetX, (void *)Y, strideY, offsetY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap.c b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap.c index a5c80bc90c48..235e2051df7f 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/cswap.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Interchanges two complex single-precision floating-point vectors. @@ -29,51 +30,7 @@ * @param strideY Y stride length */ void API_SUFFIX(c_cswap)( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) { - float *x = (float *)X; - float *y = (float *)Y; - float tmp; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT i; - CBLAS_INT j; - - if ( N <= 0 ) { - return; - } - if ( strideX == 1 && strideY == 1 ) { - for ( i = 0; i < N*2; i += 2 ) { - tmp = x[ i ]; - x[ i ] = y[ i ]; - y[ i ] = tmp; - - j = i + 1; - tmp = x[ j ]; - x[ j ] = y[ j ]; - y[ j ] = tmp; - } - return; - } - if ( strideX < 0 ) { - ix = 2 * (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = 2 * (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = x[ ix ]; - x[ ix ] = y[ iy ]; - y[ iy ] = tmp; - - tmp = x[ ix+1 ]; - x[ ix+1 ] = y[ iy+1 ]; - y[ iy+1 ] = tmp; - - ix += strideX * 2; - iy += strideY * 2; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_cswap_ndarray)( N, X, strideX, ox, Y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_cblas.c b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_cblas.c index 17cc09f21555..e14c98f5bf13 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_cblas.c @@ -19,6 +19,8 @@ #include "stdlib/blas/base/cswap.h" #include "stdlib/blas/base/cswap_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two complex single-precision floating-point vectors. @@ -32,3 +34,23 @@ void API_SUFFIX(c_cswap)( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) { API_SUFFIX(cblas_cswap)( N, X, strideX, Y, strideY ); } + +/** +* Interchanges two complex single-precision floating-point vectors using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +*/ +void API_SUFFIX(c_cswap_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 ) { + stdlib_complex64_t *x = (stdlib_complex64_t *)X; + stdlib_complex64_t *y = (stdlib_complex64_t *)Y; + + x += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer + y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); // adjust array pointer + API_SUFFIX(cblas_cswap)( N, (void *)x, strideX, (void *)y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_f.c b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_f.c index 75f77d60eadc..49510b02ea6a 100644 --- a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_f.c +++ b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_f.c @@ -19,6 +19,8 @@ #include "stdlib/blas/base/cswap.h" #include "stdlib/blas/base/cswap_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two complex single-precision floating-point vectors. @@ -32,3 +34,23 @@ void API_SUFFIX(c_cswap)( const CBLAS_INT N, void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY ) { cswap( &N, X, &strideX, Y, &strideY ); } + +/** +* Interchanges two complex single-precision floating-point vectors using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +*/ +void API_SUFFIX(c_cswap_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 ) { + stdlib_complex64_t *x = (stdlib_complex64_t *)X; + stdlib_complex64_t *y = (stdlib_complex64_t *)Y; + + x += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); + y += stdlib_strided_min_view_buffer_index( N, strideY, offsetY ); + cswap( &N, (void *)x, &strideX, (void *)y, &strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_ndarray.c b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_ndarray.c new file mode 100644 index 000000000000..266b8b6d1fa0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cswap/src/cswap_ndarray.c @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/cswap.h" +#include "stdlib/blas/base/shared.h" + +/** +* Interchanges two complex single-precision floating-point vectors. +* +* @param N number of indexed elements +* @param X first input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second input array +* @param strideY Y stride length +* @param offsetY starting index for Y +*/ +void API_SUFFIX(c_cswap_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 ) { + float *x = (float *)X; + float *y = (float *)Y; + float tmp; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT sx; + CBLAS_INT sy; + CBLAS_INT i; + + if ( N <= 0 ) { + return; + } + ix = offsetX * 2; + iy = offsetY * 2; + sx = strideX * 2; + sy = strideY * 2; + for ( i = 0; i < N; i++ ) { + tmp = x[ ix ]; + x[ ix ] = y[ iy ]; + y[ iy ] = tmp; + + tmp = x[ ix+1 ]; + x[ ix+1 ] = y[ iy+1 ]; + y[ iy+1 ] = tmp; + + ix += sx; + iy += sy; + } + return; +}