首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何返回活动数组元素的索引

如何返回活动数组元素的索引
EN

Stack Overflow用户
提问于 2012-03-16 05:38:59
回答 1查看 930关注 0票数 2

如何使用推力返回活动数组元素的索引,即返回数组元素等于1的索引向量?

在此基础上展开,在给定数组维数的多维索引的情况下,这将如何工作?

编辑:当前函数如下所示

代码语言:javascript
复制
template<class VoxelType>
void VoxelVolumeT<VoxelType>::cudaThrustReduce(VoxelType *cuda_voxels)
{
    device_ptr<VoxelType> cuda_voxels_ptr(cuda_voxels);

    int active_voxel_count = thrust::count(cuda_voxels_ptr, cuda_voxels_ptr + dim.x*dim.y*dim.z, 1);

    device_vector<VoxelType> active_voxels;

    thrust::copy_if(make_counting_iterator(0), 
                    make_counting_iterator(dim.x*dim.y*dim.z),
                    cuda_voxels_ptr,
                    active_voxels.begin(),
                    _1 == 1);
}

这就给出了错误

代码语言:javascript
复制
Error   15  error : no instance of overloaded function "thrust::copy_if" matches the argument list
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-16 06:55:03

counting_iteratorcopy_if结合使用

代码语言:javascript
复制
#include <thrust/copy.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/functional.h>
...
using namespace thrust;
using namespace thrust::placeholders;

copy_if(make_counting_iterator<int>(0),
        make_counting_iterator<int>(array.size()), // indices from 0 to N
        array.begin(),                             // array data
        active_indices.begin(),                    // result will be written here
        _1 == 1);                                  // return when an element or array is equal to 1
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9728594

复制
相关文章

相似问题

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