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!