如何使用 boost::compute 进行流压缩?
例如。如果您只想对数组中的某些元素执行繁重的操作。首先,生成掩码数组,其中包含与要执行操作的元素相对应的元素:
mask = [0 0 0 1 1 0 1 0 1]
然后对掩码数组进行排它扫描(前缀和)得到:
scan = [0 0 0 0 1 2 2 3 3]
然后用以下命令压缩该数组:
if (mask[i])
inds[scan[i]] = i;
要获得最终的压缩索引 (inds) 数组:
[3 4 6 8]
最终数组的大小是scan.last() + mask.last()
#include <boost/compute/algorithm/copy_if.hpp>
using namespace boost::compute;
detail::copy_index_if(mask.begin(), mask.end(), inds.begin(), _1 == 1, queue);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)