From 25485308798acc772305b6fe38cb1c89e69f7ee1 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Sun, 20 Sep 2026 22:02:31 +0530 Subject: [PATCH] feat: add C implementation for `blas/ext/base/ndarray/zzero-to` --- .../blas/ext/base/ndarray/zzero-to/README.md | 148 +++++++++ .../ndarray/zzero-to/benchmark/benchmark.js | 2 +- .../zzero-to/benchmark/benchmark.native.js | 104 ++++++ .../ndarray/zzero-to/benchmark/c/Makefile | 146 +++++++++ .../zzero-to/benchmark/c/benchmark.length.c | 170 ++++++++++ .../ext/base/ndarray/zzero-to/binding.gyp | 170 ++++++++++ .../base/ndarray/zzero-to/examples/c/Makefile | 146 +++++++++ .../ndarray/zzero-to/examples/c/example.c | 76 +++++ .../ext/base/ndarray/zzero-to/include.gypi | 53 ++++ .../stdlib/blas/ext/base/ndarray/zzero_to.h | 40 +++ .../ext/base/ndarray/zzero-to/lib/index.js | 16 +- .../ext/base/ndarray/zzero-to/lib/native.js | 61 ++++ .../ext/base/ndarray/zzero-to/manifest.json | 112 +++++++ .../ext/base/ndarray/zzero-to/package.json | 4 + .../ext/base/ndarray/zzero-to/src/Makefile | 70 ++++ .../ext/base/ndarray/zzero-to/src/addon.c | 61 ++++ .../blas/ext/base/ndarray/zzero-to/src/main.c | 39 +++ .../ext/base/ndarray/zzero-to/test/test.js | 269 ++-------------- .../base/ndarray/zzero-to/test/test.main.js | 290 +++++++++++++++++ .../base/ndarray/zzero-to/test/test.native.js | 299 ++++++++++++++++++ 20 files changed, 2033 insertions(+), 243 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/binding.gyp create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/include.gypi create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/include/stdlib/blas/ext/base/ndarray/zzero_to.h create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/lib/native.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/src/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/src/addon.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/src/main.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/test/test.native.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/README.md index 640f49fcab12..c614906b975d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zzero-to/README.md @@ -89,6 +89,154 @@ console.log( ndarray2array( x ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/zzero_to.h" +``` + +#### stdlib_blas_ext_zzero_to( arrays ) + +Fills a one-dimensional double-precision complex floating-point ndarray with linearly spaced numeric elements which increment by `1` starting from zero. + +```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 an ndarray: +double data[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; +int64_t shape[] = { 4 }; +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 *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Fill the ndarray: +const struct ndarray *arrays[] = { x }; +stdlib_blas_ext_zzero_to( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +``` + +The function accepts the following arguments: + +- **arrays**: `[inout] struct ndarray**` list containing a one-dimensional input ndarray. + +```c +void stdlib_blas_ext_zzero_to( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/zzero_to.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 a data buffer: + double data[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of array dimensions: + const int64_t ndims = 1; + + // Specify the array shape: + int64_t shape[] = { 4 }; + + // 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: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x }; + + // Fill the ndarray: + stdlib_blas_ext_zzero_to( arrays ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "data[ %i ] = %lf\n", i, data[ i ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); +} +``` + +
+ + + +
+ + +