diff --git a/lib/node_modules/@stdlib/blas/base/dswap/README.md b/lib/node_modules/@stdlib/blas/base/dswap/README.md index 42da74c2a04..546fb164219 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/README.md +++ b/lib/node_modules/@stdlib/blas/base/dswap/README.md @@ -195,10 +195,10 @@ console.log( y ); Interchanges two double-precision floating-point vectors. ```c -double x[] = { 1.0, 2.0, 3.0, 4.0 }; -double y[] = { 0.0, 0.0, 0.0, 0.0 }; +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_dswap( 4, x, 1, y, 1 ); +c_dswap( 5, x, 1, y, 1 ); ``` The function accepts the following arguments: @@ -206,13 +206,38 @@ 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`. -- **Y**: `[inout] double*` first input array. +- **Y**: `[inout] double*` second input array. - **strideY**: `[in] CBLAS_INT` index increment for `Y`. ```c void c_dswap( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ); ``` +#### c_dswap_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Interchanges two double-precision floating-point vectors 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_dswap_ndarray( 3, x, 1, 2, y, 1, 2 ); +``` + +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 +void c_dswap_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 ); +``` + @@ -240,7 +265,7 @@ int main( void ) { double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - // Specify the number of elements: + // Specify the number of indexed elements: const int N = 4; // Specify stride lengths: @@ -255,6 +280,15 @@ int main( void ) { printf( "x[ %i ] = %lf\n", i, x[ i ] ); printf( "y[ %i ] = %lf\n", i, y[ i ] ); } + + // Interchange elements: + c_dswap_ndarray( N, x, strideX, 0, y, strideY, 6 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } } ``` @@ -270,15 +304,6 @@ int main( void ) { @@ -295,18 +320,6 @@ int main( void ) { [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray - - -[@stdlib/blas/base/dcopy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dcopy - -[@stdlib/blas/base/gswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/gswap - -[@stdlib/blas/base/sswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sswap - -[@stdlib/blas/dswap]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/dswap - - - diff --git a/lib/node_modules/@stdlib/blas/base/dswap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/dswap/benchmark/c/benchmark.length.c index b3057bbc4ec..1f2541c34d8 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/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()*20000.0 ) - 10000.0; + y[ i ] = 0.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_dswap_ndarray( len, x, 1, 0, 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. */ @@ -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/dswap/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/dswap/examples/c/example.c index 5ffb03731b6..2ef19491fa4 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/examples/c/example.c @@ -39,4 +39,13 @@ int main( void ) { printf( "x[ %i ] = %lf\n", i, x[ i ] ); printf( "y[ %i ] = %lf\n", i, y[ i ] ); } + + // Interchange elements: + c_dswap_ndarray( N, x, strideX, 0, y, strideY, 6 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/dswap/include/stdlib/blas/base/dswap.h b/lib/node_modules/@stdlib/blas/base/dswap/include/stdlib/blas/base/dswap.h index 36cab65ebde..e54f17c4cf7 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/include/stdlib/blas/base/dswap.h +++ b/lib/node_modules/@stdlib/blas/base/dswap/include/stdlib/blas/base/dswap.h @@ -36,6 +36,11 @@ extern "C" { */ void API_SUFFIX(c_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ); +/** +* Interchanges two double-precision floating-point vectors using alternative indexing semantics. +*/ +void API_SUFFIX(c_dswap_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 ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/blas/base/dswap/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/dswap/lib/ndarray.native.js index 58df968b864..066efbc7644 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/dswap/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( './dswap.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -50,16 +48,7 @@ var addon = require( './dswap.native.js' ); * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ function dswap( N, x, strideX, offsetX, y, strideY, offsetY ) { - 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 ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/dswap/manifest.json b/lib/node_modules/@stdlib/blas/base/dswap/manifest.json index 21453fdd9eb..2d5bf561258 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/dswap/manifest.json @@ -44,6 +44,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -56,7 +57,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -64,7 +66,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -73,7 +76,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -81,7 +85,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -103,6 +108,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -126,7 +132,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -146,7 +153,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -166,6 +174,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -178,7 +187,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -186,7 +196,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -195,7 +206,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -203,7 +215,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -224,6 +237,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -246,7 +260,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -265,7 +280,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -287,6 +303,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -310,7 +327,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, { @@ -330,7 +348,8 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" ] }, @@ -340,7 +359,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -349,6 +369,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -361,7 +382,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -369,7 +391,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -378,7 +401,8 @@ "blas": "", "wasm": false, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -386,7 +410,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, @@ -396,7 +421,8 @@ "blas": "", "wasm": true, "src": [ - "./src/dswap.c" + "./src/dswap.c", + "./src/dswap_ndarray.c" ], "include": [ "./include" @@ -404,7 +430,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/dswap/src/addon.c b/lib/node_modules/@stdlib/blas/base/dswap/src/addon.c index 70ba684d6dd..936450167c0 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/src/addon.c @@ -43,4 +43,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_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_dswap_ndarray)( N, X, strideX, offsetX, 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/dswap/src/dswap.c b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap.c index fcfacf2f24a..1789083a693 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap.c @@ -18,6 +18,7 @@ #include "stdlib/blas/base/dswap.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Interchanges two double-precision floating-point vectors. @@ -29,61 +30,7 @@ * @param strideY Y stride length */ void API_SUFFIX(c_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ) { - double tmp; - CBLAS_INT ix; - CBLAS_INT iy; - CBLAS_INT i; - CBLAS_INT m; - - if ( N <= 0 ) { - return; - } - // If both strides are equal to `1`, use unrolled loops... - if ( strideX == 1 && strideY == 1 ) { - m = N % 3; - - // If we have a remainder, do a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - tmp = X[ i ]; - X[ i ] = Y[ i ]; - Y[ i ] = tmp; - } - if ( N < 3 ) { - return; - } - } - for ( i = m; i < N; i += 3 ) { - tmp = X[ i ]; - X[ i ] = Y[ i ]; - Y[ i ] = tmp; - - tmp = X[ i+1 ]; - X[ i+1 ] = Y[ i+1 ]; - Y[ i+1 ] = tmp; - - tmp = X[ i+2 ]; - X[ i+2 ] = Y[ i+2 ]; - Y[ i+2 ] = tmp; - } - return; - } - 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 = X[ ix ]; - X[ ix ] = Y[ iy ]; - Y[ iy ] = tmp; - ix += strideX; - iy += strideY; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_dswap_ndarray)( N, X, strideX, ox, Y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_cblas.c b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_cblas.c index 3076bbc268f..57d5e43bde2 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_cblas.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dswap.h" #include "stdlib/blas/base/dswap_cblas.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two double-precision floating-point vectors. @@ -32,3 +33,20 @@ void API_SUFFIX(c_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ) { API_SUFFIX(cblas_dswap)( N, X, strideX, Y, strideY ); } + +/** +* Interchanges two double-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_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + 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_dswap)( N, alpha, X, strideX, Y, strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_f.c b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_f.c index 01d8b9ad9a6..0cc1d5dc762 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_f.c +++ b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_f.c @@ -19,6 +19,7 @@ #include "stdlib/blas/base/dswap.h" #include "stdlib/blas/base/dswap_fortran.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two double-precision floating-point vectors. @@ -32,3 +33,20 @@ void API_SUFFIX(c_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ) { dswap( &N, X, &strideX, Y, &strideY ); } + +/** +* Interchanges two double-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_dswap_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 ) { + 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 + dswap( &N, X, &strideX, Y, &strideY ); +} diff --git a/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_ndarray.c b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_ndarray.c new file mode 100644 index 00000000000..01c41488ac1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dswap/src/dswap_ndarray.c @@ -0,0 +1,91 @@ +/** +* @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/dswap.h" +#include "stdlib/blas/base/shared.h" + +static const CBLAS_INT M = 3; + +/** +* Interchanges two 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_dswap_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 ) { + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; + CBLAS_INT m; + double tmp; + + if ( N <= 0 ) { + return; + } + ix = offsetX; + iy = offsetY; + + // If both strides are equal to `1`, use unrolled loops... + if ( strideX == 1 && strideY == 1 ) { + m = N % M; + + // If we have a remainder, do a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + ix += strideX; + iy += strideY; + } + if ( N < M ) { + return; + } + } + for ( i = m; i < N; i += M ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + + tmp = X[ ix+1 ]; + X[ ix+1 ] = Y[ iy+1 ]; + Y[ iy+1 ] = tmp; + + tmp = X[ ix+2 ]; + X[ ix+2 ] = Y[ iy+2 ]; + Y[ iy+2 ] = tmp; + + ix += M; + iy += M; + } + return; + } + for ( i = 0; i < N; i++ ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + ix += strideX; + iy += strideY; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/sswap/README.md b/lib/node_modules/@stdlib/blas/base/sswap/README.md index ad6bebc7770..c93c69742ef 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/README.md +++ b/lib/node_modules/@stdlib/blas/base/sswap/README.md @@ -164,18 +164,145 @@ console.log( y ); - - - diff --git a/lib/node_modules/@stdlib/blas/base/sswap/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/sswap/benchmark/c/benchmark.length.c index 0d6a2307b09..45bedb22694 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/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()*20000.0f ) - 10000.0f; + y[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_sswap_ndarray( len, x, 1, 0, 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. */ @@ -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/sswap/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/sswap/examples/c/example.c index 44c16105cb1..0fbfc329fe1 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/examples/c/example.c @@ -39,4 +39,13 @@ int main( void ) { printf( "x[ %i ] = %f\n", i, x[ i ] ); printf( "y[ %i ] = %f\n", i, y[ i ] ); } + + // Interchange elements: + c_sswap_ndarray( N, x, strideX, 0, y, strideY, 6 ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + printf( "y[ %i ] = %f\n", i, y[ i ] ); + } } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap.h b/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap.h index 6216a3e95a2..fa1f7884099 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap.h +++ b/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap.h @@ -22,6 +22,8 @@ #ifndef SSWAP_H #define SSWAP_H +#include "stdlib/blas/base/shared.h" + /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -32,7 +34,12 @@ extern "C" { /** * Interchanges two single-precision floating-point vectors. */ -void c_sswap( const int N, float *X, const int strideX, float *Y, const int strideY ); +void API_SUFFIX(c_sswap)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); + +/** +* Interchanges two single-precision floating-point vectors using alternative indexing semantics. +*/ +void API_SUFFIX(c_sswap_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 ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap_cblas.h b/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap_cblas.h index 3de91f8158e..4f289795b37 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap_cblas.h +++ b/lib/node_modules/@stdlib/blas/base/sswap/include/stdlib/blas/base/sswap_cblas.h @@ -22,6 +22,8 @@ #ifndef SSWAP_CBLAS_H #define SSWAP_CBLAS_H +#include "stdlib/blas/base/shared.h" + /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -32,7 +34,7 @@ extern "C" { /** * Interchanges two single-precision floating-point vectors. */ -void cblas_sswap( const int N, float *X, const int strideX, float *Y, const int strideY ); +void API_SUFFIX(cblas_sswap)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/sswap/lib/ndarray.native.js index cf9c48523c0..4f7a2a49509 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/sswap/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( './sswap.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -50,16 +48,7 @@ var addon = require( './sswap.native.js' ); * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ function sswap( N, x, strideX, offsetX, y, strideY, offsetY ) { - 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 ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ); return y; } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/manifest.json b/lib/node_modules/@stdlib/blas/base/sswap/manifest.json index 36a7b9f830e..7b72218bd32 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/sswap/manifest.json @@ -43,6 +43,8 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -55,14 +57,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", @@ -70,14 +76,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { @@ -97,6 +107,8 @@ ], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -119,7 +131,10 @@ "-lpthread" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { "task": "examples", @@ -137,7 +152,10 @@ "-lpthread" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { @@ -155,6 +173,8 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -167,14 +187,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", @@ -182,14 +206,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { @@ -208,6 +236,8 @@ ], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -229,7 +259,10 @@ "-lblas" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { "task": "examples", @@ -246,7 +279,10 @@ "-lblas" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { @@ -266,6 +302,8 @@ ], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -288,7 +326,10 @@ "-lpthread" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { "task": "examples", @@ -306,7 +347,10 @@ "-lpthread" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index" + ] }, { @@ -315,7 +359,8 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" @@ -323,6 +368,8 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -335,14 +382,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", @@ -350,14 +401,18 @@ "blas": "", "wasm": false, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { @@ -366,14 +421,18 @@ "blas": "", "wasm": true, "src": [ - "./src/sswap.c" + "./src/sswap.c", + "./src/sswap_ndarray.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/src/addon.c b/lib/node_modules/@stdlib/blas/base/sswap/src/addon.c index b9da62c79c9..d4af667af80 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/base/sswap.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,28 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 4 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 3 ); - c_sswap( N, X, strideX, Y, strideY ); + API_SUFFIX(c_sswap)( N, X, strideX, Y, strideY ); 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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(c_sswap_ndarray)( N, X, strideX, offsetX, 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/sswap/src/sswap.c b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap.c index 299402caf71..9a343524b4f 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap.c @@ -17,6 +17,8 @@ */ #include "stdlib/blas/base/sswap.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Interchanges two single-precision floating-point vectors. @@ -27,62 +29,9 @@ * @param Y second input array * @param strideY Y stride length */ -void c_sswap( const int N, float *X, const int strideX, float *Y, const int strideY ) { - float tmp; - int ix; - int iy; - int i; - int m; +void API_SUFFIX(c_sswap)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { - if ( N <= 0 ) { - return; - } - // If both strides are equal to `1`, use unrolled loops... - if ( strideX == 1 && strideY == 1 ) { - m = N % 3; - - // If we have a remainder, do a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - tmp = X[ i ]; - X[ i ] = Y[ i ]; - Y[ i ] = tmp; - } - if ( N < 3 ) { - return; - } - } - for ( i = m; i < N; i += 3 ) { - tmp = X[ i ]; - X[ i ] = Y[ i ]; - Y[ i ] = tmp; - - tmp = X[ i+1 ]; - X[ i+1 ] = Y[ i+1 ]; - Y[ i+1 ] = tmp; - - tmp = X[ i+2 ]; - X[ i+2 ] = Y[ i+2 ]; - Y[ i+2 ] = tmp; - } - return; - } - 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 = X[ ix ]; - X[ ix ] = Y[ iy ]; - Y[ iy ] = tmp; - ix += strideX; - iy += strideY; - } - return; + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(c_sswap_ndarray)( N, X, strideX, ox, Y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_cblas.c b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_cblas.c index 93b4e650564..792a8ebdc3b 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_cblas.c @@ -18,6 +18,8 @@ #include "stdlib/blas/base/sswap.h" #include "stdlib/blas/base/sswap_cblas.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two single-precision floating-point vectors. @@ -28,6 +30,23 @@ * @param Y second input array * @param strideY Y stride length */ -void c_sswap( const int N, float *X, const int strideX, float *Y, const int strideY ) { - cblas_sswap( N, X, strideX, Y, strideY ); +void API_SUFFIX(c_sswap)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { + API_SUFFIX(cblas_sswap)( N, X, strideX, Y, strideY ); +} + +/** +* Interchanges two 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_sswap_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 ) { + 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_sswap)( N, alpha, X, strideX, Y, strideY ); } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_f.c b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_f.c index 460952fe52b..4766d1a2b25 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_f.c +++ b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_f.c @@ -18,6 +18,8 @@ #include "stdlib/blas/base/sswap.h" #include "stdlib/blas/base/sswap_fortran.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Interchanges two single-precision floating-point vectors. @@ -28,6 +30,23 @@ * @param Y second input array * @param strideY Y stride length */ -void c_sswap( const int N, float *X, const int strideX, float *Y, const int strideY ) { +void API_SUFFIX(c_sswap)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { + sswap( &N, X, &strideX, Y, &strideY ); +} + +/** +* Interchanges two 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_sswap_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 ) { + 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 sswap( &N, X, &strideX, Y, &strideY ); } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_ndarray.c b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_ndarray.c new file mode 100644 index 00000000000..68fcf668407 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/sswap/src/sswap_ndarray.c @@ -0,0 +1,91 @@ +/** +* @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/sswap.h" +#include "stdlib/blas/base/shared.h" + +static const CBLAS_INT M = 3; + +/** +* Interchanges two 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_sswap_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 ) { + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; + CBLAS_INT m; + float tmp; + + if ( N <= 0 ) { + return; + } + ix = offsetX; + iy = offsetY; + + // If both strides are equal to `1`, use unrolled loops... + if ( strideX == 1 && strideY == 1 ) { + m = N % M; + + // If we have a remainder, do a clean-up loop... + if ( m > 0 ) { + for ( i = 0; i < m; i++ ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + ix += strideX; + iy += strideY; + } + if ( N < M ) { + return; + } + } + for ( i = m; i < N; i += M ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + + tmp = X[ ix+1 ]; + X[ ix+1 ] = Y[ iy+1 ]; + Y[ iy+1 ] = tmp; + + tmp = X[ ix+2 ]; + X[ ix+2 ] = Y[ iy+2 ]; + Y[ iy+2 ] = tmp; + + ix += M; + iy += M; + } + return; + } + for ( i = 0; i < N; i++ ) { + tmp = X[ ix ]; + X[ ix ] = Y[ iy ]; + Y[ iy ] = tmp; + ix += strideX; + iy += strideY; + } + return; +}