diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-product/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-product/README.md index f6a6f9b254df..006c77a3bb83 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-product/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-product/README.md @@ -113,6 +113,126 @@ console.log( ndarray2array( v ) ); + + +* * * + +
+ +## C APIs + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/dcartesian_product.h" +``` + +#### stdlib_blas_ext_dcartesian_product( arrays ) + +Computes the Cartesian product for two double-precision floating-point ndarrays and stores each pair in a row of a two-dimensional output ndarray. + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing two one-dimensional input ndarrays and a two-dimensional output ndarray. + +```c +void stdlib_blas_ext_dcartesian_product( const struct ndarray *arrays[] ); +``` + +
+ + + +
+ +### Notes + +- For inputs of lengths `M` and `N`, the output ndarray should have shape `[M*N, 2]`. +- The first column contains elements from the first input and the second column contains elements from the second input. +- If `M <= 0` or `N <= 0`, the output ndarray is unchanged. +- C ndarray strides and offsets are specified in bytes. The function supports independently strided input and output views. + +
+ + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/dcartesian_product.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 }; + const double dataY[] = { 3.0, 4.0, 5.0 }; + double dataOut[ 12 ]; + + // Specify input and output shapes: + int64_t shapeX[] = { 2 }; + int64_t shapeY[] = { 3 }; + int64_t shapeOut[] = { 6, 2 }; + + // Specify byte strides: + int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + int64_t stridesOut[] = { + 2 * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, + STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT + }; + + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + + // Create input and output ndarrays: + // cppcheck-suppress invalidPointerCast + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, 1, shapeX, strides, 0, order, imode, 1, submodes ); + + // cppcheck-suppress invalidPointerCast + struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, 1, shapeY, strides, 0, order, imode, 1, submodes ); + + // cppcheck-suppress invalidPointerCast + struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, 2, shapeOut, stridesOut, 0, order, imode, 1, submodes ); + if ( x == NULL || y == NULL || out == NULL ) { + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); + stdlib_ndarray_free( out ); + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + const struct ndarray *arrays[] = { x, y, out }; + stdlib_blas_ext_dcartesian_product( arrays ); + + // Print the resulting pairs: + for ( int i = 0; i < 6; i++ ) { + printf( "out[ %i ] = ( %lf, %lf )\n", i, dataOut[ i*2 ], dataOut[ (i*2)+1 ] ); + } + stdlib_ndarray_free( x ); + stdlib_ndarray_free( y ); + stdlib_ndarray_free( out ); +} +``` + +
+ + + +
+ + +