Vector3.normalized / Vector2.normalized return NaN for a zero vector in float16 (zero in every other dtype): F.normalize's eps=1e-12 floor underflows, the #4021 twin
Vector3.normalized() and Vector2.normalized() divide by F.normalize's norm floor, eps = 1e-12 (kornia/geometry/vector.py:90 and :227). In float16 that floor rounds to 0, so the zero vector becomes 0 / 0 = NaN. In bfloat16, float32 and float64 the zero vector stays zero. This is the defect #4021 reported for normalize_quaternion. #4162 fixed it there by flooring a positive eps at the dtype's smallest subnormal, but the two normalized methods call F.normalize directly and were not covered.
import torch
from kornia.geometry.vector import Vector2, Vector3
for device in ("cpu", "mps"):
for dtype in (torch.float16, torch.bfloat16, torch.float32):
v3 = Vector3(torch.zeros(1, 3, device=device, dtype=dtype)).normalized()
v2 = Vector2(torch.zeros(1, 2, device=device, dtype=dtype)).normalized()
print(device, dtype, v3.data.tolist(), v2.data.tolist())cpu torch.float16 [[nan, nan, nan]] [[nan, nan]]
cpu torch.bfloat16 [[0.0, 0.0, 0.0]] [[0.0, 0.0]]
cpu torch.float32 [[0.0, 0.0, 0.0]] [[0.0, 0.0]]
mps torch.float16 [[nan, nan, nan]] [[nan, nan]]
mps torch.bfloat16 [[0.0, 0.0, 0.0]] [[0.0, 0.0]]
mps torch.float32 [[0.0, 0.0, 0.0]] [[0.0, 0.0]]kornia main 78cd06c35, torch 2.14.0, macOS arm64 (CPU and MPS).
ParametrizedLine.through(p, p) normalises p1 - p0 the same way (kornia/geometry/line.py:110) and gives a NaN direction in float16 for coincident points. That case is also degenerate input, which #5041 (PR #5054) turns into a ValueCheckError while value checks are enabled.
Classification
Kornia defect: the result for the same input depends on the dtype, 0 in three dtypes and NaN in float16. It is the float16 half of the F.normalize floor. The other half, a short nonzero vector scaled to length ‖v‖ / eps, is recorded on #3952 (comment 5858923931). That comment's "the zero vector stays zero" holds for every dtype except float16.
Disposition
Floor the norm with the #4162 guard, or share a helper with normalize_quaternion, in both normalized methods (and in ParametrizedLine.through, unless #5054's check makes that moot). Then pin the zero vector at every dtype. The batch-10 convention docstring for Vector3.normalized names this defect.
Posted on behalf of @ducha-aiki by Claude (Opus 5.5).
Source: kornia/kornia