From 62d23704ead2a49cefa8e97314fde47e03d62922 Mon Sep 17 00:00:00 2001 From: Samarth Kolarkar Date: Sun, 11 Oct 2026 14:13:55 +0530 Subject: [PATCH] feat: add C implementation for `blas/ext/base/ndarray/zxmy` --- .../blas/ext/base/ndarray/zxmy/README.md | 164 +++++++++ .../base/ndarray/zxmy/benchmark/benchmark.js | 2 +- .../zxmy/benchmark/benchmark.native.js | 117 ++++++ .../base/ndarray/zxmy/benchmark/c/Makefile | 146 ++++++++ .../zxmy/benchmark/c/benchmark.length.c | 205 +++++++++++ .../blas/ext/base/ndarray/zxmy/binding.gyp | 265 ++++++++++++++ .../ext/base/ndarray/zxmy/examples/c/Makefile | 146 ++++++++ .../base/ndarray/zxmy/examples/c/example.c | 88 +++++ .../blas/ext/base/ndarray/zxmy/include.gypi | 53 +++ .../stdlib/blas/ext/base/ndarray/zxmy.h | 40 ++ .../blas/ext/base/ndarray/zxmy/lib/index.js | 16 +- .../blas/ext/base/ndarray/zxmy/lib/native.js | 67 ++++ .../blas/ext/base/ndarray/zxmy/manifest.json | 119 ++++++ .../blas/ext/base/ndarray/zxmy/package.json | 4 + .../blas/ext/base/ndarray/zxmy/src/Makefile | 70 ++++ .../blas/ext/base/ndarray/zxmy/src/addon.c | 64 ++++ .../blas/ext/base/ndarray/zxmy/src/main.c | 51 +++ .../blas/ext/base/ndarray/zxmy/test/test.js | 312 ++-------------- .../ext/base/ndarray/zxmy/test/test.main.js | 333 +++++++++++++++++ .../ext/base/ndarray/zxmy/test/test.native.js | 342 ++++++++++++++++++ 20 files changed, 2318 insertions(+), 286 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/include/stdlib/blas/ext/base/ndarray/zxmy.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/test/test.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/README.md index 2ebce943e90b..87fa5e4e7dbc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zxmy/README.md @@ -113,6 +113,170 @@ console.log( ndarray2array( y ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/zxmy.h" +``` + +#### stdlib_blas_ext_zxmy( arrays ) + +Multiplies elements of a one-dimensional double-precision complex floating-point ndarray by the corresponding elements of a second one-dimensional double-precision complex floating-point ndarray and assigns the results to the second 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, 1.0, 2.0, -1.0, 3.0, 0.0 }; +double dataY[] = { 2.0, 1.0, 1.0, 2.0, 2.0, -2.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 ); + +// Perform computation: +const struct ndarray *arrays[] = { x, y }; +stdlib_blas_ext_zxmy( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( y ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a one-dimensional input ndarray. + - `[inout] struct ndarray*` a one-dimensional output ndarray. + +```c +void stdlib_blas_ext_zxmy( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/zxmy.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, -4.0, 5.0, -6.0, 7.0, -8.0, 9.0, -10.0, 11.0, -12.0, 13.0, -14.0, 15.0, -16.0 }; + double dataY[] = { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0 }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 8 }; + + // 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 an ndarray for x: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + + // Create an ndarray for y: + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + + if ( x == NULL || y == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, y }; + + // Perform computation: + stdlib_blas_ext_zxmy( arrays ); + + // Print the result: + const stdlib_complex128_t *v = (const stdlib_complex128_t *)dataY; + for ( int i = 0; i < 8; i++ ) { + printf( "y[ %i ] = %f + %fi\n", i, stdlib_complex128_real( v[ i ] ), stdlib_complex128_imag( v[ i ] ) ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); +} +``` + +
+ + + +
+ + +