From 1d397258845c808461e3e02759afb40dbc0a79fc Mon Sep 17 00:00:00 2001 From: aman-095 Date: Mon, 30 Sep 2024 12:32:58 +0530 Subject: [PATCH 1/7] feat: update Js implementation and add C ndarray API for cscal --- .../@stdlib/blas/base/cscal/README.md | 37 +++++++- .../base/cscal/benchmark/c/benchmark.length.c | 45 +++++++++- .../@stdlib/blas/base/cscal/docs/repl.txt | 3 +- .../blas/base/cscal/examples/c/example.c | 8 ++ .../cscal/include/stdlib/blas/base/cscal.h | 5 ++ .../@stdlib/blas/base/cscal/lib/cscal.js | 25 +----- .../@stdlib/blas/base/cscal/lib/ndarray.js | 2 +- .../blas/base/cscal/lib/ndarray.native.js | 7 +- .../@stdlib/blas/base/cscal/manifest.json | 43 ++++++++-- .../@stdlib/blas/base/cscal/src/addon.c | 23 ++++- .../@stdlib/blas/base/cscal/src/cscal.c | 17 +--- .../@stdlib/blas/base/cscal/src/cscal_cblas.c | 16 ++++ .../@stdlib/blas/base/cscal/src/cscal_f.c | 27 ++++++ .../blas/base/cscal/src/cscal_ndarray.c | 50 +++++++++++ .../blas/base/cscal/test/test.cscal.js | 75 +++++++++++----- .../blas/base/cscal/test/test.cscal.native.js | 75 +++++++++++----- .../blas/base/cscal/test/test.ndarray.js | 86 +++++++++++++++---- .../base/cscal/test/test.ndarray.native.js | 77 ++++++++++++----- 18 files changed, 484 insertions(+), 137 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/cscal/README.md b/lib/node_modules/@stdlib/blas/base/cscal/README.md index be878274cdb..5ff72d193ef 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/README.md +++ b/lib/node_modules/@stdlib/blas/base/cscal/README.md @@ -251,7 +251,7 @@ Scales values from `CX` by `ca`. float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); -c_dscal( 4, ca, (void *)cx, 1 ); +c_cscal( 4, ca, (void *)cx, 1 ); ``` The function accepts the following arguments: @@ -262,7 +262,32 @@ The function accepts the following arguments: - **strideX**: `[in] CBLAS_INT` index increment for `CX`. ```c -void c_dscal( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ); +void c_cscal( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ); +``` + +#### c_cscal_ndarray( N, ca, \*CX, strideX, offsetX ) + +Scales values from `CX` by `ca` using alternative indexing semantics. + +```c +#include "stdlib/complex/float32/ctor.h" + +float cx[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; +const stdlib_complex64_t ca = stdlib_complex64( 2.0f, 2.0f ); + +c_cscal( 4, ca, (void *)cx, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **ca**: `[in] stdlib_complex64_t` scalar constant. +- **CX**: `[inout] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `CX`. +- **offsetX**: `[in] CBLAS_INT` starting index for `CX`. + +```c +void c_cscal_ndarray( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ); ``` @@ -308,6 +333,14 @@ int main( void ) { for ( int i = 0; i < N; i++ ) { printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); } + + // Scale the elements of the array: + c_cscal_ndarray( N, ca, (void *)cx, -strideX, 3 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); + } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c index 239d6f67ca9..c4a7a77504c 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/benchmark/c/benchmark.length.c @@ -95,7 +95,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 ) { stdlib_complex64_t ca; float cx[ len*2 ]; double elapsed; @@ -122,6 +122,40 @@ 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 ) { + stdlib_complex64_t ca; + float cx[ len*2 ]; + double elapsed; + double t; + int i; + + ca = stdlib_complex64( 1.0f, 0.0f ); + for ( i = 0; i < len*2; i += 2 ) { + cx[ i ] = ( rand_float()*2.0f ) - 1.0f; + cx[ i+1 ] = ( rand_float()*2.0f ) - 1.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_cscal_ndarray( len, ca, (void *)cx, 1, 0 ); + if ( cx[ 0 ] != cx[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( cx[ 0 ] != cx[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +178,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/cscal/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt index 922d686a564..894daacaf6c 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/cscal/docs/repl.txt @@ -9,8 +9,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N` or `strideX` is less than or equal to `0`, the function returns `cx` - unchanged. + If `N` is less than or equal to `0`, the function returns `cx` unchanged. Parameters diff --git a/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c index 67ff6e14b88..0a2b4b7753d 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/examples/c/example.c @@ -40,4 +40,12 @@ int main( void ) { for ( int i = 0; i < N; i++ ) { printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); } + + // Scale the elements of the array: + c_cscal_ndarray( N, ca, (void *)cx, -strideX, 3 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "cx[ %i ] = %f + %fj\n", i, cx[ i*2 ], cx[ (i*2)+1 ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal.h b/lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal.h index 910a68a87e9..96349cdaecc 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal.h +++ b/lib/node_modules/@stdlib/blas/base/cscal/include/stdlib/blas/base/cscal.h @@ -37,6 +37,11 @@ extern "C" { */ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ); +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant using alternative indexing semantics. +*/ +void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.js index 42c6d2da998..3972bf27614 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/cscal.js @@ -20,7 +20,8 @@ // MODULES // -var cmulf = require( '@stdlib/complex/float32/base/mul' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -55,26 +56,8 @@ var cmulf = require( '@stdlib/complex/float32/base/mul' ); * // returns 6.0 */ function cscal( N, ca, cx, strideX ) { - var ix; - var i; - - if ( N <= 0 || strideX <= 0 ) { - return cx; - } - if ( strideX === 1 ) { - // Code for stride equal to `1`... - for ( i = 0; i < N; i++ ) { - cx.set( cmulf( ca, cx.get( i ) ), i ); - } - return cx; - } - // Code for stride not equal to `1`... - ix = 0; - for ( i = 0; i < N; i++ ) { - cx.set( cmulf( ca, cx.get( ix ) ), ix ); - ix += strideX; - } - return cx; + var ox = stride2offset( N, strideX ); + return ndarray( N, ca, cx, strideX, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js index c85dc78a73c..6b56245e080 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.js @@ -59,7 +59,7 @@ function cscal( N, ca, cx, strideX, offsetX ) { var ix; var i; - if ( N <= 0 || strideX <= 0 ) { + if ( N <= 0 ) { return cx; } ix = offsetX; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js index 5a1780632dc..ad22c3f4348 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/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' ); @@ -58,10 +57,8 @@ var addon = require( './../src/addon.node' ); * // returns 6.0 */ function cscal( N, ca, cx, strideX, offsetX ) { - var viewCX; - offsetX = minViewBufferIndex( N, strideX, offsetX ); - viewCX = reinterpret( cx, offsetX ); - addon( N, ca, viewCX, strideX ); + var viewCX = reinterpret( cx, 0 ); + addon.ndarray( N, ca, viewCX, strideX, offsetX ); return cx; } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/manifest.json b/lib/node_modules/@stdlib/blas/base/cscal/manifest.json index e20d079287f..4736f9e1ef9 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/cscal/manifest.json @@ -45,6 +45,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -59,7 +60,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -68,6 +70,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -78,7 +81,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -87,6 +91,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -111,6 +116,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -136,6 +142,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -157,6 +164,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -178,6 +186,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -191,7 +200,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -200,6 +210,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -210,7 +221,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -219,6 +231,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -242,6 +255,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -266,6 +280,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -286,6 +301,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -309,6 +325,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -334,6 +351,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -355,6 +373,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -365,7 +384,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -375,6 +395,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex64array", @@ -389,7 +410,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -398,6 +420,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -408,7 +431,8 @@ "blas": "", "wasm": false, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -417,6 +441,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] @@ -428,7 +453,8 @@ "blas": "", "wasm": true, "src": [ - "./src/cscal.c" + "./src/cscal.c", + "./src/cscal_ndarray.c" ], "include": [ "./include" @@ -437,6 +463,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float32/base/mul", "@stdlib/complex/float32/ctor" ] diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/addon.c b/lib/node_modules/@stdlib/blas/base/cscal/src/addon.c index cfc7f870722..0ad96dee423 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/base/cscal.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -37,8 +38,26 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_COMPLEX64( env, ca, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); - c_cscal( N, ca, (void *)CX, strideX ); + API_SUFFIX(c_cscal)( N, ca, (void *)CX, strideX ); 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_COMPLEX64( env, ca, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX64ARRAY( env, CX, N, strideX, argv, 2 ); + API_SUFFIX(c_cscal_ndarray)( N, ca, (void *)CX, strideX, offsetX ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c index 2dc84e61b5d..92378b5c607 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c @@ -20,6 +20,7 @@ #include "stdlib/blas/base/shared.h" #include "stdlib/complex/float32/ctor.h" #include "stdlib/complex/float32/base/mul.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -31,18 +32,6 @@ * @param strideX CX stride length */ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { - stdlib_complex64_t z; - CBLAS_INT i; - - uint8_t *ip1 = (uint8_t *)CX; - int64_t is1 = 8 * strideX; - - if ( N <= 0 || strideX <= 0 ) { - return; - } - for ( i = 0; i < N; i++, ip1 += is1 ) { - z = *(stdlib_complex64_t *)ip1; - *(stdlib_complex64_t *)ip1 = stdlib_base_complex64_mul( ca, z ); - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(c_cscal_ndarray)( N, ca, CX, strideX, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c index 49e95da7586..4a2a3320e0d 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c @@ -30,5 +30,21 @@ * @param strideX CX stride length */ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { + if( strideX < 0 ) { + cblas_cscal( N, ca, CX, -strideX ); + } + cblas_cscal( N, ca, CX, strideX ); +} + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param offsetX starting index for CX +*/ +void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { cblas_cscal( N, ca, CX, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c index 07f2a070e3d..6cea7367db7 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c @@ -20,6 +20,8 @@ #include "stdlib/blas/base/cscal_fortran.h" #include "stdlib/blas/base/shared.h" #include "stdlib/complex/float32/ctor.h" +#include "stdlib/strided/base/min_view_buffer_index.h" +#include /** * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. @@ -30,5 +32,30 @@ * @param strideX CX stride length */ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { + CBLAS_INT sx = strideX; + if( sx < 0 ) { + sx = -sx; + cscal( &N, &ca, CX, &sx ); + } cscal( &N, &ca, CX, &strideX ); } + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param offsetX starting index for CX +*/ +void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT sx = strideX; + + CX = (void *)((stdlib_complex64_t *)CX + stdlib_strided_min_view_buffer_index( N, strideX, offsetX )); + if( sx < 0 ) { + sx = -sx; + cscal( &N, &ca, CX, &sx ); + } + cscal( &N, &ca, CX, &sx ); +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c new file mode 100644 index 00000000000..3a63b1e1570 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/cscal.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float32/ctor.h" +#include "stdlib/complex/float32/base/mul.h" +#include + +/** +* Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param ca scalar constant +* @param CX input array +* @param strideX CX stride length +* @param offsetX starting index for CX +*/ +void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + stdlib_complex64_t z; + CBLAS_INT i; + + stdlib_complex64_t *ip1 = (stdlib_complex64_t *)CX; + int64_t is1 = strideX; + + ip1 += offsetX; + if ( N <= 0 ) { + return; + } + for ( i = 0; i < N; i++, ip1 += is1 ) { + z = *ip1; + *ip1 = stdlib_base_complex64_mul( ca, z ); + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js index ec3e73c922c..624ab95acbe 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.js @@ -88,7 +88,7 @@ tape( 'the function scales elements from `cx` by `ca`', function test( t ) { t.end(); }); -tape( 'the function supports a `cx` stride', function test( t ) { +tape( 'the function supports specifying a `cx` stride', function test( t ) { var expected; var delta; var viewX; @@ -142,42 +142,75 @@ tape( 'the function supports a `cx` stride', function test( t ) { t.end(); }); -tape( 'the function returns a reference to the input array', function test( t ) { - var out; +tape( 'the function supports specifying a negative `cx` stride', function test( t ) { + var expected; + var delta; + var viewX; + var tol; var ca; var cx; + var k; - cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - ca = new Complex64( 2.0, 2.0 ); + cx = new Complex64Array( [ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); - out = cscal( 4, ca, cx, 1 ); + cscal( 3, ca, cx, -2 ); - t.strictEqual( out, cx, 'same reference' ); + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { - var expected; - var viewX; +tape( 'the function returns a reference to the input array', function test( t ) { + var out; var ca; var cx; cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); ca = new Complex64( 2.0, 2.0 ); - viewX = new Float32Array( cx.buffer ); - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - cscal( -1, ca, cx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - cscal( 0, ca, cx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); + out = cscal( 4, ca, cx, 1 ); + t.strictEqual( out, cx, 'same reference' ); t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var viewX; var ca; @@ -189,10 +222,10 @@ tape( 'if provided an `strideX` parameter less than or equal to `0`, the functio viewX = new Float32Array( cx.buffer ); expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - cscal( 4, ca, cx, -1 ); + cscal( -1, ca, cx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); - cscal( 4, ca, cx, 0 ); + cscal( 0, ca, cx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js index 56a2f8ad84f..c69e6f27f76 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.cscal.native.js @@ -97,7 +97,7 @@ tape( 'the function scales elements from `cx` by `ca`', opts, function test( t ) t.end(); }); -tape( 'the function supports a `cx` stride', opts, function test( t ) { +tape( 'the function supports specifying a `cx` stride', opts, function test( t ) { var expected; var delta; var viewX; @@ -151,42 +151,75 @@ tape( 'the function supports a `cx` stride', opts, function test( t ) { t.end(); }); -tape( 'the function returns a reference to the input array', opts, function test( t ) { - var out; +tape( 'the function supports specifying a negative `cx` stride', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; var ca; var cx; + var k; - cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - ca = new Complex64( 2.0, 2.0 ); + cx = new Complex64Array( [ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); - out = cscal( 4, ca, cx, 1 ); + cscal( 3, ca, cx, -2 ); - t.strictEqual( out, cx, 'same reference' ); + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { - var expected; - var viewX; +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; var ca; var cx; cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); ca = new Complex64( 2.0, 2.0 ); - viewX = new Float32Array( cx.buffer ); - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - cscal( -1, ca, cx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - cscal( 0, ca, cx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); + out = cscal( 4, ca, cx, 1 ); + t.strictEqual( out, cx, 'same reference' ); t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var viewX; var ca; @@ -198,10 +231,10 @@ tape( 'if provided an `strideX` parameter less than or equal to `0`, the functio viewX = new Float32Array( cx.buffer ); expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - cscal( 4, ca, cx, -1 ); + cscal( -1, ca, cx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); - cscal( 4, ca, cx, 0 ); + cscal( 0, ca, cx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js index 4ccc29d9455..0d3478b5573 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js @@ -96,7 +96,7 @@ tape( 'the function scales elements from `cx` by `ca`', function test( t ) { t.end(); }); -tape( 'the function supports a `cx` stride', function test( t ) { +tape( 'the function supports specifying a `cx` stride', function test( t ) { var expected; var delta; var viewX; @@ -150,6 +150,60 @@ tape( 'the function supports a `cx` stride', function test( t ) { t.end(); }); +tape( 'the function supports specifying a negative `cx` stride', function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, -2, 4 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + tape( 'the function supports a `cx` offset', function test( t ) { var expected; var delta; @@ -239,26 +293,26 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { - var expected; - var viewX; - var ca; - var cx; +// tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { +// var expected; +// var viewX; +// var ca; +// var cx; - cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - ca = new Complex64( 2.0, 2.0 ); +// cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +// ca = new Complex64( 2.0, 2.0 ); - viewX = new Float32Array( cx.buffer ); - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +// viewX = new Float32Array( cx.buffer ); +// expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - cscal( 4, ca, cx, -1, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); +// cscal( 4, ca, cx, -1, 3 ); +// t.deepEqual( viewX, expected, 'returns expected value' ); - cscal( 4, ca, cx, 0, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); +// cscal( 4, ca, cx, 0, 3 ); +// t.deepEqual( viewX, expected, 'returns expected value' ); - t.end(); -}); +// t.end(); +// }); tape( 'the function supports complex access patterns', function test( t ) { var expected; diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js index be323851bc5..b6b77b5795c 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.native.js @@ -105,7 +105,7 @@ tape( 'the function scales elements from `cx` by `ca`', opts, function test( t ) t.end(); }); -tape( 'the function supports a `cx` stride', opts, function test( t ) { +tape( 'the function supports specifying a `cx` stride', opts, function test( t ) { var expected; var delta; var viewX; @@ -159,6 +159,60 @@ tape( 'the function supports a `cx` stride', opts, function test( t ) { t.end(); }); +tape( 'the function supports specifying a negative `cx` stride', opts, function test( t ) { + var expected; + var delta; + var viewX; + var tol; + var ca; + var cx; + var k; + + cx = new Complex64Array( [ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ] ); + ca = new Complex64( 0.4, -0.7 ); + + cscal( 3, ca, cx, -2, 4 ); + + viewX = new Float32Array( cx.buffer ); + expected = new Float32Array( [ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ] ); + for ( k = 0; k < expected.length; k++ ) { + if ( viewX[ k ] === expected[ k ] ) { + t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); + } else { + delta = abs( viewX[ k ] - expected[ k ] ); + tol = 1.0 * EPS * abs( expected[ k ] ); + t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + tape( 'the function supports a `cx` offset', opts, function test( t ) { var expected; var delta; @@ -248,27 +302,6 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { - var expected; - var viewX; - var ca; - var cx; - - cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - ca = new Complex64( 2.0, 2.0 ); - - viewX = new Float32Array( cx.buffer ); - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - cscal( 4, ca, cx, -1, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - cscal( 4, ca, cx, 0, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports complex access patterns', opts, function test( t ) { var expected; var delta; From 9817ed9531d4dd3b0bc0a1e402611ceba2c59e8d Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 30 Sep 2024 23:47:32 -0700 Subject: [PATCH 2/7] fix: remove duplicate invocations and simplify pointer adjustment --- lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c index 6cea7367db7..b7e8ca4012a 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c @@ -35,9 +35,8 @@ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void * CBLAS_INT sx = strideX; if( sx < 0 ) { sx = -sx; - cscal( &N, &ca, CX, &sx ); } - cscal( &N, &ca, CX, &strideX ); + cscal( &N, &ca, CX, &sx ); } /** @@ -50,12 +49,12 @@ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void * * @param offsetX starting index for CX */ void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + stdlib_complex64_t *cx = (stdlib_complex64_t *)CX; CBLAS_INT sx = strideX; - CX = (void *)((stdlib_complex64_t *)CX + stdlib_strided_min_view_buffer_index( N, strideX, offsetX )); + cx += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); if( sx < 0 ) { sx = -sx; - cscal( &N, &ca, CX, &sx ); } - cscal( &N, &ca, CX, &sx ); + cscal( &N, &ca, (void *)cx, &sx ); } From 1de35dae911b448c5a5d91f11fb0f4297f19cc2a Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 30 Sep 2024 23:51:23 -0700 Subject: [PATCH 3/7] refactor: clean-up implementation --- .../@stdlib/blas/base/cscal/src/cscal_ndarray.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c index 3a63b1e1570..5ac3d7b15df 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_ndarray.c @@ -33,15 +33,15 @@ */ void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { stdlib_complex64_t z; - CBLAS_INT i; + int64_t is1; + int64_t i; - stdlib_complex64_t *ip1 = (stdlib_complex64_t *)CX; - int64_t is1 = strideX; - - ip1 += offsetX; if ( N <= 0 ) { return; } + stdlib_complex64_t *ip1 = (stdlib_complex64_t *)CX; + is1 = (int64_t)strideX; + ip1 += offsetX; for ( i = 0; i < N; i++, ip1 += is1 ) { z = *ip1; *ip1 = stdlib_base_complex64_mul( ca, z ); From 64dc9e3cc9a297f1800ccee47cbc5608ebdccda7 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 1 Oct 2024 12:38:02 +0530 Subject: [PATCH 4/7] chore: apply review changes --- .../@stdlib/blas/base/cscal/src/cscal_cblas.c | 16 ++++++++++++---- .../@stdlib/blas/base/cscal/src/cscal_f.c | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c index 4a2a3320e0d..d942b96ed38 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_cblas.c @@ -30,10 +30,11 @@ * @param strideX CX stride length */ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX ) { - if( strideX < 0 ) { - cblas_cscal( N, ca, CX, -strideX ); + CBLAS_INT sx = strideX; + if( sx < 0 ) { + sx = -sx; } - cblas_cscal( N, ca, CX, strideX ); + API_SUFFIX(cblas_cscal)( N, ca, CX, sx ); } /** @@ -46,5 +47,12 @@ void API_SUFFIX(c_cscal)( const CBLAS_INT N, const stdlib_complex64_t ca, void * * @param offsetX starting index for CX */ void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca, void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - cblas_cscal( N, ca, CX, strideX ); + stdlib_complex64_t *cx = (stdlib_complex64_t *)CX; + CBLAS_INT sx = strideX; + + cx += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); + if( sx < 0 ) { + sx = -sx; + } + API_SUFFIX(cblas_cscal)( N, ca, (void *)cx, sx ); } diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c index b7e8ca4012a..065760d09c1 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c @@ -52,7 +52,7 @@ void API_SUFFIX(c_cscal_ndarray)( const CBLAS_INT N, const stdlib_complex64_t ca stdlib_complex64_t *cx = (stdlib_complex64_t *)CX; CBLAS_INT sx = strideX; - cx += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); + cx += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); if( sx < 0 ) { sx = -sx; } From 5b548ba86131b1d87e3666e838a3f23b7b18fc94 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Tue, 1 Oct 2024 15:00:10 +0530 Subject: [PATCH 5/7] test: resolve lint error --- .../blas/base/cscal/test/test.ndarray.js | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js index 0d3478b5573..3da9c624be3 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/cscal/test/test.ndarray.js @@ -293,27 +293,6 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -// tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { -// var expected; -// var viewX; -// var ca; -// var cx; - -// cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -// ca = new Complex64( 2.0, 2.0 ); - -// viewX = new Float32Array( cx.buffer ); -// expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - -// cscal( 4, ca, cx, -1, 3 ); -// t.deepEqual( viewX, expected, 'returns expected value' ); - -// cscal( 4, ca, cx, 0, 3 ); -// t.deepEqual( viewX, expected, 'returns expected value' ); - -// t.end(); -// }); - tape( 'the function supports complex access patterns', function test( t ) { var expected; var delta; From dd8a3fe9f4b9479d410996fbf8435fb9f765d87c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Oct 2024 18:57:19 -0700 Subject: [PATCH 6/7] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c index 92378b5c607..cf7f7d7f9a0 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal.c @@ -21,7 +21,6 @@ #include "stdlib/complex/float32/ctor.h" #include "stdlib/complex/float32/base/mul.h" #include "stdlib/strided/base/stride2offset.h" -#include /** * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant. From 450e917da512851e1c2afce6023d19e1256214fd Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Oct 2024 18:59:09 -0700 Subject: [PATCH 7/7] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c index 065760d09c1..85426c28b8b 100644 --- a/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/cscal/src/cscal_f.c @@ -21,7 +21,6 @@ #include "stdlib/blas/base/shared.h" #include "stdlib/complex/float32/ctor.h" #include "stdlib/strided/base/min_view_buffer_index.h" -#include /** * Scales a single-precision complex floating-point vector by a single-precision complex floating-point constant.