npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stdlib/ndarray-base-nullary

v0.3.0

Published

Apply a nullary function and assign results to elements in an output ndarray.

Downloads

26

Readme

Nullary

[![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.

Installation

npm install @stdlib/ndarray-base-nullary

Usage

var nullary = require( '@stdlib/ndarray-base-nullary' );

nullary( arrays, fcn )

Applies a nullary callback and assigns results to elements in an output ndarray.

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 );
// => <Float64Array>[ 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 0.0 ]

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).

Notes

  • 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.

Examples

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 ) );

C APIs

Character codes for data types:

  • x: bool (boolean).
  • z: complex128 (double-precision floating-point complex number).
  • c: complex64 (single-precision floating-point complex number).
  • f: float32 (single-precision floating-point number).
  • d: float64 (double-precision floating-point number).
  • k: int16 (signed 16-bit integer).
  • i: int32 (signed 32-bit integer).
  • s: int8 (signed 8-bit integer).
  • t: uint16 (unsigned 16-bit integer).
  • u: uint32 (unsigned 32-bit integer).
  • b: uint8 (unsigned 8-bit integer).

Function name suffix naming convention:

stdlib_ndarray_<output_data_type>[_as_<callback_return_data_type>]

For example,

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,

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

// Evaluate the callback:
double out = f();

// Convert the callback return value to single-precision:
x[ i ] = (float)out;

Usage

#include "stdlib/ndarray/base/nullary.h"

stdlib_ndarray_b( *arrays[], *fcn )

Applies a nullary callback and assigns results to elements in an output ndarray.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
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.

#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 <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a stdlib_complex64_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a float (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint16_t (*f)() function to apply provided as a void pointer.
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.

#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 <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a stdlib_complex128_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a double (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a float (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int32_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint32_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a float (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a double (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int32_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int8_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a int16_t (*f)() function to apply provided as a void pointer.
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.

#include "stdlib/ndarray/dtypes.h"
#include "stdlib/ndarray/index_modes.h"
#include "stdlib/ndarray/orders.h"
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

// 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.
  • fcn: [in] void* a uint8_t (*f)() function to apply provided as a void pointer.
int8_t stdlib_ndarray_k_as_b( struct nda