Using arrayfun is giving me an error
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Edric Ellis
on 6 Nov 2015
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);
?
See Also
Categories
Find more on Parallel Computing Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!