From 116964ae6f3207c8170770f376cc1332a42c3d25 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Tue, 13 Oct 2026 13:09:57 +0530 Subject: [PATCH] feat: add C implementation for `blas/ext/base/ndarray/swxmy` --- .../blas/ext/base/ndarray/swxmy/README.md | 165 ++++++++++ .../base/ndarray/swxmy/benchmark/benchmark.js | 2 +- .../swxmy/benchmark/benchmark.native.js | 109 +++++++ .../base/ndarray/swxmy/benchmark/c/Makefile | 146 +++++++++ .../swxmy/benchmark/c/benchmark.length.c | 209 ++++++++++++ .../blas/ext/base/ndarray/swxmy/binding.gyp | 265 +++++++++++++++ .../base/ndarray/swxmy/examples/c/Makefile | 146 +++++++++ .../base/ndarray/swxmy/examples/c/example.c | 87 +++++ .../blas/ext/base/ndarray/swxmy/include.gypi | 53 +++ .../stdlib/blas/ext/base/ndarray/swxmy.h | 40 +++ .../blas/ext/base/ndarray/swxmy/lib/index.js | 16 +- .../blas/ext/base/ndarray/swxmy/lib/native.js | 66 ++++ .../blas/ext/base/ndarray/swxmy/manifest.json | 109 +++++++ .../blas/ext/base/ndarray/swxmy/package.json | 4 + .../blas/ext/base/ndarray/swxmy/src/Makefile | 70 ++++ .../blas/ext/base/ndarray/swxmy/src/addon.c | 67 ++++ .../blas/ext/base/ndarray/swxmy/src/main.c | 55 ++++ .../blas/ext/base/ndarray/swxmy/test/test.js | 271 ++-------------- .../ext/base/ndarray/swxmy/test/test.main.js | 292 +++++++++++++++++ .../base/ndarray/swxmy/test/test.native.js | 301 ++++++++++++++++++ 20 files changed, 2228 insertions(+), 245 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/include/stdlib/blas/ext/base/ndarray/swxmy.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/test/test.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/README.md index 8cb471257a47..7998b71d0aa2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/swxmy/README.md @@ -112,6 +112,171 @@ console.log( ndarray2array( w ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/swxmy.h" +``` + +#### stdlib_blas_ext_swxmy( arrays ) + +Multiplies elements of a one-dimensional single-precision floating-point ndarray by the corresponding elements of a second one-dimensional single-precision floating-point ndarray and assigns the results to elements in a third one-dimensional single-precision floating-point ndarray. + +```c +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include + +// Create ndarrays: +const float dataX[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; +const float dataY[] = { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }; +float dataW[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; +int64_t shape[] = { 5 }; +int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataX, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); +struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataY, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); +struct ndarray *w = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataW, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Perform computation: +const struct ndarray *arrays[] = { x, y, w }; +stdlib_blas_ext_swxmy( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( y ); +stdlib_ndarray_free( w ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` first one-dimensional input ndarray. + - `[in] struct ndarray*` second one-dimensional input ndarray. + - `[out] struct ndarray*` a one-dimensional output ndarray. + +```c +void stdlib_blas_ext_swxmy( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/swxmy.h" +#include "stdlib/ndarray/ctor.h" +#include "stdlib/ndarray/dtypes.h" +#include "stdlib/ndarray/index_modes.h" +#include "stdlib/ndarray/orders.h" +#include "stdlib/ndarray/base/bytes_per_element.h" +#include +#include +#include + +int main( void ) { + // Create data buffers: + const float dataX[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; + const float dataY[] = { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }; + float dataW[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 5 }; + + // Specify the array strides: + int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; + + // Specify the byte offset: + const int64_t offset = 0; + + // Specify the array order: + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + + // Specify the index mode: + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + + // Specify the subscript index modes: + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 1; + + // Create ndarrays: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + struct ndarray *w = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataW, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + + if ( x == NULL || y == NULL || w == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, y, w }; + + // Perform computation: + stdlib_blas_ext_swxmy( arrays ); + + // Print the result: + for ( int i = 0; i < 5; i++ ) { + printf( "w[ %i ] = %f\n", i, dataW[ i ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); + stdlib_ndarray_free( w ); +} +``` + +
+ + + +
+ + +