Main Content

List of Functions with dlarray Support

Deep Learning Toolbox Functions with dlarray Support

These tables list and briefly describe the Deep Learning Toolbox™ functions that operate on dlarray objects.

Deep Learning Operations

FunctionDescription
attentionThe attention operation focuses on parts of the input using weighted multiplication operations.
avgpoolThe average pooling operation performs downsampling by dividing the input into pooling regions and computing the average value of each region.
batchnormThe batch normalization operation normalizes the input data across all observations for each channel independently. To speed up training of the convolutional neural network and reduce the sensitivity to network initialization, use batch normalization between convolution and nonlinear operations such as relu.
crossentropyThe cross-entropy operation computes the cross-entropy loss between network predictions and binary or one-hot encoded targets for single-label and multi-label classification tasks.
indexcrossentropy (since R2024b)The index cross-entropy operation computes the cross-entropy loss between network predictions and targets specified as integer class indices for single-label classification tasks.
crosschannelnormThe cross-channel normalization operation uses local responses in different channels to normalize each activation. Cross-channel normalization typically follows a relu operation. Cross-channel normalization is also known as local response normalization.
ctcThe CTC operation computes the connectionist temporal classification (CTC) loss between unaligned sequences.
dlconvThe convolution operation applies sliding filters to the input data. Use the dlconv function for deep learning convolution, grouped convolution, and channel-wise separable convolution.
dlode45The neural ordinary differential equation (ODE) operation returns the solution of a specified ODE.
dltranspconvThe transposed convolution operation upsamples feature maps.
embedThe embed operation converts numeric indices to numeric vectors, where the indices correspond to discrete data. Use embeddings to map discrete data such as categorical values or words to numeric vectors.
fullyconnectThe fully connect operation multiplies the input by a weight matrix and then adds a bias vector.
geluThe Gaussian error linear unit (GELU) activation operation weights the input by its probability under a Gaussian distribution.
groupnormThe group normalization operation normalizes the input data across grouped subsets of channels for each observation independently. To speed up training of the convolutional neural network and reduce the sensitivity to network initialization, use group normalization between convolution and nonlinear operations such as relu.
gruThe gated recurrent unit (GRU) operation allows a network to learn dependencies between time steps in time series and sequence data.
huberThe Huber operation computes the Huber loss between network predictions and target values for regression tasks. When the 'TransitionPoint' option is 1, this is also known as smooth L1 loss.
instancenormThe instance normalization operation normalizes the input data across each channel for each observation independently. To improve the convergence of training the convolutional neural network and reduce the sensitivity to network hyperparameters, use instance normalization between convolution and nonlinear operations such as relu.
l1lossThe L1 loss operation computes the L1 loss given network predictions and target values. When the Reduction option is "sum" and the NormalizationFactor option is "batch-size", the computed value is known as the mean absolute error (MAE).
l2lossThe L2 loss operation computes the L2 loss (based on the squared L2 norm) given network predictions and target values. When the Reduction option is "sum" and the NormalizationFactor option is "batch-size", the computed value is known as the mean squared error (MSE).
layernormThe layer normalization operation normalizes the input data across all channels for each observation independently. To speed up training of recurrent and multilayer perceptron neural networks and reduce the sensitivity to network initialization, use layer normalization after the learnable operations, such as LSTM and fully connect operations.
leakyreluThe leaky rectified linear unit (ReLU) activation operation performs a nonlinear threshold operation, where any input value less than zero is multiplied by a fixed scale factor.
lstmThe long short-term memory (LSTM) operation allows a network to learn long-term dependencies between time steps in time series and sequence data.
maxpoolThe maximum pooling operation performs downsampling by dividing the input into pooling regions and computing the maximum value of each region.
maxunpoolThe maximum unpooling operation unpools the output of a maximum pooling operation by upsampling and padding with zeros.
mseThe half mean squared error operation computes the half mean squared error loss between network predictions and target values for regression tasks.
onehotdecode

The one-hot decode operation decodes probability vectors, such as the output of a classification network, into classification labels.

The input A can be a dlarray. If A is formatted, the function ignores the data format.

