Skip to content

Handle an invariant subspace smaller than howmany consistently - #176

Open
leburgel wants to merge 5 commits into
Jutho:masterfrom
leburgel:lb/invariant_subspace
Open

leburgel wants to merge 5 commits into
Jutho:masterfrom
leburgel:lb/invariant_subspace

Conversation

@leburgel

@leburgel leburgel commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

If the Krylov subspace becomes invariant at a dimension K < howmany, e.g. because of degenerate eigenvalues or singular values, svdsolve and realeigsolve threw a BoundsError, and the other solvers reported the event in different ways. This PR makes all of them return the K values found with a single, uniform warning:

A = Diagonal([1.0, 1, 2, 2, 3, 3])
svdsolve(A, ones(6), 4, :LR, GKL(; krylovdim = 10, tol = 1e-12))  # was a BoundsError, now 3 values
realeigsolve(A, ones(6), 4, :LM, Arnoldi(; krylovdim = 10, tol = 1e-12))  # idem

Changes:

  • Bug fixes: svdsolve (GKL) and realeigsolve limit howmany to the factorization size, as eigsolve and schursolve already did.

  • Warnings: Lanczos, BlockLanczos, Arnoldi, GolubYe and GKL emit the same invariant-subspace message, which says how many values are returned and that degenerate eigenvalues can be the cause:

    Invariant subspace of dimension 3 (up to requested tolerance tol = 1.0e-12), which is smaller than the number of requested eigenvalues (howmany = 4): returning 3 eigenvalues. The Krylov subspace of a single start vector contains only one eigenvector per distinct eigenvalue, so degenerate eigenvalues can be the cause.

    The final "stopped without convergence" warning is no longer emitted in this case, since all returned values are converged: it now compares converged with min(howmany, K) instead of howmany. BiArnoldi is left unchanged (it warns if either residual is small but only stops when both are).

  • Docstrings: eigsolve, realeigsolve, geneigsolve and svdsolve state that vals is shorter than howmany in this case.

  • Tests: new tests for svdsolve and realeigsolve on the example above; the three tests that expected two warnings (Lanczos, Arnoldi, BlockLanczos with howmany = n + 1) now expect a single one and check that n values are returned.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.24%. Comparing base (fdbbc11) to head (4be7c7b).

Files with missing lines Patch % Lines
src/eigsolve/golubye.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
+ Coverage   86.62%   87.24%   +0.61%     
==========================================
  Files          36       35       -1     
  Lines        3919     3848      -71     
==========================================
- Hits         3395     3357      -38     
+ Misses        524      491      -33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/eigsolve/arnoldi.jl Outdated
Comment thread src/KrylovKit.jl
return s
end

# warning for a Krylov subspace that becomes invariant at a dimension `K < howmany`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would also be okay with a more generic message with less logic, but that is just subjective:

Invariant subspace of dimension $K (up to requested tolerance `tol = $tol`), which is smaller than the number of requested values (`howmany = $howmany`): returning $K values.
The Krylov subspace does not capture degenerate vectors past its blocksize (`blocksize = $blocksize`).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.

2 participants