[BUG] A column with one infinity sums to NaN in `raft::stats::sum`
Describe the bug
Put one positive infinity in a column of 32 floats and fill the rest with ones. raft::stats::sum returns NaN. The same thing happens with a single negative infinity and with doubles.
Steps to reproduce
#include <raft/stats/sum.cuh>
#include <rmm/device_uvector.hpp>
#include <array>
#include <cstdio>
#include <limits>
int main()
{
raft::resources handle;
auto stream = raft::resource::get_cuda_stream(handle);
std::array<float, 32> host;
host.fill(1.0f);
host[0] = std::numeric_limits<float>::infinity();
rmm::device_uvector<float> x(host.size(), stream), y(1, stream);
raft::update_device(x.data(), host.data(), host.size(), stream);
raft::stats::sum(handle,
raft::make_device_matrix_view<const float, int, raft::row_major>(x.data(), 32, 1),
raft::make_device_vector_view(y.data(), 1));
float result;
raft::update_host(&result, y.data(), 1, stream);
raft::resource::sync_stream(handle);
std::printf("%g\n", double(result));
}
Expected behavior
The example should print inf. Changing the first entry to negative infinity should give -inf. A column that contains both signs of infinity should still give NaN.
Environment
RAFT main at b74966f, CUDA 12.9.1, GeForce GTX 1660 SUPER, driver 580.159.03. The example was compiled against the source headers with nvcc in the nvidia/cuda:12.9.1-devel-ubuntu24.04 image on Vast.ai.
Additional context
The running sum reaches infinity, then the compensation step subtracts infinity from itself and gets NaN. Adding that correction back changes the result. A local patch keeps the ordinary partial sum when it is already nonfinite. The same example prints inf with that patch.