Error when using branching in gpuArray/arrayfun
显示 更早的评论
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 个评论
Jill Reese
2013-12-4
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
2013-12-4
Also, what version of MATLAB are you running?
Jill Reese
2013-12-12
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
2013-12-12
Jill Reese
2013-12-12
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
2013-12-13
No problem. I'm glad that it's sorted out. :-)
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!