Find the minima of the rows of a matrix along with their corresponding column indices with CUDA Thrust

Suppose to have a matrix and that you want to find the minima (or, of course, the maxima) of the rows of that matrix along with their corresponding column indices.
For example, if you have the following matrix:

[ 0 1 12 18 20 3 10 8 ]
[ 5 15 1 11 12 17 12 10 ]
[ 18 20 15 20 6 8 18 13 ]
[ 18 20 3 18 19 6 19 8 ]
[ 6 10 8 16 14 11 12 1 ]
[ 12 9 12 17 10 16 1 4 ]

you want the following output:

Min position = 0; Min value = 0
Min position = 2; Min value = 1
Min position = 4; Min value = 6
Min position = 2; Min value = 3
Min position = 7; Min value = 1
Min position = 6; Min value = 1

This is easy to achieve with CUDA Thrust and on our GitHub website can find a fully worked example.

Leave a Reply

Your email address will not be published. Required fields are marked *