I have following function which I would like to apply to each element:
function result = f(a, b, bs)
% Simplified code
result = a
for i=0:bs
result = dosomething(result, b(i))
end
end
% Use
arrayfun(@result, gpuArray(A), gpuArray(B), size(B));
Is there a way of ‘tricking’ MATLAB into thinking b is scalar for purpose of passing to function?
The only way to do it is to use
bsxfunfunction:is more or less equivalent to
Other useful function is
repmat.Then the series of matrices and vectors are JITted so there is in effect no
O(MN)space penalty (checked bynvidia-smi).