#10300·cupy

Very niche `out=` bug in CUB fast-path

Author: sebergCreated Sep 11, 2026Updated Sep 28, 2026
Labelscat:bugprio:medium

The CUB fast-path does some mutation under the assumption that out= is not user-passed. It could maybe recover some if it knew that part (if it doesn't, the fast-path needs to just reject this). As such, changing the output order for a freshly allocated result is somewhat OK (if awkward).

Until then, these two fail, but shouldn't:

python
import cupy
a = cupy.asfortranarray(cupy.ones((128, 2, 2)))
out = cupy.zeros((2, 2))
cupy.nansum(a, axis=0, out=out)
assert out.flags.c_contiguous  # `out` strides got mutated

And here showing that it corrupts the input in principle

import cupy
a = cupy.asfortranarray(cupy.ones((128, 2, 2)))
base = cupy.zeros((2, 4))
cupy.nansum(a, axis=0, out=base[:, ::2])
assert (base[:, 1::2] == 0).all(), base