reluThe rectified linear unit (ReLU) activation operation performs a nonlinear threshold operation, where any input value less than zero is set to zero.
sigmoidThe sigmoid activation operation applies the sigmoid function to the input data.
softmaxThe softmax activation operation applies the softmax function to the channel dimension of the input data.

dlarray-Specific Functions

FunctionDescription
dimsThe dims function returns the data format of the input.
dlfevalThe dlfeval function evaluates deep learning models and functions with automatic differentiation enabled.
dlgradientThe dlgradient function computes derivatives using automatic differentiation.
dljacobianThe Jacobian deep learning operation returns the Jacobian matrix for neural network and model function outputs with respect to the specified input data and operation dimension.
dldivergenceThe divergence deep learning operation returns the mathematical divergence of neural network and model function outputs with respect to the specified input data and operation dimension.
dllaplacianThe Laplacian deep learning operation returns the Laplacian of neural network and model function outputs with respect to the specified input data and operation dimension.
extractdataThe extractdata function extracts the data from a dlarray object.
finddimThe finddim function finds the dimension index of a formatted dlarray object for a specified label.
stripdimsThe stripdims function removes the format from a dlarray object.

Domain-Specific Functions with dlarray Support

These tables list and briefly describe the domain-specific functions that operate on dlarray objects.

Computer Vision

FunctionDescription
focalCrossEntropy (Computer Vision Toolbox)Calculate the focal cross-entropy loss between two dlarray objects that represent predicted and target classification labels.
generalizedDice (Computer Vision Toolbox)Measure the similarity between two dlarray objects that represent segmented images, using a generalized Dice metric that accounts for class weighting.
roialign (Computer Vision Toolbox)Perform ROI pooling of dlarray data.

Image Processing

FunctionDescription
depthToSpace (Image Processing Toolbox)Rearrange dlarray data from the depth dimension into spatial blocks.
dlresize (Image Processing Toolbox)Resize the spatial dimensions of a dlarray.
imageshow (Image Processing Toolbox)Display a single 2-D image stored in a dlarray. Unformatted dlarray objects must contain a grayscale or RGB image with optional singleton dimensions corresponding to time or batch. Formatted dlarray objects must have one of these formats, where time and batch are singleton dimensions: "SS", "SSC", "SSB", "SSCB", "SST", "SSCT", "SSBT", "SSCBT".
montage (Image Processing Toolbox)Display a montage consisting of several 2-D frames of a multiframe image stored in a dlarray (since R2024b).
multissim (Image Processing Toolbox)Measure the similarity between two dlarray objects that represent 2-D images, using the multiscale structural similarity (MS-SSIM) metric.
multissim3 (Image Processing Toolbox)Measure the similarity between two dlarray objects that represent 3-D images, using the 3-D MS-SSIM metric.
psnr (Image Processing Toolbox)Measure the similarity between two dlarray objects that represent images using the peak signal-to-noise ratio (PSNR) metric.
spaceToDepth (Image Processing Toolbox)Rearrange spatial blocks of dlarray data into the depth dimension.
ssim (Image Processing Toolbox)Measure the similarity between two dlarray objects that represent images using the structural similarity (SSIM) metric.

Signal Processing

FunctionDescription
dlcwt (Wavelet Toolbox)Compute continuous wavelet transform.
dlicwt (Wavelet Toolbox)Compute inverse continuous wavelet transform.
dlmodwt (Wavelet Toolbox)Compute maximal overlap discrete wavelet transform and multiresolution analysis.
dlstft (Signal Processing Toolbox)Compute short-time Fourier transform.
dlistft (Signal Processing Toolbox)Compute inverse short-time Fourier transform.
framesig (Signal Processing Toolbox)Partition signal into frames.
scatteringFeatures (Wavelet Toolbox)Compute wavelet joint time-frequency scattering feature tensor.
scatteringTransform (Wavelet Toolbox)Compute wavelet joint time-frequency scattering transform.

Wireless Communications

