Conversation
mindaugl
approved these changes
Sep 29, 2026
This branch has not been deployed
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.
Describe your change
Power iteration can stop after its first iteration when the Rayleigh quotient is negative. The relative-error denominator currently uses the signed quotient, so a negative estimate produces a negative error that immediately satisfies the positive tolerance.
For example,
power_iteration(np.diag([-4.0, 2.0]), np.ones(2))returns an eigenvalue of-2.8with a residual norm of2.4. Dividing by the magnitude of the quotient keeps the relative error nonnegative and allows convergence to the dominant eigenvalue,-4.Reproduction and verification:
Validation:
test_power_iteration().numpy.linalg.eigvalshand eigenvector residuals.ruff checkandruff format --checkpass for the changed file.pre-commit run --all-filescheck passes.Upstream CI: Ruff, type checking, documentation build, and pre-commit checks passed. The test run reports 3,428 passed and one failure in the untouched
web_programming/crypto_price_tracker.pydoctest: CoinGecko's live API returned HTTP 403. The power-iteration tests passed in that run.Checklist