User`s guide
11 Functions — Alphabetical List
11-210
pagefun
Apply function to each page of array on GPU
Syntax
A = pagefun(FUN,B)
A = pagefun(FUN,B,C,...)
[A,B,...] = pagefun(FUN,C,...)
Description
pagefun iterates over the pages of a gpuArray, applying the same function to each page.
A = pagefun(FUN,B) applies the function specified by FUN to each page of the
gpuArray B, and returns the results in gpuArray A, such that A(:,:,I,J,...) =
FUN(B(:,:,I,J,...)). FUN is a handle to a function that takes a two-dimensional
input argument.
You can use gather to retrieve the array from the GPU back to the MATLAB workspace.
A = pagefun(FUN,B,C,...) evaluates FUN using pages of the arrays B, C, etc., as
input arguments with scalar expansion enabled. Any of the input page dimensions that
are scalar are virtually replicated to match the size of the other arrays in that dimension
so that A(:,:,I,J,...) = FUN(B(:,:,I,J,...), C(:,:,I,J,...),...). At least
one of the inputs B, C, etc. must be a gpuArray. Any other inputs held in CPU memory
are converted to a gpuArray before calling the function on the GPU. If an array is to
be used in several different pagefun calls, it is more efficient to convert that array to
a gpuArray before your series of pagefun calls. The input pages B(:,:,I, J, ...),
C(:,:,I, J, ...), etc., must satisfy all of the input and output requirements of FUN.
[A,B,...] = pagefun(FUN,C,...), where FUN is a handle to a function that returns
multiple outputs, returns gpuArrays A, B, etc., each corresponding to one of the output
arguments of FUN. pagefun invokes FUN with as many outputs as there are in the call to
pagefun. All elements of A must be the same class; B can be a different class from A, but
all elements of B must be of the same class; etc.
FUN must return values of the same class each time it is called. The order in which
pagefun computes pages is not specified and should not be relied on.