Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#5082·kornia

`fit_line` with weights that are positive on a single point (or on identical points) returns an arbitrary direction instead of raising

Author: ducha-aikiCreated Sep 28, 2026Updated Sep 28, 2026

#5041 (fixed by #5054) makes fit_line raise ValueCheckError for fewer than two points, for identical points and for a non-positive weight sum. A weighted set whose positive-weight points are all the same point is just as degenerate, because points with weight 0 do not count (#5029). It still returns the fallback directions that #5041 rejects for unweighted input:

python
import torch
from kornia.geometry.line import fit_line

pts = torch.tensor([[[0.0, 0.0, 0.3], [1.0, 0.4, -0.2], [2.5, 0.9, 0.1]]], dtype=torch.float64)
for D in (2, 3):
    for w in ([1.0, 0.0, 0.0], [0.0, 0.0, 2.0]):
        l = fit_line(pts[..., :D], torch.tensor([w], dtype=torch.float64))
        print(D, w, l.origin.tolist(), l.direction.tolist())
2 [1.0, 0.0, 0.0] [[0.0, 0.0]] [[0.0, 1.0]]
2 [0.0, 0.0, 2.0] [[2.5, 0.9]] [[0.0, 1.0]]
3 [1.0, 0.0, 0.0] [[0.0, 0.0, 0.3]] [[1.0, 0.0, 0.0]]
3 [0.0, 0.0, 2.0] [[2.5, 0.9, 0.1]] [[1.0, 0.0, 0.0]]

kornia main efed254b9 and the #5054 head, torch 2.14.0, CPU float64. The unweighted fits of the same points point along (0.94, 0.34) and (-0.94, -0.34, 0.06).

Expected: the #5041 rule applied to the points with positive weight. For each row, some point with positive weight must differ from another point with positive weight. For example, take the reference point at argmax(weights) and require ((points != ref).any(-1) & (weights > 0)).any(-1). Like the other checks, this is skipped under torch.compile and disable_checks().

Posted on behalf of @ducha-aiki by Claude (Opus 5.5).

Source: kornia/kornia

View original on GitHubView discussion on GitHub