Wolfram Language

NumericArray in LibraryLink

NumericArray and ByteArray objects in the Wolfram Language can be passed to or from a LibraryFunction where they appear as arguments or results of type MNumericArrary. MNumericArray is a pointer to a data structure, and it is passed by reference. Memory management for MNumericArray is very similar to memory management for MTensor.

The family of MNumericArray callback functions are in the numericarrayLibraryFunctions field of WolframLibraryData, and they are declared in WolframNumericArrayLibrary.h.

A typical use looks as follows.

#include "WolframNumericArrayLibrary.h" .... MNumericArray na_in = NULL, na_out = NULL; errcode_t err = 0; numericarray_data_t type = MNumericArray_Type_Undef; WolframNumericArrayLibrary_Functions naFuns = libData->numericarrayLibraryFunctions; ... na_in = MArgument_getMNumericArray(Args[0]); type = naFuns->MNumericArray_getType(na_in); if(type != MNumericArray_Type_Real32) { err = naFuns->MNumericArray_convertType(&na_out, na_in, MNumericArray_Type_Real32, MNumericArray_Convert_Coerce, 1); ... } ...

Examples in the demo_numericarray library show how to use MNumericArray arguments and results with NumericArray and ByteArray objects in the Wolfram Language.

This example shows how to compute the complex conjugate of elements stored in a NumericArray.

The function readBytesFromFile from the demo shows how to read data from a file and store it in a ByteArray object.

Related Examples

de es fr ja ko pt-br zh