From 57d03ad4821f87e6ea471794cd6c4a60adc40d86 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sat, 21 Sep 2024 06:30:55 +0530 Subject: [PATCH] feat: add C `ndarray` implementation for `blas/base/srot` and `blas/base/drot` PR-URL: https://github.com/stdlib-js/stdlib/pull/2896 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines --- .../@stdlib/blas/base/drot/README.md | 41 +++++++- .../base/drot/benchmark/c/benchmark.length.c | 44 ++++++++- .../blas/base/drot/examples/c/example.c | 14 ++- .../base/drot/include/stdlib/blas/base/drot.h | 5 + .../blas/base/drot/lib/ndarray.native.js | 15 +-- .../@stdlib/blas/base/drot/manifest.json | 93 ++++++++++++------- .../@stdlib/blas/base/drot/src/addon.c | 24 ++++- .../@stdlib/blas/base/drot/src/drot.c | 39 +------- .../@stdlib/blas/base/drot/src/drot_cblas.c | 20 ++++ .../@stdlib/blas/base/drot/src/drot_f.c | 20 ++++ .../@stdlib/blas/base/drot/src/drot_ndarray.c | 54 +++++++++++ .../@stdlib/blas/base/srot/README.md | 49 ++++++++-- .../base/srot/benchmark/c/benchmark.length.c | 44 ++++++++- .../blas/base/srot/examples/c/example.c | 14 ++- .../base/srot/include/stdlib/blas/base/srot.h | 5 + .../blas/base/srot/lib/ndarray.native.js | 19 +--- .../@stdlib/blas/base/srot/lib/srot.native.js | 4 +- .../@stdlib/blas/base/srot/manifest.json | 93 ++++++++++++------- .../@stdlib/blas/base/srot/src/addon.c | 24 ++++- .../@stdlib/blas/base/srot/src/srot.c | 43 ++------- .../@stdlib/blas/base/srot/src/srot.f | 4 +- .../@stdlib/blas/base/srot/src/srot_cblas.c | 24 ++++- .../@stdlib/blas/base/srot/src/srot_f.c | 24 ++++- .../@stdlib/blas/base/srot/src/srot_ndarray.c | 54 +++++++++++ 24 files changed, 574 insertions(+), 196 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c create mode 100644 lib/node_modules/@stdlib/blas/base/srot/src/srot_ndarray.c diff --git a/lib/node_modules/@stdlib/blas/base/drot/README.md b/lib/node_modules/@stdlib/blas/base/drot/README.md index e06b96eee24..f12f5efce11 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/README.md +++ b/lib/node_modules/@stdlib/blas/base/drot/README.md @@ -230,6 +230,33 @@ The function accepts the following arguments: void c_drot( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ); ``` +#### c_drot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, c, s ) + +Applies a plane rotation using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; +double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; + +c_drot_ndarray( 5, x, 1, 0, y, 1, 0, 0.8, 0.6 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] double*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] double*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. +- **c**: `[in] double` cosine of the angle of rotation. +- **s**: `[in] double` sine of the angle of rotation. + +```c +void c_drot_ndarray( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ); +``` + @@ -258,11 +285,11 @@ int main( void ) { double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const double c = 0.8; @@ -275,6 +302,14 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c index b522fce1d70..8bb1d80688f 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/drot/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( 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; double x[ len ]; double y[ len ]; @@ -120,6 +120,39 @@ 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; + double x[ len ]; + double y[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*200.0 ) - 100.0; + y[ i ] = ( rand_double()*200.0 ) - 100.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_drot_ndarray( len, x, 1, 0, y, 1, 0, 0.8, 0.6 ); + 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. */ @@ -142,7 +175,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/drot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c index 86c9fd5c41b..ff492f3f55c 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/drot/examples/c/example.c @@ -25,11 +25,11 @@ int main( void ) { double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const double c = 0.8; @@ -42,4 +42,12 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_drot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h index 5042ea4cb30..2d62297f1fd 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h +++ b/lib/node_modules/@stdlib/blas/base/drot/include/stdlib/blas/base/drot.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ); +/** +* Applies a plane rotation using alternative indexing semantics. +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js index fd2d583bb32..f101e40b215 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './drot.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -52,16 +50,7 @@ var addon = require( './drot.native.js' ); * // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] */ function drot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY, c, s ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/manifest.json b/lib/node_modules/@stdlib/blas/base/drot/manifest.json index fa3bb61162c..83614c2f493 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/drot/manifest.json @@ -44,11 +44,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,11 +109,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,11 +176,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,11 +240,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,11 +307,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -354,11 +374,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/argv-double" + "@stdlib/napi/argv-strided-float64array" ] }, { @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/drot.c" + "./src/drot.c", + "./src/drot_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,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/drot/src/addon.c b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c index c98a80dbd01..43f51971ce9 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/addon.c @@ -45,4 +45,26 @@ 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, 9 ); + 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_DOUBLE( env, c, argv, 7 ); + STDLIB_NAPI_ARGV_DOUBLE( env, s, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_drot_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY, c, s ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c index 14c5e8ea644..0a617c2a401 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Applies a plane rotation. @@ -31,40 +32,8 @@ * @param s sine of the angle of rotation */ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { - double tmp; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT i; - - if ( N <= 0 ) { - return; - } - // If both strides are equal to `1`... - if ( strideX == 1 && strideY == 1 ) { - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ i ] ) + ( s * Y[ i ] ); - Y[ i ] = ( c * Y[ i ] ) - ( s * X[ i ] ); - X[ i ] = tmp; - } - return; - } - // If both strides are not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); - Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); - X[ ix ] = tmp; - ix += strideX; - iy += strideY; - } + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_drot_ndarray)( N, X, strideX, ox, Y, strideY, oy, c, s ); return; } diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c index 7c557e79df0..d58272128d5 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/drot_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. @@ -34,3 +35,22 @@ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { API_SUFFIX(cblas_drot)( N, X, strideX, Y, strideY, c, s ); } + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + 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_drot)( N, alpha, X, strideX, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c index 3546a520363..99e15935655 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/drot.h" #include "stdlib/blas/base/drot_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. @@ -34,3 +35,22 @@ void API_SUFFIX(c_drot)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double c, const double s ) { drot( &N, X, &strideX, Y, &strideY, &c, &s ); } + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + 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 + drot( &N, X, &strideX, Y, &strideY, &c, &s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c b/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c new file mode 100644 index 00000000000..716b441e37d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/drot/src/drot_ndarray.c @@ -0,0 +1,54 @@ +/** +* @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/drot.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_drot_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double c, const double s ) { + double tmp; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; + + if ( N <= 0 ) { + return; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); + Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); + X[ ix ] = tmp; + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/srot/README.md b/lib/node_modules/@stdlib/blas/base/srot/README.md index ec8a73a35a3..0db8477dbc3 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/README.md +++ b/lib/node_modules/@stdlib/blas/base/srot/README.md @@ -213,7 +213,7 @@ Applies a plane rotation. float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; -c_drot( 5, x, 1, y, 1, 0.8f, 0.6f ); +c_srot( 5, x, 1, y, 1, 0.8f, 0.6f ); ``` The function accepts the following arguments: @@ -227,7 +227,34 @@ The function accepts the following arguments: - **s**: `[in] float` sine of the angle of rotation. ```c -void c_drot( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ); +void c_srot( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ); +``` + +#### c_srot_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, c, s ) + +Applies a plane rotation using alternative indexing semantics. + +```c +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; +float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; + +c_srot_ndarray( 5, x, 1, 0, y, 1, 0, 0.8f, 0.6f ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[inout] float*` first input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] float*` second input array. +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. +- **c**: `[in] float` cosine of the angle of rotation. +- **s**: `[in] float` sine of the angle of rotation. + +```c +void c_srot_ndarray( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float c, const float s ); ``` @@ -249,7 +276,7 @@ void c_drot( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, con ### Examples ```c -#include "stdlib/blas/base/drot.h" +#include "stdlib/blas/base/srot.h" #include int main( void ) { @@ -258,18 +285,26 @@ int main( void ) { float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const float c = 0.8f; const float s = 0.6f; // Apply plane rotation: - c_drot( N, x, strideX, y, strideY, c, s ); + c_srot( N, x, strideX, y, strideY, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); + } + + // Apply plane rotation: + c_srot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); // Print the result: for ( int i = 0; i < 5; i++ ) { diff --git a/lib/node_modules/@stdlib/blas/base/srot/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/srot/benchmark/c/benchmark.length.c index a22d7420036..38eb59e16c5 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/srot/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 ]; float y[ len ]; @@ -120,6 +120,39 @@ 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 ]; + float y[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*200.0f ) - 100.0f; + y[ i ] = ( rand_float()*200.0f ) - 100.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_srot_ndarray( len, x, 1, 0, y, 1, 0, 0.8f, 0.6f ); + 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. */ @@ -142,7 +175,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/srot/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/srot/examples/c/example.c index c96100acbfa..83ae4d43220 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/srot/examples/c/example.c @@ -25,11 +25,11 @@ int main( void ) { float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; // Specify the number of elements: - const int N = 5; + const int N = 3; // Specify stride lengths: - const int strideX = 1; - const int strideY = 1; + const int strideX = 2; + const int strideY = -2; // Specify angle of rotation: const float c = 0.8f; @@ -42,4 +42,12 @@ int main( void ) { for ( int i = 0; i < 5; i++ ) { printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); } + + // Apply plane rotation: + c_srot_ndarray( N, x, strideX, 0, y, strideY, 4, c, s ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/srot/include/stdlib/blas/base/srot.h b/lib/node_modules/@stdlib/blas/base/srot/include/stdlib/blas/base/srot.h index af4bd0bbd97..4206771149a 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/include/stdlib/blas/base/srot.h +++ b/lib/node_modules/@stdlib/blas/base/srot/include/stdlib/blas/base/srot.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_srot)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ); +/** +* Applies a plane rotation using alternative indexing semantics. +*/ +void API_SUFFIX(c_srot_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float c, const float s ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/srot/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/srot/lib/ndarray.native.js index def0c29f9ae..f9994f4469b 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/srot/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './srot.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,10 +29,10 @@ var addon = require( './srot.native.js' ); * Applies a plane rotation. * * @param {PositiveInteger} N - number of indexed elements -* @param {Float32Array} x - input array +* @param {Float32Array} x - first input array * @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - starting `x` index -* @param {Float32Array} y - output array +* @param {Float32Array} y - second input array * @param {integer} strideY - `y` stride length * @param {NonNegativeInteger} offsetY - starting `y` index * @param {number} c - cosine of the angle of rotation @@ -52,16 +50,7 @@ var addon = require( './srot.native.js' ); * // y => [ 6.0, 4.4, ~4.6, ~4.8, 5.0 ] */ function srot( N, x, strideX, offsetX, y, strideY, offsetY, c, s ) { - var viewX; - var viewY; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - offsetY = minViewBufferIndex( N, strideY, offsetY ); - - viewX = offsetView( x, offsetX ); - viewY = offsetView( y, offsetY ); - - addon( N, viewX, strideX, viewY, strideY, c, s ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, c, s ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/srot/lib/srot.native.js b/lib/node_modules/@stdlib/blas/base/srot/lib/srot.native.js index 3d839031198..25273afce4b 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/lib/srot.native.js +++ b/lib/node_modules/@stdlib/blas/base/srot/lib/srot.native.js @@ -29,9 +29,9 @@ var addon = require( './../src/addon.node' ); * Applies a plane rotation. * * @param {PositiveInteger} N - number of indexed elements -* @param {Float32Array} x - input array +* @param {Float32Array} x - first input array * @param {integer} strideX - `x` stride length -* @param {Float32Array} y - output array +* @param {Float32Array} y - second input array * @param {integer} strideY - `y` stride length * @param {number} c - cosine of the angle of rotation * @param {number} s - sine of the angle of rotation diff --git a/lib/node_modules/@stdlib/blas/base/srot/manifest.json b/lib/node_modules/@stdlib/blas/base/srot/manifest.json index 508401f8d12..dd508f67a17 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/srot/manifest.json @@ -44,11 +44,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -57,7 +58,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -65,7 +67,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -74,7 +77,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -82,7 +86,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -104,11 +109,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -128,7 +134,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -148,7 +155,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -168,11 +176,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -181,7 +190,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -189,7 +199,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -198,7 +209,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -206,7 +218,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -227,11 +240,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -250,7 +264,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -269,7 +284,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -291,11 +307,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -315,7 +332,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -335,7 +353,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -345,7 +364,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -354,11 +374,12 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array" ] }, { @@ -367,7 +388,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -375,7 +397,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -384,7 +407,8 @@ "blas": "", "wasm": false, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -392,7 +416,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -402,7 +427,8 @@ "blas": "", "wasm": true, "src": [ - "./src/srot.c" + "./src/srot.c", + "./src/srot_ndarray.c" ], "include": [ "./include" @@ -410,7 +436,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/srot/src/addon.c b/lib/node_modules/@stdlib/blas/base/srot/src/addon.c index 47241243e2f..2498efd9360 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/srot/src/addon.c @@ -45,4 +45,26 @@ 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, 9 ); + 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_FLOAT( env, c, argv, 7 ); + STDLIB_NAPI_ARGV_FLOAT( env, s, argv, 8 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_srot_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY, c, s ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/srot/src/srot.c b/lib/node_modules/@stdlib/blas/base/srot/src/srot.c index 33378e215f8..cf5dc70c6d5 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/src/srot.c +++ b/lib/node_modules/@stdlib/blas/base/srot/src/srot.c @@ -18,53 +18,22 @@ #include "stdlib/blas/base/srot.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Applies a plane rotation. * * @param N number of indexed elements -* @param X input array +* @param X first input array * @param strideX X stride length -* @param Y output array +* @param Y second input array * @param strideY Y stride length * @param c cosine of the angle of rotation * @param s sine of the angle of rotation */ void API_SUFFIX(c_srot)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ) { - float tmp; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT i; - - if ( N <= 0 ) { - return; - } - // If both strides are equal to `1`... - if ( strideX == 1 && strideY == 1 ) { - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ i ] ) + ( s * Y[ i ] ); - Y[ i ] = ( c * Y[ i ] ) - ( s * X[ i ] ); - X[ i ] = tmp; - } - return; - } - // If both strides are not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); - Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); - X[ ix ] = tmp; - ix += strideX; - iy += strideY; - } + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_srot_ndarray)( N, X, strideX, ox, Y, strideY, oy, c, s ); return; } diff --git a/lib/node_modules/@stdlib/blas/base/srot/src/srot.f b/lib/node_modules/@stdlib/blas/base/srot/src/srot.f index 9c52b0becf8..77d006369f6 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/src/srot.f +++ b/lib/node_modules/@stdlib/blas/base/srot/src/srot.f @@ -48,9 +48,9 @@ ! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. ! ! @param {integer} N - number of indexed elements -! @param {Array} sx - input array +! @param {Array} sx - first input array ! @param {integer} strideX - `sx` stride length -! @param {Array} sy - output array +! @param {Array} sy - second input array ! @param {integer} strideY - `sy` stride length ! @param {real} c - cosine of the angle of rotation ! @param {real} s - sine of the angle of rotation diff --git a/lib/node_modules/@stdlib/blas/base/srot/src/srot_cblas.c b/lib/node_modules/@stdlib/blas/base/srot/src/srot_cblas.c index 5f0a6590253..3260ba84a1b 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/src/srot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/srot/src/srot_cblas.c @@ -19,14 +19,15 @@ #include "stdlib/blas/base/srot.h" #include "stdlib/blas/base/srot_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. * * @param N number of indexed elements -* @param X input array +* @param X first input array * @param strideX X stride length -* @param Y output array +* @param Y second input array * @param strideY Y stride length * @param c cosine of the angle of rotation * @param s sine of the angle of rotation @@ -34,3 +35,22 @@ void API_SUFFIX(c_srot)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ) { API_SUFFIX(cblas_srot)( N, X, strideX, Y, strideY, c, s ); } + +/** +* Applies a plane rotation 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 +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_srot_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float c, const float s ) { + 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_srot)( N, alpha, X, strideX, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/srot/src/srot_f.c b/lib/node_modules/@stdlib/blas/base/srot/src/srot_f.c index 3e70a4e3b74..50519f152ba 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/src/srot_f.c +++ b/lib/node_modules/@stdlib/blas/base/srot/src/srot_f.c @@ -19,14 +19,15 @@ #include "stdlib/blas/base/srot.h" #include "stdlib/blas/base/srot_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Applies a plane rotation. * * @param N number of indexed elements -* @param X input array +* @param X first input array * @param strideX X stride length -* @param Y output array +* @param Y second input array * @param strideY Y stride length * @param c cosine of the angle of rotation * @param s sine of the angle of rotation @@ -34,3 +35,22 @@ void API_SUFFIX(c_srot)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float c, const float s ) { srot( &N, X, &strideX, Y, &strideY, &c, &s ); } + +/** +* Applies a plane rotation 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 +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_srot_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float c, const float s ) { + 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 + srot( &N, X, &strideX, Y, &strideY, &c, &s ); +} diff --git a/lib/node_modules/@stdlib/blas/base/srot/src/srot_ndarray.c b/lib/node_modules/@stdlib/blas/base/srot/src/srot_ndarray.c new file mode 100644 index 00000000000..aa98cbe5b62 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/srot/src/srot_ndarray.c @@ -0,0 +1,54 @@ +/** +* @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/srot.h" +#include "stdlib/blas/base/shared.h" + +/** +* Applies a plane rotation 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` +* @param c cosine of the angle of rotation +* @param s sine of the angle of rotation +*/ +void API_SUFFIX(c_srot_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const float c, const float s ) { + float tmp; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; + + if ( N <= 0 ) { + return; + } + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + tmp = ( c * X[ ix ] ) + ( s * Y[ iy ] ); + Y[ iy ] = ( c * Y[ iy ] ) - ( s * X[ ix ] ); + X[ ix ] = tmp; + ix += strideX; + iy += strideY; + } + return; +}