Currently, NumericArray
s are directly supported by the most important array-related functions, what makes them a very attractive data structure for implementing highly efficient algorithms. Here is a (possibly incomplete) list of functions from the current Documentation which directly support NumericArray
s as input and output data structure:
Part
,
Take
,
Drop
,
Flatten
,
Join
,
FunctionCompile
,
NetEncoder
.
Other functions which directly support NumericArray
s according to the Documentation include:
Dimensions
,
Length
,
ArrayDepth
,
NumericArrayQ
,
NumericArrayType
,
Normal
,
Image
,
Image3D
,
Audio
.
Testing shows that Total
also accepts NumericArray
as input:
Total[NumericArray[{1, 2, 3}, "UnsignedInteger8"]]
6
But what is missing is the support even for the basic arithmetic operations on NumericArray
s. For example, an attempt to add two arrays of the same type and shape returns unevaluated:
NumericArray[{1, 2, 3}, "UnsignedInteger8"] + NumericArray[{3, 4, 5}, "UnsignedInteger8"]
There is undocumented built-in package "NumericArrayUtilities`"
with the Description
Utilities for doing high-performance numeric computations.
It includes several utilities:
Needs["NumericArrayUtilities`"]
Names["NumericArrayUtilities`*"] // Length
38
But it seems they don't offer the desired functionality either.
My question:
How can I perform basic arithmetic operations on NumericArray
s without converting them to usual arrays?
I'm most interested in subtraction and addition.
FunctionCompile
to do that. $\endgroup$