Extract minimizer index for each subscript using `accumarray' with gpuArray
6 次查看(过去 30 天)
显示 更早的评论
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).
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!