我有一个扩展推力矢量的特殊要求。 假设我有关键向量K,以及值向量V和扩展因子E的向量,它对应于关键向量。 我想通过(扩展因子)次复制与某个键对应的值。我查看了几个Thrust :: expand示例,但它似乎不适用于我的特定用法。 push :: reduce_by_key可以很容易地为结果数组分配空间,但我不知道如何实际扩展我的向量。
例如:
key is [0,0,0,1,2,2,2,2,4]
value is [1,2,3,5,6,7,8,4,7]
key 0 has values [1,2,3]
key 1 has value [5]
key 2 has values [6,7,8,4]
key 4 has value [7]
(This is not code but the website won't let me submit unless I indent these statements)
扩展因子数组:
Expansion factor: [2,3,1,1,3]
desired result array: [1,2,3,1,2,3,5,5,5,6,7,8,4,7,7,7]
1,2,3 are the values of key[0], expanded 2 times according to E[0]
5 is the value of key[1], expanded 3 times according to E[1]
6,7,8,4 are the values of key[2], expanded 1 times according to E[2]
[none] is the value of key[3], expanded 1 times according to E[3]
7 is the value of key[4], expanded 3 times according to E[4]
有一种有效的方法吗? 提前致谢。
答案 0 :(得分:2)
原始海报报告了这个问题的解决方案如下:
thrust::expand
展开它。key[(iterator - exclusive scan result)%number of elements]
的起始位置是当前迭代器的结果此评论已添加此社区维基条目,以便将问题从未答复的列表中删除。