FunctionDescription
awgn (Communications Toolbox)Filter a signal represented in a dlarray object through an additive white Gaussian noise (AWGN) channel. Only unformatted input arrays are supported.
comm.ChannelFilter (Communications Toolbox)Filter a signal represented in a dlarray object through a channel using multipath gains at specified path delays. Only unformatted input arrays are supported.
comm.MIMOChannel (Communications Toolbox)Filter a signal represented in a dlarray object through an MIMO channel. Only unformatted input arrays are supported.
bit2int (Communications Toolbox)Convert input bits represented in a dlarray object to integers. Only unformatted input arrays are supported.
genqammod (Communications Toolbox)Modulate a signal represented in a dlarray object using general quadrature amplitude modulation (QAM). Only unformatted input arrays are supported.
ofdmmod (Communications Toolbox)Modulate a frequency-domain signal represented in a dlarray object using orthogonal frequency division multiplexing (OFDM). Only unformatted input arrays are supported.
ofdmdemod (Communications Toolbox)Demodulate a time-domain signal represented in a dlarray object using orthogonal frequency division multiplexing (OFDM). Only unformatted input arrays are supported.
ofdmChannelResponse (Communications Toolbox)Calculate the frequency response of a time-varying channel represented in a dlarray object. Only unformatted input arrays are supported.
ofdmEqualize (Communications Toolbox)Equalize a frequency-domain OFDM signal represented in a dlarray object. Only unformatted input arrays are supported.

MATLAB Functions with dlarray Support

Many MATLAB® functions operate on dlarray objects. These tables list the usage notes and limitations for these functions when you use dlarray arguments.

Unary Element-wise Functions

FunctionNotes and Limitations
abs

The output dlarray has the same data format as the input dlarray.

acos
acosh
acot
acsc
angle
asec
asin
asinh
atan
atan2
atanh
conj
cos
cosh
cot
csc
erf
exp
imag
log
real
reallog
realsqrt
sec
sign
sin
sinh
sqrt
tan
tanh
uminus, -
uplus, +
log10 (since R2024b)

The output dlarray has the same data format as the input dlarray.

Binary Element-wise Operators

FunctionNotes and Limitations
complex

For the one-input syntax, the output dlarray has the same data format as the input dlarray

For the two-input syntax, if dlarray inputs are formatted, their data formats must match.

minus, -

If the two dlarray inputs are formatted, then the output dlarray is formatted with a combination of both of their data formats. The function uses implicit expansion to combine the inputs. For more information, see Implicit Expansion with Data Formats.

plus, +
power, .^
rdivide, ./
realpow
times, .*

Reduction Functions

FunctionNotes and Limitations
mean
  • The output dlarray has the same data format as the input dlarray.

  • The 'omitnan' option is not supported.

  • If the input dlarray is on the GPU, the 'native' option is not supported.

  • The Weights argument is not supported.

normalize
  • The output dlarray has the same data format as the input dlarray.

  • Only the "norm" normalization method is supported.

std
  • The output dlarray has the same data format as the input dlarray.

  • The 'omitnan' option is not supported.

prod
  • The output dlarray has the same data format as the input dlarray.

  • The 'omitnan' option is not supported.

sum
vecnorm

The output dlarray has the same data format as the input dlarray.

median (since R2024b)
  • The output dlarray has the same data format as the input dlarray.

  • The 'omitnan' option is not supported.

  • The Weights argument is not supported.

Extrema Functions

FunctionNotes and Limitations
ceil

The output dlarray has the same data format as the input dlarray.

eps
  • The output dlarray has the same data format as the input dlarray.

  • Use eps(ones('like', x)) to get a scalar epsilon value based on the data type of a dlarray x.

fix

The output dlarray has the same data format as the input dlarray.

floor

The output dlarray has the same data format as the input dlarray.

max
  • When you find the maximum or minimum elements of a single dlarray, the output dlarray has the same data format as the input dlarray.

  • When you find the maximum or minimum elements between two formatted dlarray inputs, the output dlarray has a combination of both of their data formats. The function uses implicit expansion to combine the inputs. For more information, see Implicit Expansion with Data Formats.

  • The index output argument is not traced and cannot be used with automatic differentiation. For more information, see Use Automatic Differentiation In Deep Learning Toolbox.

