diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/striu2tril/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/striu2tril/README.md index b2646f839033..543d3b550bc0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/striu2tril/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/striu2tril/README.md @@ -48,7 +48,7 @@ var A = new Float32Matrix( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); var B = new Float32Matrix( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ); var k = scalar2ndarray( 0, { - 'dtype': 'generic' + 'dtype': 'int32' }); var out = striu2tril( [ A, B, k ] ); @@ -106,7 +106,7 @@ var B = discreteUniform( shapeB, -10, 10, { console.log( ndarray2array( B ) ); var k = scalar2ndarray( 0, { - 'dtype': 'generic' + 'dtype': 'int32' }); var out = striu2tril( [ A, B, k ] ); @@ -117,6 +117,190 @@ console.log( ndarray2array( out ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ndarray/striu2tril.h" +``` + +#### stdlib_blas_ext_striu2tril( arrays ) + +Reflects the upper triangular part of a single-precision floating-point matrix `A` into the lower triangular part of another matrix `B`. + +```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 for A: +float dataA[] = { 1.0f, 2.0f, 3.0f, 4.0f }; +int64_t shape[] = { 2, 2 }; +int64_t stridesA[] = { 2 * STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR, STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *A = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataA, 2, shape, stridesA, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes ); + +// Create an ndarray for B: +float dataB[] = { 0.0f, 0.0f, 0.0f, 0.0f }; +int64_t stridesB[] = { 2 * STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; + +struct ndarray *B = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataB, 2, shape, stridesB, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 2, submodes ); + +// Create an ndarray for k: +int32_t dataK[] = { 0 }; +int64_t stridesK[] = { 0 }; +int8_t submodesK[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *k = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)dataK, 0, NULL, stridesK, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodesK ); + +// Perform computation: +const struct ndarray *arrays[] = { A, B, k }; +stdlib_blas_ext_striu2tril( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( A ); +stdlib_ndarray_free( B ); +stdlib_ndarray_free( k ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a two-dimensional input ndarray corresponding to `A`. + - `[inout] struct ndarray*` a two-dimensional output ndarray corresponding to `B`. + - `[in] struct ndarray*` a zero-dimensional ndarray specifying the diagonal below which to ignore. + +```c +void stdlib_blas_ext_striu2tril( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ndarray/striu2tril.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: + float dataA[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }; + float dataB[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + // Specify the number of array dimensions: + const int64_t ndims = 2; + + // Specify the array shape: + int64_t shape[] = { 3, 3 }; + + // Specify the array strides: + int64_t stridesA[] = { 3 * STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT }; + int64_t stridesB[] = { 3 * STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT, STDLIB_NDARRAY_FLOAT32_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 ndarrays: + struct ndarray *A = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataA, ndims, shape, stridesA, offset, order, imode, nsubmodes, submodes ); + + struct ndarray *B = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)dataB, ndims, shape, stridesB, offset, order, imode, nsubmodes, submodes ); + + // Create a data buffer for an ndarray containing the diagonal offset: + const int32_t kdata[] = { 0 }; + + // Specify the array strides for a zero-dimensional ndarray: + int64_t kstrides[] = { 0 }; + + int8_t ksubmodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + + // Create an ndarray containing the diagonal offset: + struct ndarray *k = stdlib_ndarray_allocate( STDLIB_NDARRAY_INT32, (uint8_t *)kdata, 0, NULL, kstrides, 0, order, imode, 1, ksubmodes ); + if ( A == NULL || B == NULL || k == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { A, B, k }; + + // Perform computation: + stdlib_blas_ext_striu2tril( arrays ); + + // Print the result: + for ( int i = 0; i < 9; i++ ) { + printf( "B[ %i ] = %f\n", i, dataB[ i ] ); + } + + // Free allocated memory: + stdlib_ndarray_free( A ); + stdlib_ndarray_free( B ); + stdlib_ndarray_free( k ); +} +``` + +
+ + + +
+ + +