From 67ae31c74fc3d5efacb5ba47a99e08b31f0ab251 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Thu, 15 Oct 2026 00:15:41 +0530 Subject: [PATCH] feat: add C implementation for `blas/ext/base/ndarray/zwxsy` --- .../blas/ext/base/ndarray/zwxsy/README.md | 169 +++++++++ .../base/ndarray/zwxsy/benchmark/benchmark.js | 2 +- .../zwxsy/benchmark/benchmark.native.js | 119 ++++++ .../base/ndarray/zwxsy/benchmark/c/Makefile | 146 ++++++++ .../zwxsy/benchmark/c/benchmark.length.c | 216 +++++++++++ .../blas/ext/base/ndarray/zwxsy/binding.gyp | 265 +++++++++++++ .../base/ndarray/zwxsy/examples/c/Makefile | 146 ++++++++ .../base/ndarray/zwxsy/examples/c/example.c | 92 +++++ .../blas/ext/base/ndarray/zwxsy/include.gypi | 53 +++ .../stdlib/blas/ext/base/ndarray/zwxsy.h | 40 ++ .../blas/ext/base/ndarray/zwxsy/lib/index.js | 16 +- .../blas/ext/base/ndarray/zwxsy/lib/native.js | 67 ++++ .../blas/ext/base/ndarray/zwxsy/manifest.json | 119 ++++++ .../blas/ext/base/ndarray/zwxsy/package.json | 4 + .../blas/ext/base/ndarray/zwxsy/src/Makefile | 70 ++++ .../blas/ext/base/ndarray/zwxsy/src/addon.c | 67 ++++ .../blas/ext/base/ndarray/zwxsy/src/main.c | 56 +++ .../blas/ext/base/ndarray/zwxsy/test/test.js | 324 ++-------------- .../ext/base/ndarray/zwxsy/test/test.main.js | 345 +++++++++++++++++ .../base/ndarray/zwxsy/test/test.native.js | 354 ++++++++++++++++++ 20 files changed, 2372 insertions(+), 298 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/include/stdlib/blas/ext/base/ndarray/zwxsy.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/test/test.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/README.md index 632e77206dbb..7670387a144f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwxsy/README.md @@ -116,6 +116,175 @@ console.log( ndarray2array( w ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/zwxsy.h" +``` + +#### stdlib_blas_ext_zwxsy( arrays ) + +Subtracts elements of a second one-dimensional double-precision complex floating-point ndarray from the corresponding elements of a first one-dimensional double-precision complex floating-point ndarray and assigns the results to elements in a third one-dimensional double-precision complex 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 double dataX[] = { 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 }; +const double dataY[] = { 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 }; +double dataW[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; +int64_t shape[] = { 3 }; +int64_t strides[] = { STDLIB_NDARRAY_COMPLEX128_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (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_COMPLEX128, (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_COMPLEX128, (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_zwxsy( 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_zwxsy( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/zwxsy.h" +#include "stdlib/complex/float64/ctor.h" +#include "stdlib/complex/float64/real.h" +#include "stdlib/complex/float64/imag.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 double dataX[] = { 1.0, 2.0, 3.0, -1.0, 0.0, 1.0 }; + const double dataY[] = { 2.0, 1.0, -1.0, 3.0, 4.0, 0.0 }; + double dataW[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 3 }; + + // Specify the array strides: + int64_t strides[] = { STDLIB_NDARRAY_COMPLEX128_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_COMPLEX128, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + struct ndarray *w = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (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_zwxsy( arrays ); + + // Print the result: + const stdlib_complex128_t *v = (const stdlib_complex128_t *)dataW; + for ( int i = 0; i < 3; i++ ) { + printf( "w[ %i ] = %lf + %lfi\n", i, stdlib_complex128_real( v[ i ] ), stdlib_complex128_imag( v[ i ] ) ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); + stdlib_ndarray_free( w ); +} +``` + +
+ + + +
+ + +