Repository navigation
fix(trackingutils): take the real part of eig eigenvectors in EllipseFitter - #3502
Merged
deruyter92 merged 1 commit intoSep 9, 2026
Merged
Conversation
…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
approved these changes
Sep 9, 2026
C-Achard
left a comment
Member
There was a problem hiding this comment.
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
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
With numpy 2, numba types the output of
np.linalg.eigascomplex128, so the jittedEllipseFitter._fitfails to typeT @ a1(float64 matrix against a complex vector) andfitraisesnumba.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.realis a no-op, so results are unchanged there.Found while testing
devwith numpy 2.5.3 ahead of #3499.Scope
deeplabcut/core/trackingutils.py:EllipseFitter._fittakesV.realafternp.linalg.eig.Blast Radius
EllipseFitteris 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_fitteron this branch, Python 3.12, numba 0.67.0:TypingError: '@' arguments must all have the same dtype, passes after.