Apply a nullary function and assign results to elements in an output ndarray.
npm install @stdlib/ndarray-base-nullaryWe believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js. The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases. When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there. To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
About stdlib...
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
> Apply a nullary callback and assign results to elements in an output ndarray.
``bash`
npm install @stdlib/ndarray-base-nullary
`javascript`
var nullary = require( '@stdlib/ndarray-base-nullary' );
#### nullary( arrays, fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`javascript
var Float64Array = require( '@stdlib/array-float64' );
function fcn() {
return 10.0;
}
// Create data buffers:
var xbuf = new Float64Array( 12 );
// Define the shape of the output array:
var shape = [ 3, 1, 2 ];
// Define the array strides:
var sx = [ 4, 4, 1 ];
// Define the index offset:
var ox = 1;
// Create the output ndarray-like object:
var x = {
'dtype': 'float64',
'data': xbuf,
'shape': shape,
'strides': sx,
'offset': ox,
'order': 'row-major'
};
// Apply the nullary function:
nullary( [ x ], fcn );
console.log( x.data );
// =>
`
The function accepts the following arguments:
- arrays: array-like object containing an output ndarray.
- fcn: nullary function to apply.
The provided ndarray should be an object with the following properties:
- dtype: data type.
- data: data buffer.
- shape: dimensions.
- strides: stride lengths.
- offset: index offset.
- order: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a nullary function in order to achieve better performance.
`javascript
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
var filledarray = require( '@stdlib/array-filled' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var nullary = require( '@stdlib/ndarray-base-nullary' );
var x = {
'dtype': 'generic',
'data': filledarray( 0, 10, 'generic' ),
'shape': [ 5, 2 ],
'strides': [ 2, 1 ],
'offset': 0,
'order': 'row-major'
};
nullary( [ x ], discreteUniform( -100, 100 ) );
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
`
*
Character codes for data types:
- x: bool (boolean).complex128
- z: (double-precision floating-point complex number).complex64
- c: (single-precision floating-point complex number).float32
- f: (single-precision floating-point number).float64
- d: (double-precision floating-point number).int16
- k: (signed 16-bit integer).int32
- i: (signed 32-bit integer).int8
- s: (signed 8-bit integer).uint16
- t: (unsigned 16-bit integer).uint32
- u: (unsigned 32-bit integer).uint8
- b: (unsigned 8-bit integer).
Function name suffix naming convention:
`text`
stdlib_ndarray_
For example,
`c`
void stdlib_ndarray_d(...) {...}
is a function which accepts one double-precision floating-point output ndarray. In other words, the suffix encodes the function type signature.
To support callbacks whose return values are of a different data type than the output ndarray data types, the naming convention supports appending an as suffix. For example,
`c`
void stdlib_ndarray_f_as_d(...) {...}
is a function which accepts one single-precision floating-point output ndarray. However, the callback returns double-precision floating-point numbers. Accordingly, the output values need to be cast using the following conversion sequence
`c
// Evaluate the callback:
double out = f();
// Convert the callback return value to single-precision:
x[ i ] = (float)out;
`
`c`
#include "stdlib/ndarray/base/nullary.h"
#### stdlib_ndarray_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 2, 1 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_b( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include "stdlib/complex/float32/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static stdlib_complex64_t fcn( void ) {
// ...
}
// Apply the callback:
int8_t status = stdlib_ndarray_c( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a stdlib_complex64_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_b( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_f( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static float fcn( void ) {
return 10.0f;
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_f( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a float (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_f( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_k( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_k( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_k( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_s( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_s( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_s( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_t( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_t( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_t( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_c_as_z( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include "stdlib/complex/float64/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_COMPLEX64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static stdlib_complex128_t fcn( void ) {
// ...
}
// Apply the callback:
int8_t status = stdlib_ndarray_c_as_z( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a stdlib_complex128_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_c_as_z( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static double fcn( void ) {
return 10.0;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a double (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_b( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_f( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static float fcn( void ) {
return 10.0f;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_f( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a float (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_f( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_i( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int32_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_i( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int32_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_i( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_k( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_k( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_k( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_s( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_s( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_s( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_t( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_t( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_t( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_d_as_u( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 16, 8 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint32_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_d_as_u( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint32_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_d_as_u( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static float fcn( void ) {
return 10.0f;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a float (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f_as_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f_as_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f_as_b( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f_as_d( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static double fcn( void ) {
return 10.0;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f_as_d( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a double (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f_as_d( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f_as_k( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f_as_k( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f_as_k( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f_as_s( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f_as_s( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f_as_s( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_f_as_t( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_FLOAT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_f_as_t( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_f_as_t( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_i( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int32_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_i( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int32_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_i( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_i_as_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_i_as_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_i_as_b( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_i_as_k( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_i_as_k( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_i_as_k( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_i_as_s( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_i_as_s( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int8_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_i_as_s( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_i_as_t( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT32;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 8, 4 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_i_as_t( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_i_as_t( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_k( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT16;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 4, 2 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static int16_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_k( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a int16_t (f)() function to apply provided as a void pointer.
`c`
int8_t stdlib_ndarray_k( struct ndarray arrays[], void fcn );
#### stdlib_ndarray_k_as_b( \arrays\[], \fcn )
Applies a nullary callback and assigns results to elements in an output ndarray.
`c
#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include
#include
#include
// Define the ndarray data type:
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_INT16;
// Create an underlying byte array:
uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
// Define the number of dimensions:
int64_t ndims = 2;
// Define the array shape:
int64_t shape[] = { 2, 2 };
// Define the strides:
int64_t sx[] = { 4, 2 };
// Define the index offset:
int64_t ox = 0;
// Define the array order:
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { imode };
int64_t nsubmodes = 1;
// Create an output ndarray:
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( EXIT_FAILURE );
}
// Create an array containing a pointer to the ndarray:
struct ndarray *arrays[] = { x };
// Define a callback:
static uint8_t fcn( void ) {
return 10;
}
// Apply the callback:
int8_t status = stdlib_ndarray_k_as_b( arrays, (void *)fcn );
if ( status != 0 ) {
fprintf( stderr, "Error during computation.\n" );
exit( EXIT_FAILURE );
}
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
`
The function accepts the following arguments:
- arrays: [inout] struct ndarray** array whose only element is a pointer to an output ndarray.[in] void
- fcn: a uint8_t (f)() function to apply provided as a void pointer.
``c
int8_t stdlib_ndarray_k_as_b( struct ndarr