min
rescale
  • If the first input dlarray A is unformatted, all additional inputs must be unformatted.

  • If the first input dlarray A is formatted, all additional inputs must either be unformatted scalars, or have data formats that are a subset of the data format of A. In this case, each dimension must either be singleton or match the length of the corresponding dimension of A.

round
  • Only the syntax Y = round(X) is supported.

  • The output dlarray has the same data format as the input dlarray.

Fourier Transforms

FunctionNotes and Limitations
fft Only unformatted input arrays are supported.
ifft
  • Only unformatted input arrays are supported.

  • When you use the 'symmetric' option, ifft treats the input Y as exactly symmetric. If you compute the derivative using automatic differentiation, then the derivative is also exactly symmetric. If Y is non-symmetric, then the function and gradient behavior might not match. To ensure that function and gradient behavior match for non-symmetric inputs, explicitly symmetrize Y.

Other Math Operations

FunctionNotes and Limitations
colon, :
  • The supported operations are:

    • a:b

    • a:b:c

    For information on indexing into a dlarray, see Indexing.

  • All inputs must be real scalars. The output dlarray is unformatted.

interp1
  • Sample points input x must be a finite, increasing vector without repeating elements.

  • method must be 'linear' or 'nearest'.

  • The piecewise polynomial syntax ('pp') is not supported.

  • Only the sample values input v can be a formatted dlarray. All other inputs must be unformatted. If v is a formatted dlarray, query points input xq must be a vector, and the output vq has the same data format as v.

mrdivide, /

The second dlarray input must be a scalar. The output dlarray has the same data format as the first dlarray input.

mtimes, *
  • One input can be a formatted dlarray only when the other input is an unformatted scalar. In this case, the output dlarray has the same data format as the formatted dlarray input.

  • Multiplying a dlarray with a non-dlarray sparse matrix is supported only when both inputs are non-scalar.

ode45

The supported syntaxes are:

  • [t,y] = ode45(odefun,tspan,y0)

  • [t,y] = ode45(odefun,tspan,y0,options)

At least one of y0 and tspan must be an unformatted dlarray object.

If tspan is a dlarray object, then the output t is an unformatted dlarray object. If y0 is a dlarray object, then the output y is an unformatted dlarray object.

For dlarray input, the ode45 function does not support the OutputFcn, Mass, NonNegative, and Events options.

For dlarray input, the ode45 function does not support acceleration using dlaccelerate.

Tip

For neural ODE workflows, use dlode45.

pagemtimes

One input can be a formatted dlarray only when the other input is unformatted, with scalar pages. In this case, the output dlarray has the same data format as the formatted dlarray input.

pinv (since R2024a)

The first argument must be a 2-D unformatted dlarray object with type double or single.

Logical Operations

FunctionNotes and Limitations
all

The output dlarray has the same data format as the input dlarray.

and, &

If the two dlarray inputs are formatted, then the output dlarray is formatted with a combination of both of their data formats. The function uses implicit expansion to combine the inputs. For more information, see Implicit Expansion with Data Formats.

any

The output dlarray has the same data format as the input dlarray.

eq, ==

If the two dlarray inputs are formatted, then the output dlarray is formatted with a combination of both of their data formats. The function uses implicit expansion to combine the inputs. For more information, see Implicit Expansion with Data Formats.

ge, >=
gt, >
le, <=
lt, <
ne, ~=
not, ~

The output dlarray has the same data format as the input dlarray.

or, |

If the two dlarray inputs are formatted, then the output dlarray is formatted with a combination of both of their data formats. The function uses implicit expansion to combine the inputs. For more information, see Implicit Expansion with Data Formats.

xor

Size Manipulation Functions

FunctionNotes and Limitations
reshape

The output dlarray is unformatted, even if the input dlarray is formatted.

squeeze

Two-dimensional dlarray objects are unaffected by squeeze. If the input dlarray is formatted, the function removes dimension labels belonging to singleton dimensions. If the input dlarray has more than two dimensions and its third and above dimensions are singleton, then the function discards these dimensions and their labels.

Sorting and Transposition Operations

FunctionNotes and Limitations
sort (since R2024a)N/A
ctranspose, '

If the input dlarray is formatted, then the labels of both dimensions must be the same. The function performs transposition implicitly, and transposes directly only if necessary for other operations.

