I have two arrays of integers dmap
and dflag
on the device of
the same length
and I have wrapped them with thrust device pointers, dmapt
and
dflagt
There are some elements in the dmap array with value -1. I want to remove these -1's and the corresponding values from the dflag array.
I am using the remove_if function to do this, but I cannot figure out what the return value of this call is or how I should use this returned value to get .
( I want to pass these reduced arrays to the reduce_by_key
function
where dflagt will be used as the keys. )
I am using the following call for doing the reduction. Please let me
know how I can store the returned value in a variable and
use it to address the individual arrays dflag
and dmap
thrust::remove_if(
thrust::make_zip_iterator(thrust::make_tuple(dmapt, dflagt)),
thrust::make_zip_iterator(thrust::make_tuple(dmapt+numindices, dflagt+numindices)),
minus_one_equality_test()
);
where the predicate functor used above is defined as
struct minus_one_equality_test
{
typedef typename thrust::tuple<int,int> Tuple;
__host__ __device__
bool operator()(const Tuple& a )
{
return thrust::get<0>(a) == (-1);
}
}
The return value is a zip_iterator which marks the new end of the sequence of tuples for which your functor returned true during the remove_if call. To access the new end iterator of the underlying array you will need to retrieve a tuple iterator from the zip_iterator; the contents of that tuple are then the new end iterators of the original arrays you used to build the zip_iterator. It is a lot more convoluted in words than in code:
If you compile this and run it, you should see something like this:
In this example I only "retrieve" the shorted contents of the first element of the tuple, the second is accessed in the same way, ie. the iterator marking the new end of the vector is
thrust::get<1>(Tend)
.