#4635·kornia

Explicit (lo, hi) ranges containing inf/nan are still accepted where the scalar form now rejects them

Author: Yi-111-aCreated Sep 17, 2026Updated Sep 17, 2026

Follow-up to #4621 / PR #4625.

PR #4625 makes _range_bound reject a non-finite scalar magnitude (factor.dim() == 0), so RandomSharpness(float("inf")) now raises ValueError at construction. The equivalent explicit range form takes the non-scalar branch and is still accepted:

python
RandomSharpness((0.0, float("inf")))        # accepted; UniformDistribution(0, inf) -> NaN at forward
ColorJitter(contrast=(0.0, float("inf")))   # accepted; NaN at forward
RandomAffine(0., scale=(0., float("inf")))  # accepted; NaN at forward
_range_bound((0.0, float("inf")), "param")  # -> tensor([0., inf])

So the scalar and pair forms of the same parameter now disagree — the pair form can still build an infinite draw range and produce inf * 0 -> NaN in the forward blend, exactly the defect #4621 reported for the scalar form. _range_bound's docstring also still describes the two forms as agreeing.

Possible directions (not mutually exclusive):

  • extend the finiteness check to the pair branch of _range_bound (and decide what bounds=(0, inf) means for an explicit (0, inf) range — arguably legal as a half-open domain declaration rather than a draw range);
  • or check finiteness where the draw range is consumed (the UniformDistribution/random_generator sites), which would also catch nan endpoints;
  • update the _range_bound docstring whichever way the semantics land.

Reproduced on main at 8c71df9a0 (CPU, torch 2.14): forward on torch.rand(2, 3, 8, 8) with RandomSharpness((0.0, float("inf")), p=1.0) returns a tensor with NaN fraction 0.4375.