Skip to content

Limit iterations in EigenvalueDecomposition - #71

Open
wtn wants to merge 1 commit into
ruby:masterfrom
wtn:eigen
Open

wtn wants to merge 1 commit into
ruby:masterfrom
wtn:eigen

Conversation

@wtn

@wtn wtn commented Nov 16, 2026 •

Copy link
Copy Markdown

Matrix#eigensystem hangs in an infinite loop for a non-symmetric matrix of size 3 or more when the QR iteration in hessenberg_to_real_schur does not converge. This happens with a NaN entry, with most placements of an Infinity entry, and with finite entries above about 1e153, where the product of two entries overflows.

Matrix[[Float::NAN, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]].eigensystem
#=> hangs
Matrix[[1e308, 1e308, 3.0], [-1e308, 1e308, 1e308], [1e200, 1e308, 1e308]].eigensystem
#=> hangs

The QR iteration now counts steps and raises the new Matrix::ErrNotConverged after 30 * size steps, the limit EISPACK hqr2 uses. Matrix#** with a non-Integer exponent calls eigensystem, so m ** 0.5 hangs for the same matrices before this change and raises Matrix::ErrNotConverged after. Symmetric matrices use a separate loop, which is unchanged.

There is one more case: a matrix with very small numbers, below about 1e-163. Multiplying two numbers of this size gives 0 in floating point, so the loop takes many more steps than 30 * size. Matrix[[1e-300, 2e-300, 3e-300], [4e-300, 5e-300, 6e-300], [7e-300, 8e-300, 1e-299]].eigensystem returns a wrong answer before this change (largest eigenvalue 7.9e-300, correct value 1.67e-299) and raises Matrix::ErrNotConverged after.

Matrix#eigensystem hung in an infinite loop for a non-symmetric matrix
of size 3 or more when the QR iteration did not converge, for example
with a NaN entry or with entries that overflow or underflow. The QR
iteration now raises Matrix::ErrNotConverged after 30 * size steps.

Co-authored-by: Claude Mythos 5.2 <noreply@anthropic.com>
@wtn
wtn marked this pull request as draft November 16, 2026 20:10
@wtn
wtn marked this pull request as ready for review November 16, 2026 20:25

This branch has not been deployed

No deployments
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.

1 participant