を与えている。この
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);
}
次のようになります。
#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
さて、私はそれを試してみました、エラーが発生しています 'エラーエラー:オーバーロードされた関数のインスタンスがありません" thrust :: copy_if "は引数リストと一致します – ragnar
クールな、それは動作しているようです。 '推理::プレースホルダー'がどのように機能するかに関する文書はありますか?また、1次元イテレータと一緒に反復する3次元イテレータを作成する最良の方法は何ですか?すなわち、私は3次元座標を知りたいが、単純に線形メモリにアクセスするために単一のインデックスに戻すことは無駄に思える。 – ragnar
@ragnar:おそらく、 'transform_iterator'を使って線形インデックスを多次元座標に変換することができます。 –