I have two thrust device vectors, let's say a and b. I would like to find the indices of vector a where it is smaller/greater than the pair-wise component of vector b ($a_{ij}>b_{ij}$).
I found the following links on how to do it with a scalar:
My main problem is that transform only takes one vector as input while as for the other approach, I am not sure how to do a pair-wise comparison.
Example: a = {1,3,5,6,9} and b = {2,1,4,7,8}. I am looking for indices where a_ij >b_ij.
Therefore, the output should be {1,2,4} with 0-indexed as a is larger at these places than the pair-wise component of b.
This is at least partially a stream-compaction problem. Thrust provides algorithms for stream compaction such as
copy_if.Thrust does have a
transformvariant that accepts two vectors as input. You can also do something similar withzip_iteratoras input to any thrust algorithm.I think the most compact method will be to use
copy_ifwith both a zip iterator and a counting iterator. There is acopy_ifvariant that accepts a stencil array, and that works well for our purpose here.Here is an example: