首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推力remove_if使用thrust::zip_iterator,如何分隔pred?

推力remove_if使用thrust::zip_iterator,如何分隔pred?
EN

Stack Overflow用户
提问于 2020-04-15 01:38:49
回答 1查看 101关注 0票数 0

这是我的密码

压缩迭代器的定义

代码语言:javascript
复制
    `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的分红

代码语言:javascript
复制
struct is_less_than_zero_zip
   { 
      __host__ __device__
       bool operator()(ZipIterator & x)
       {
         return thrust::get<0>(x[0]) <= 5.0;
      }
   };

主功能启动

代码语言:javascript
复制
int main(void)
   {
    const int N=10;

向量定义

代码语言:javascript
复制
    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()));

问题是如何划分我的pred。

代码语言:javascript
复制
is_less_than_zero_zip pred;
thrust::remove_if(iter,iter+N,pred);

return 0;
}

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-15 17:24:59

我不确定我完全理解您的问题,但是如果我正确地理解了您,您正在尝试使您的自定义谓词正确工作。这是你应该做的改变。(顺便说一下,我不知道5.0是从哪里来的,因为您将您的结构命名为“is_less_than_zero”)。

代码语言:javascript
复制
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]
      }
   };
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61219940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档