Skip to content

Conversation

@gemenerik
Copy link
Member

Use np.linalg.eigh instead of np.linalg.eig for the symmetric matrix Q.T @ Q. eigh is designed for symmetric matrices and guarantees real eigenvalues/eigenvectors, whereas eig can return complex values due to numerical precision. This fixes a dtype mismatch error in scipy's Rotation.from_quat which now strictly validates input types.

Use np.linalg.eigh instead of np.linalg.eig for the symmetric matrix
Q.T @ Q. eigh is designed for symmetric matrices and guarantees real
eigenvalues/eigenvectors, whereas eig can return complex values due to
numerical precision. This fixes a dtype mismatch error in scipy's
Rotation.from_quat which now strictly validates input types.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in quaternion averaging that was causing dtype mismatch errors in scipy's Rotation.from_quat method. The fix uses the mathematically correct np.linalg.eigh function for symmetric matrices instead of np.linalg.eig, which can return complex values due to numerical precision issues.

Changes:

  • Replaced np.linalg.eig with np.linalg.eigh for computing eigenvalues/eigenvectors of the symmetric matrix Q.T @ Q
  • Updated to use the last eigenvector (largest eigenvalue) by indexing with [-1] instead of using argmax()
  • Changed from in-place array multiplication to explicit assignment for clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@ArisMorgens ArisMorgens left a comment

Choose a reason for hiding this comment

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

Nice fix!

@ArisMorgens ArisMorgens merged commit 8900f0d into master Jan 20, 2026
7 checks passed
@ArisMorgens ArisMorgens deleted the rik/lheigh branch January 20, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants