这是我的密码
压缩迭代器的定义
`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;
}
};主功能启动
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()));问题是如何划分我的pred。
is_less_than_zero_zip pred;
thrust::remove_if(iter,iter+N,pred);
return 0;
}谢谢
发布于 2020-04-15 17:24:59
我不确定我完全理解您的问题,但是如果我正确地理解了您,您正在尝试使您的自定义谓词正确工作。这是你应该做的改变。(顺便说一下,我不知道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]
}
};https://stackoverflow.com/questions/61219940
复制相似问题