User`s guide
11 Functions — Alphabetical List
11-4
arrayfun
Apply function to each element of array on GPU
Syntax
A = arrayfun(FUN, B)
A = arrayfun(FUN,B,C,...)
[A,B,...] = arrayfun(FUN,C,...)
Description
This method of a gpuArray object is very similar in behavior to the MATLAB function
arrayfun, except that the actual evaluation of the function happens on the GPU, not on
the CPU. Thus, any required data not already on the GPU is moved to GPU memory, the
MATLAB function passed in for evaluation is compiled for the GPU, and then executed
on the GPU. All the output arguments return as gpuArray objects, whose data you can
retrieve with the gather method.
A = arrayfun(FUN, B) applies the function specified by FUN to each element of
the gpuArray B, and returns the results in gpuArray A. A is the same size as B, and
A(i,j,...) is equal to FUN(B(i,j,...)). FUN is a function handle to a function that
takes one input argument and returns a scalar value. FUN must return values of the
same class each time it is called. The input data must be an array of one of the following
types: numeric, logical, or gpuArray. The order in which arrayfun computes elements of
A is not specified and should not be relied on.
FUN must be a handle to a function that is written in the MATLAB language (i.e., not a
MEX-function).
For more detailed information, see “Run Element-wise MATLAB Code on GPU” on page
9-13. For the subset of the MATLAB language that is currently supported by arrayfun
on the GPU, see “Supported MATLAB Code” on page 9-15.
A = arrayfun(FUN,B,C,...) evaluates FUN using elements of arrays B, C, ... as
input arguments with singleton expansion enabled. The resulting gpuArray element
A(i,j,...) is equal to FUN(B(i,j,...),C(i,j,...),...). The inputs B, C, ... must