Skip to content

fix(trackingutils): take the real part of eig eigenvectors in EllipseFitter - #3502

Merged
deruyter92 merged 1 commit into
DeepLabCut:devfrom
michael-denyer:fix/ellipse-fit-complex-eig
Sep 9, 2026
Merged

deruyter92 merged 1 commit into
DeepLabCut:devfrom
michael-denyer:fix/ellipse-fit-complex-eig

Conversation

@michael-denyer

Copy link
Copy Markdown

Why

With numpy 2, numba types the output of np.linalg.eig as complex128, so the jitted EllipseFitter._fit fails to type T @ a1 (float64 matrix against a complex vector) and fit raises numba.core.errors.TypingError. The ellipse fit only ever uses real eigenvectors, so this takes the real part explicitly. On numpy 1 numba types the same call as float64 and .real is a no-op, so results are unchanged there.

Found while testing dev with numpy 2.5.3 ahead of #3499.

Scope

  • deeplabcut/core/trackingutils.py: EllipseFitter._fit takes V.real after np.linalg.eig.

Blast Radius

EllipseFitter is used by the SORT ellipse tracker. Behaviour on numpy 1 is identical; on numpy 2 it goes from raising to working.

Verification

tests/test_trackingutils.py::test_ellipse_fitter on this branch, Python 3.12, numba 0.67.0:

  • numpy 2.5.3: fails before the change with TypingError: '@' arguments must all have the same dtype, passes after.
  • numpy 1.26.4: passes before and after.

…Fitter

Under numpy 2 numba types np.linalg.eig output as complex128, so the
jitted _fit fails to type T @ a1. The fit needs the real part; taking it
explicitly keeps the same result on numpy 1. Covered by
tests/test_trackingutils.py::test_ellipse_fitter, which fails before and
passes after on numpy 2.5.3 with numba 0.67.0.
@C-Achard C-Achard self-assigned this Sep 9, 2026

@C-Achard C-Achard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @michael-denyer, this is a useful fix.

@deruyter92 Not needed here but we may want to add in a follow-up:

  • On np2, V.real truncates complex egvs instead of raising, so cond > 0 can select nothing and V[:, cond > 0][:, 0] then reads out of bounds.
  • Pre-existingthis, if not (cond > 0).any(): return np.full(6, np.nan), which lets fit()'s existing NaN check return None.

@deruyter92
deruyter92 merged commit fce1e4f into DeepLabCut:dev Sep 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants