diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md index a40de9dd62db..ba3860dfed5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/dcartesian-power/README.md @@ -51,7 +51,7 @@ var out = zeros( [ 4, 2 ], { }); var k = scalar2ndarray( 2, { - 'dtype': 'generic' + 'dtype': 'int32' }); var v = dcartesianPower( [ x, out, k ] ); @@ -108,7 +108,7 @@ console.log( ndarray2array( x ) ); var out = zeros( [ 9, 2 ], opts ); var k = scalar2ndarray( 2, { - 'dtype': 'generic' + 'dtype': 'int32' }); var v = dcartesianPower( [ x, out, k ] ); @@ -119,6 +119,211 @@ console.log( ndarray2array( v ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/dcartesian_power.h" +``` + +#### stdlib_blas_ext_dcartesian_power( arrays ) + +Computes the Cartesian power for a double-precision 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 +#include +#include + +// Create an input ndarray: +const double data_x[] = { 1.0, 2.0 }; +int64_t shape_x[] = { 2 }; +int64_t strides_x[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data_x, 1, shape_x, strides_x, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Allocate memory for the output array: +int32_t K = 2; +int64_t num_rows = (int64_t)pow( 2.0, (double)K ); +double *data_out = (double *)malloc( num_rows * K * sizeof( double ) ); + +int64_t shape_out[] = { num_rows, K }; +int64_t strides_out[] = { K * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + +// Create the output ndarray: +struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data_out, 2, shape_out, strides_out, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes ); + +// Create a 0D ndarray for `k`: +int32_t data_k[] = { K }; +int64_t strides_k[] = { 0 }; + +struct ndarray *k_arr = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)data_k, 0, NULL, strides_k, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Compute the Cartesian power: +const struct ndarray *arrays[] = { x, out, k_arr }; +stdlib_blas_ext_dcartesian_power( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( out ); +stdlib_ndarray_free( k_arr ); +free( data_out ); +``` + +The function accepts the following arguments: + +- **arrays**: `[inout] struct ndarray**` list containing the following ndarrays: + + - a one-dimensional input ndarray. + - a two-dimensional output ndarray. + - a zero-dimensional ndarray specifying the power. + +```c +void stdlib_blas_ext_dcartesian_power( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/dcartesian_power.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 an input data buffer: + const double dataX[] = { 1.0, -2.0, 3.0, -4.0 }; + + // Specify the array shape for the input array: + int64_t shapeX[] = { 4 }; + + // Specify the array strides: + int64_t stridesX[] = { STDLIB_NDARRAY_FLOAT64_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, STDLIB_NDARRAY_INDEX_ERROR }; + const int64_t nsubmodes = 2; + + // Create the input ndarray: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, 1, shapeX, stridesX, offset, order, imode, 1, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Allocate memory for the output array: + int32_t K = 2; + int64_t nrows = 1; + for ( int p = 0; p < K; p++ ) { + nrows *= 4; + } + double *dataOut = (double *)malloc( nrows * K * sizeof( double ) ); + + // Specify the array shape for the output array: + int64_t shapeOut[] = { nrows, K }; + + // Specify the array strides for the output array: + int64_t stridesOut[] = { K * STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Create the output ndarray: + struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, 2, shapeOut, stridesOut, offset, order, imode, nsubmodes, submodes ); + if ( out == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Create a 0D ndarray for `k`: + int32_t dataK[] = { K }; + int64_t stridesK[] = { 0 }; + + struct ndarray *k = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)dataK, 0, NULL, stridesK, offset, order, imode, 1, submodes ); + if ( k == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, out, k }; + + // Compute the Cartesian power: + stdlib_blas_ext_dcartesian_power( arrays ); + + // Print the result: + for ( int i = 0; i < nrows; i++ ) { + printf( "Tuple %d: %lf, %lf\n", i, dataOut[ i*K ], dataOut[ i*K + 1 ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( out ); + stdlib_ndarray_free( k ); + free( dataOut ); +} +``` + +
+ + + +
+ + +