Extract minimizer index for each subscript using `accumarray' with gpuArray

1 view (last 30 days)
I have an array if values `vals', and a corresponding array of subscripts `subs' with repeated subscripts into an output array. I would like to extract, for each subscript, the index of the minimizer of the corresponding items in 'vals'. To that end, I have the following piece of code:
function i = minimizer(idx)
[~, i] = min(vals(idx));
i = idx(i);
end
accum = accumarray(subs, (1:numel(vals))', [], @minimizer);
Now, assume that `subs' is a gpuArray. This code does not work because of a limitation of accumarray for gpuArrays - I cannot specify a custom aggregation function. Is there any fast alternative I can use for gpu arrays?
P.S. - what I thought of is embedding all the information into a complex array, so that real(vals) are the values and imag(vals) are the indices. But it does not seem to be clear how to ensure that the `min' function will compare only the values, e.g., by which factor I need to multiply the indices so that they become negligible in the comparison (I can ensure that the values are non-negative, so absolute value comparison is OK).

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!