permute

If the input dlarray is formatted, then the permutation must be among only those dimensions that have the same label. The function performs permutations implicitly, and permutes directly only if necessary for other operations.

transpose, .'

If the input dlarray is formatted, then the labels of both dimensions must be the same. The function performs transposition implicitly, and transposes directly only if necessary for other operations.

Concatenation Functions

FunctionNotes and Limitations
cat

The dlarray inputs must have matching formats or be unformatted. Mixed formatted and unformatted inputs are supported. If any dlarray inputs are formatted, then the output dlarray is formatted with the same data format.

horzcat
vertcat

Conversion Functions

FunctionNotes and Limitations
cast
  • cast(A,newdatatype) copies the data in the dlarray A into a dlarray of the underlying data type newdatatype. The newdatatype option must be 'double', 'single', or 'logical'. The output dlarray is formatted with the same data format as A.

  • cast(A,'like',Y) returns an array of the same type as Y. If Y is a dlarray, then the output is a dlarray that has the same underlying data type as Y. If Y is on the GPU, then the output is on the GPU. If both A and Y are dlarray objects, then the output dlarray is formatted with the same data format as the input A.

double

The output is a dlarray that contains data of type double.

gather (Parallel Computing Toolbox)
  • The supported syntaxes are:

    • X = gather(A)

    • [X,Y,Z,...] = gather(A,B,C,...)

  • gather(A) returns a dlarray containing numeric or logical data. This function applies gather to the underlying data in the dlarray A. If A is on the GPU, then X is in the local workspace, not on the GPU. If A is in the local workspace (not on the GPU), then X is equal to A.

  • gather(A,B,C,...) gathers multiple arrays.

gpuArray (Parallel Computing Toolbox)
  • This function requires Parallel Computing Toolbox™.

  • gpuArray returns a dlarray containing a gpuArray. This function applies gpuArray to the underlying data. If the input dlarray is in the local workspace, then its data is moved to the GPU and internally represented as a gpuArray. If the input dlarray is on the GPU, then the output dlarray is equal to the input dlarray.

logicalThe output is a dlarray that contains data of type logical.
singleThe output is a dlarray that contains data of type single.

Comparison Functions

FunctionNotes and Limitations
isequal
  • The syntax with more than two input arguments is not supported.

  • Two dlarray inputs are equal if the numeric data they represent are equal and if they both are either formatted with the same data format or unformatted.

isequaln
  • The syntax with more than two input arguments is not supported.

  • Two dlarray inputs are equal if the numeric data they represent are equal (treating NaNs as equal) and if they both are either formatted with the same data format or unformatted.

Data Type and Value Identification Functions

FunctionNotes and Limitations
isdlarray N/A
isfinite

The software applies the function to the underlying data of an input dlarray.

isfloat
isgpuarray (Parallel Computing Toolbox)
isinf
islogical
isnan
isnumeric
isreal
isUnderlyingTypeN/A
mustBeUnderlyingType
underlyingType
validateattributesIf input array A is a formatted dlarray, its dimensions are permuted to match the order "SCBTU". Size validation is applied after permutation.

Size Identification Functions

FunctionNotes and Limitations
iscolumnThis function returns true for a dlarray that is a column vector, where each dimension except the first is a singleton. For example, a 3-by-1-by-1 dlarray is a column vector.
ismatrixThis function returns true for dlarray objects with only two dimensions and for dlarray objects where each dimension except the first two is a singleton. For example, a 3-by-4-by-1 dlarray is a matrix.
isrowThis function returns true for a dlarray that is a row vector, where each dimension except the second is a singleton. For example, a 1-by-3-by-1 dlarray is a row vector.
isscalarN/A
isvectorThis function returns true for a dlarray that is a row vector or column vector. Note that isvector does not consider a 1-by-1-by-3 dlarray to be a vector.
lengthN/A
ndims

If the input dlarray X is formatted, then ndims(X) returns the number of dimension labels, even if some of the labeled dimensions are trailing singleton dimensions.

numelN/A
size

If the input dlarray X is formatted, then size(X) returns a vector of length equal to the number of dimension labels, even if some of the labeled dimensions are trailing singleton dimensions.

