diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/dmeanstdev/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/dmeanstdev/README.md index 3c6ab036531b..4d6a35e0796f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/dmeanstdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/dmeanstdev/README.md @@ -173,6 +173,202 @@ console.log( ndarray2array( v ) ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/ndarray/dmeanstdev.h" +``` + +#### stdlib_stats_dmeanstdev( arrays ) + +Computes the arithmetic mean and standard deviation of a one-dimensional 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 + +// Create an input ndarray: +const double data[] = { 1.0, 3.0, 4.0, 2.0 }; +int64_t shape[] = { 4 }; +int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; + +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Create an output ndarray: +double data_out[] = { 0.0, 0.0 }; +int64_t shape_out[] = { 2 }; +int64_t strides_out[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + +struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data_out, 1, shape_out, strides_out, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Create an ndarray for specifying the degrees of freedom adjustment: +double cdata[] = { 1.0 }; +int64_t cstrides[] = { 0 }; +struct ndarray *corr = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)cdata, 0, NULL, cstrides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); + +// Compute the result: +const struct ndarray *arrays[] = { x, out, corr }; +stdlib_stats_dmeanstdev( arrays ); + +// Free allocated memory: +stdlib_ndarray_free( x ); +stdlib_ndarray_free( out ); +stdlib_ndarray_free( corr ); +``` + +The function accepts the following arguments: + +- **arrays**: `[in] struct ndarray**` list containing the following ndarrays: + + - `[in] struct ndarray*` a one-dimensional input ndarray. + - `[in] struct ndarray*` a zero-dimensional ndarray specifying the degrees of freedom adjustment. Providing a non-zero degrees of freedom adjustment has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `N` is the number of elements in the input ndarray and `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). + +```c +void stdlib_stats_dmeanstdev( const struct ndarray *arrays[] ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/ndarray/dmeanstdev.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: + const 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[] = { 2*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 }; + const int64_t nsubmodes = 1; + + // Create an ndarray: + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); + if ( x == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Create a data buffer for the output: + double data_out[] = { 0.0, 0.0 }; + + // Specify the array shape: + int64_t shape_out[] = { 2 }; + + // Specify the array strides: + int64_t strides_out[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; + + // Create an ndarray for the output: + // cppcheck-suppress invalidPointerCast + struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data_out, ndims, shape_out, strides_out, offset, order, imode, nsubmodes, submodes ); + if ( out == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Create a data buffer for an ndarray specifying the degrees of freedom adjustment: + double cdata[] = { 1.0 }; + + // Specify the array strides: + int64_t cstrides[] = { 0 }; + + // Create an ndarray for the degrees of freedom adjustment: + // cppcheck-suppress invalidPointerCast + struct ndarray *corr = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)cdata, 0, NULL, cstrides, 0, order, imode, nsubmodes, submodes ); + if ( corr == NULL ) { + fprintf( stderr, "Error allocating memory.\n" ); + exit( 1 ); + } + + // Define a list of ndarrays: + const struct ndarray *arrays[] = { x, out, corr }; + + // Compute the result: + stdlib_stats_dmeanstdev( arrays ); + + // Print the result: + printf( "mean: %lf, stdev: %lf\n", data_out[ 0 ], data_out[ 1 ] ); + + // Free allocated memory: + stdlib_ndarray_free( x ); + stdlib_ndarray_free( out ); + stdlib_ndarray_free( corr ); +} +``` + +
+ + + +
+ + +