Error when using branching in gpuArray/arrayfun
Show older comments
Hello,
I would like to pass a custom function into arrayfun, while only making use of supported built-in Matlab functions in element-wise operations within my custom function. When I make use of branching instructions in the custom function, I get the error message "Conversion to logical from gpuArray is not possible." The corresponding code (running excerpt):
sa = gpuArray.zeros(4,3,3);
sb = gpuArray.ones(4,3,3).*0.4;
t = gpuArray.ones(4,3,3).*1e-5;
x = sa + 0.5 .* ( sb - sa );
while ( 1 )
m = 0.5 * ( sa + sb );
tol = abs ( x ) + t;
t2 = 2.0 * tol;
%(...)
if ( abs ( x - m ) <= t2 - 0.5 * ( sb - sa ) )
break
end
%(...)
end
Already in the first place, I do not see which variable is converted by the if-statement. Further, if branching instructions are supported by arrayfun, what is the reason for the error message?
Calling the function within my main code (not quoted here), I receive the following error message: "Error using gpuArray/arrayfun Variable 'r' changed type. Consider renaming variable on left hand side of assignment"
I think that this is directly related to the previous problem (the reason why I posted the smaller example first). What can I do to make my custom function work with arrayfun?
Best,
Christoph
8 Comments
Jill Reese
on 4 Dec 2013
It is not clear to me from the above code what your custom function actually looks like, including what its inputs and outputs are. Can you please clarify which of the above code is (1) the data passed to arrayfun, (2) the contents of your custom function, (3) how you actually invoke arrayfun with the handle to your custom function.
Jill Reese
on 4 Dec 2013
Also, what version of MATLAB are you running?
Jill Reese
on 12 Dec 2013
Christoph, it would help to see the entire contents of the local_min function if it is not too long. In the code that you initially posted, I can't see where any change of type might occur. Also, for your information, you don't need to multiply your scalars by an array of ones so that all variables have the same dimension. Arrayfun on the GPU supports scalar expansion of input variables.
Christoph
on 12 Dec 2013
Jill Reese
on 12 Dec 2013
I don't see any compilation error in R2013a when calling your local_min via arrayfun with all double gpuArray inputs. I know there are a lot of inputs to your function, but if you can give me a sense of what their types are I may be able to reproduce the problem.
Jill Reese
on 13 Dec 2013
No problem. I'm glad that it's sorted out. :-)
Answers (0)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!