thrust remove_if с помощью thrust :: zip_iterator, как разделить пред.? - PullRequest
0 голосов
/ 15 апреля 2020

это мой код


определение zip-итератора

    `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;`

отличия от pred


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

main запуск функции

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

определение вектора


    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()));

вопрос в том, как определить мой пред


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

return 0;
}

Спасибо

1 Ответ

0 голосов
/ 15 апреля 2020

Я не уверен, что полностью понимаю ваш вопрос, но если я вас правильно понимаю, вы пытаетесь заставить ваш пользовательский предикат работать правильно. Вот изменения, которые вы должны сделать. (Кстати, я не знаю, откуда появился 5.0, так как вы назвали свою структуру "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]
      }
   };
...