Using arrayfun is giving me an error
7 ビュー (過去 30 日間)
古いコメントを表示
Hello! I have a question about the use of arrayfun and a gpuArray. My function:
function [ pks, locs ] = peakDetector( gpu_signal, freq)
x = (1:numel(gpu_signal));
x = x.';
%%Get All The Peaks
% fetch indices all infinite peaks
iInf = find(isinf(gpu_signal) & gpu_signal>0);
yTemp = gpu_signal;
yTemp(iInf) = NaN;
% Do more stuff
end
And, in my main script, I try to use this function with a gpuArray and arrayfun:
signal_2 = gpuArray(signalCell{2});
[ pks, locs ] = arrayfun(@peakDetector,signal_2, freq);
However, the following error occurs: Function passed as first input argument contains unsupported or unknown function 'colon'. Error in 'peakDetector'
which corresponds to the first line of the function. If I take it off, then there's another error in the 3rd line of the code. If I run the script without a function and declare a lot of variables as gpuArrays, the code works. But it's still not so fast and I wanted do make it faster. According to MATLAB documentation, the built-in functions are overloaded for gpuArrays, so I don't understand what is wrong here. If arrayfun is impossible to use in this situation, would it be doable to parallelize the code with spmd and try to make it faster?
0 件のコメント
回答 (1 件)
Edric Ellis
2015 年 11 月 6 日
arrayfun is designed for purely element-wise operations. Your code appears to be attempting to operate on the whole value of gpu_signal. Does it work simply to call
peakDetector(signal_2, freq);
?
参考
カテゴリ
Help Center および File Exchange で GPU Computing in MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!