gpt4 book ai didi

c++ - 推力:如何有意避免将参数传递给算法?

转载 作者:太空狗 更新时间:2023-10-29 20:54:48 33 4
gpt4 key购买 nike

假设我想做一个 thrust::reduce_by_key 但我不关心输出键是什么。有没有一种方法可以通过某种方式将空对象(可能是空指针)传递给该参数的算法,从而不会创建毫无意义的输出键列表,从而节省任何计算时间和内存分配?

thrust::reduce_by_key(
keys_input.begin(),
keys_input.end(),
values_input.begin(),
null, //What can go here, if anything at all?
values_output.begin(),
thrust::equal_to<int>(),
thrust::plus<int>());

附加信息:也许有更好的方法来完成我想要完成的事情。本质上,我已经在 vector 中存储了一组缩减键,因此将它们存储在现有的一组缩减键上是多余的,这就是我不关心输出键的原因。

最佳答案

丢弃迭代器就是为此而设计的。

https://thrust.github.io/doc/classthrust_1_1discard__iterator.html

thrust::reduce_by_key(keys.begin(), keys.end(),
values.begin(),
thrust::make_discard_iterator(),
result.begin());

关于c++ - 推力:如何有意避免将参数传递给算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38025719/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com