diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwax/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwax/README.md index c2a142bd1475..a0f5ea389e21 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwax/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/zwax/README.md @@ -112,6 +112,187 @@ console.log( ndarray2array( w ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/zwax.h" +``` + +#### stdlib_blas_ext_zwax( arrays ) + +Multiplies each element in an input one-dimensional double-precision complex floating-point ndarray by a scalar constant and assigns the results to elements in a one-dimensional double-precision complex floating-point output ndarray. + +```c +#include "stdlib/complex/float64/ctor.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 + +// Create ndarrays: +const double dataX[] = { -2.0, 1.0, 3.0, -5.0 }; +double dataW[] = { 0.0, 0.0, 0.0, 0.0 }; +int64_t shape[] = { 2 }; +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 *w = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)dataW, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Create an ndarray containing the scalar constant to multiply: +const double adata[] = { 5.0, 0.0 }; +int64_t astrides[] = { 0 }; + +struct ndarray *alpha = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)adata, 0, NULL, astrides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Perform computation: +const struct ndarray *arrays[] = { x, w, alpha }; +stdlib_blas_ext_zwax( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( w ); +stdlib_ndarray_free( alpha ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a one-dimensional input ndarray. + - `[out] struct ndarray*` a one-dimensional output ndarray. + - `[in] struct ndarray*` a zero-dimensional ndarray containing the scalar constant to multiply. + +```c +void stdlib_blas_ext_zwax( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/zwax.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[] = { -2.0, 1.0, 3.0, -5.0 }; + double dataW[] = { 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[] = { 2 }; + + // 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 *w = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)dataW, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + + // Create a data buffer for an ndarray containing the scalar constant to multiply: + const double adata[] = { 5.0, 0.0 }; + + // Specify the array strides for a zero-dimensional ndarray: + int64_t astrides[] = { 0 }; + + // Create an ndarray containing the scalar constant to multiply: + struct ndarray *alpha = stdlib_ndarray_allocate( STDLIB_NDARRAY_COMPLEX128, (uint8_t *)adata, 0, NULL, astrides, 0, order, imode, nsubmodes, submodes ); + if ( x == NULL || w == NULL || alpha == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, w, alpha }; + + // Perform computation: + stdlib_blas_ext_zwax( arrays ); + + // Print the result: + const stdlib_complex128_t *v = (const stdlib_complex128_t *)dataW; + for ( int i = 0; i < 2; 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( w ); + stdlib_ndarray_free( alpha ); +} +``` + +
+ + + +
+ + +