MATLAB Answers

Soohun
0

Error using gpuArray/arrayfun ... Use of functional workspace is not supported.

Asked by Soohun
on 26 Dec 2013
Latest activity Answered by Jill Reese
on 30 Dec 2013
I define a simple function of summation.m as follows:
--------------------------------------------
function out = summation(a, b, c, d)
out = a+b+c+d;
--------------------------------------------
Then, I run the following code:
--------------------------------------------
R1 = gpuArray.rand(10,10);
R2 = gpuArray.rand(10,10);
R3 = gpuArray.rand(10,10);
f = @(a,b,c)summation( a, b, c, 5);
R = arrayfun(f,R1,R2,R3);
--------------------------------------------
This works fine. However, if I change the function handle as
--------------------------------------------
R1 = gpuArray.rand(10,10);
R2 = gpuArray.rand(10,10);
R3 = gpuArray.rand(10,10);
*_d = 5;_*
f = @(a,b,c)summation( a, b, c, *_d_* );
R = arrayfun(f,R1,R2,R3);
--------------------------------------------
I get the error message "Error using gpuArray/arrayfun Use of functional workspace is not supported." Is there a way to resolve this issue? I would like to resolve this so that I can use GPU in the case that d is either a vector or a matrix.

  0 Comments

Sign in to comment.

2 Answers

Answer by Jill Reese
on 30 Dec 2013

As of the latest MATLAB release (R2013b) arrayfun on the GPU does not support anonymous functions that have been created using variables from the existing MATLAB workspace. This is the meaning of the error message you have encountered.
Unless I am missing something, you should not need to create your function handle using your variable, d. Arrayfun on the GPU supports scalar expansion so d can be a scalar, a vector, or a matrix as long as its dimensions are either the same as your R1, R2, and R3 variables or the dimension is 1. So for the dimensions you mention above, d can be passed into the arrayfun call in the same way as R1, R2, and R3 and the call will succeed if d has size 1 x 1, 10 x 1, 1 x 10, or 10 x 10. Does this not work for you?

  0 Comments

Sign in to comment.


Answer by Matt J
on 27 Dec 2013

You must do
R = arrayfun(@summation,R1,R2,R3,d);

  0 Comments

Sign in to comment.