Search code examples
copythrustremove-if

thrust remove_if using the thrust::zip_iterator,how to delimit pred?


this is my code


a definition of the zip-iterator

    `using namespace std;
    typedef thrust::device_vector<unsigned int>::iterator   IntIterator;
    typedef thrust::device_vector<float>::iterator FloatIterator;

    typedef thrust::tuple<IntIterator, FloatIterator> IteratorTuple;
    typedef thrust::zip_iterator<IteratorTuple> ZipIterator;`

a difintion of the pred


struct is_less_than_zero_zip
   { 
      __host__ __device__
       bool operator()(ZipIterator & x)
       {
         return thrust::get<0>(x[0]) <= 5.0;
      }
   };

main function start

int main(void)
   {
    const int N=10;

vector defintion


    thrust::host_vector<unsigned int> h_values;
    h_values = thrust::host_vector<unsigned int>(N);
    thrust::sequence(h_values.begin(), h_values.end());
    thrust::device_vector<unsigned int> d_values;

    d_values = h_values;



    thrust::device_vector<float> d_keys;
    d_keys=h_keys;

    ZipIterator iter(thrust::make_tuple(d_values.begin(), d_keys.begin()));

the question is how to delimit my pred


is_less_than_zero_zip pred;
thrust::remove_if(iter,iter+N,pred);

return 0;
}

Thanks


Solution

  • I'm not sure I fully understand your question, but if I understand you correctly, you are trying to get your custom predicate to work correctly. Here are the changes you should make. (By the way, I don't know where the 5.0 comes from since you named your struct "is_less_than_zero.")

    struct is_less_than_zero_zip
       { 
          __host__ __device__
           bool operator()(const thrust::tuple<int, float>& x)
           {
             return thrust::get<0>(x) <= 0; // get<0> instead of x[0]
          }
       };