Creator Functions

FunctionNotes and Limitations
false
  • Only the 'like' syntax is supported for dlarray.

  • The output dlarray is unformatted.

inf
nan
ones
rand
randi
randn
true
zeros
createArray (since R2024a)
  • You can create a dlarray object by doing one of the following:

    • Specifying className as "dlarray".

    • Specifying a dlarray object as the prototype array using the Like name-value argument.

    • Specifying the FillValue as a dlarray without specifying a className or a prototype array.

  • The output dlarray is unformatted.

String, Character, and Categorical Functions

FunctionNotes and Limitations
string

string(A) converts the data in the dlarray object A to a string array.

categoricalThe output is a categorical array.
composeN/A
fprintf
int2str
mat2str
sprintf
num2str

Visualization Functions

FunctionNotes and Limitations
plotPlotting functions do not support tracing.
addpoints

Notable dlarray Behaviors

Implicit Expansion with Data Formats

Some functions use implicit expansion to combine two formatted dlarray inputs. The function introduces labeled singleton dimensions (dimensions of size 1) into the inputs, as necessary, to make their formats match. The function inserts singleton dimensions at the end of each block of dimensions with the same label.

To see an example of this behavior, enter the following code.

X = ones(2,3,2);
X = dlarray(X,'SCB')
Y = 1:3;
Y = dlarray(Y,'C')
Z = X.*Y
X = 

  2(S) × 3(C) × 2(B) dlarray


(:,:,1) =

     1     1     1
     1     1     1


(:,:,2) =

     1     1     1
     1     1     1


Y = 

  3(C) × 1(U) dlarray

     1
     2
     3


Z = 

  2(S) × 3(C) × 2(B) dlarray


(:,:,1) =

     1     2     3
     1     2     3


(:,:,2) =

     1     2     3
     1     2     3
In this example, Z(i,j,k) = X(i,j,k).*Y(j) for indices i, j, and k. The second dimension of Z (labeled 'C') corresponds to the second dimension of X and the first dimension of Y.

In general, the format of one dlarray input does not need to be a subset of the format of another dlarray input. For example, if X and Y are input arguments with dims(X) = 'SCB' and dims(Y) = 'SSCT', then the output Z has dims(Z) = 'SSCBT'. The 'S' dimension of X maps to the first 'S' dimension of Y.

Special 'U' Dimension Behavior

The 'U' dimension of a dlarray behaves differently from other labeled dimensions in that it exhibits the standard MATLAB singleton dimension behavior. You can think of a formatted dlarray as having infinitely many 'U' dimensions of size 1 following the dimensions returned by size.

The software discards a 'U' label unless the dimension is nonsingleton or it is one of the first two dimensions of the dlarray.

To see an example of this behavior, enter the following code.

X = ones(2,2);
X = dlarray(X,'SC')
X(:,:,2) = 2
X = 

  2(S) × 2(C) dlarray

     1     1
     1     1


X = 

  2(S) × 2(C) × 2(U) dlarray


(:,:,1) =

     1     1
     1     1


(:,:,2) =

     2     2
     2     2
In this example, the software expands a formatted two-dimensional dlarray to a three-dimensional dlarray, and labels the third dimension with 'U' by default. For an example of how the 'U' dimension is used in implicit expansion, see Implicit Expansion with Data Formats.

Indexing

Indexing with a dlarray is supported and exhibits the following behaviors:

  • X(idx1,...,idxn) returns a dlarray with the same data format as X if n is greater than or equal to ndims(X). Otherwise, it returns an unformatted dlarray.

  • If you set Y(idx1,...,idxn) = X, then the data format of Y is preserved, although the software might add or remove trailing 'U' dimension labels. The data format of X has no impact on this operation.

  • If you delete parts of a dlarray using X(idx1,…,idxn) = [], then the data format of X is preserved if n is greater than or equal to ndims(X). Otherwise, X is returned unformatted.

Round-off Error

When you use a function with a dlarray input, the order of the operations within the function can change based on the internal storage order of the dlarray. This change can result in differences on the order of round-off for two dlarray objects that are otherwise equal.

See Also

| | |

Related Topics