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

15 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Jill Reese
Jill Reese il 30 Dic 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?
  1 Commento
LASIN T
LASIN T il 10 Ago 2022
I made everything same length and I am still getting the same error, "Use of functional workspace is not supported."

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by