Missing two range overload for `thrust::transform_reduce`
I was recently writing the following code using C++17:
auto max_gap(std::vector<int> nums) -> int {
return std::transform_reduce(
nums.begin() + 1, nums.end(), nums.begin(), 0,
[](auto a, auto b) { return std::max(a, b); },
std::minus{});
}
and when I went to write the equivalent in Thrust it wasn't possible because there is no two range overload of thrust::transform_reduce. The C++17 std::transform_reduce has both a one range and two range overload. Because of this, the morally equivalent code in Thrust is:
auto max_gap(std::vector<int> nums) -> int {
return thrust::transform_reduce(
thrust::make_zip_iterator(thrust::make_tuple(nums.begin() + 1, nums.begin())),
thrust::make_zip_iterator(thrust::make_tuple(nums.end(), nums.end() - 1)),
[](auto t) { return thrust::get<0>(t) - thrust::get<1>(t); }, 0,
[](auto a, auto b) { return std::max(a, b); });
}
which is far from ideal.
I would recommend adding the two range overload of thrust::transform_reduce in order to:
- Be more consistent with what is available in standard C++
- Avoid the necessary code in the 2nd example above.
I'd be happy to work on this if a maintainer would be willing to accept a PR implementing this functionality.
cc @senior-zero
@tfsingh thank you for reaching out and offering to contribute to our library. We welcome contributions from the community. Feel free to open a PR, and please do not hesitate to discuss any questions that require clarification on this issue or the relevant PR.
Sounds great, @senior-zero . There may be a bit of a learning curve as this will be my first time working on thrust, but I'm excited to make a contribution.
Closing for the same reason as https://github.com/NVIDIA/cccl/issues/5160#issuecomment-5096893432. @codereport if you are still interested, try cuda:: PSTL and if overload is not there, file another issue.