thrust count occurence [duplicate]

送分小仙女□ 提交于 2019-12-02 06:35:58

You can first sort the vector using thrust::sort and then use thrust::reduce_by_key. However, you also need to create a new vector (called values) of 1's (and of the same length as your sorted vector) after sort. These values will be added up to get the counts:

reduce_by_key is a generalization of reduce to key-value pairs. 
For each group of consecutive keys in the range [keys_first, keys_last) 
that are equal, reduce_by_key copies the first element of the group to 
the keys_output. The corresponding values in the range are reduced using 
the plus and the result copied to values_output.

You could use a combination of thrust::unique and thrust::binary_search to find duplicates. You won't be able to do it in place using this approach, but it can be done just using thrust code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!