Implement the 2-norm in opnorm for sparse matrices - #859
Open
ViralBShah wants to merge 1 commit into
Open
ViralBShah wants to merge 1 commit into
ViralBShah wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #859 +/- ##
==========================================
+ Coverage 92.89% 92.91% +0.01%
==========================================
Files 12 12
Lines 8982 9002 +20
==========================================
+ Hits 8344 8364 +20
Misses 638 638 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
@dkarrasch Would be great for your review on this - I don't want to merge this one without review. |
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.
Fixes #119.
opnormdefaults top = 2, which threw for every sparse matrix that is not a single row or column:It now returns the largest singular value from Golub-Kahan-Lanczos bidiagonalization (internal helper
opnorm2est), which needs onlyA*vandA'*u, so each step is O(nnz) and the only storage is two vectors plus the bidiagonal. The iteration stops when the residual of the leading Ritz pair, read off the SVD of the smallBidiagonal, falls belowsqrt(eps())relative to it; the error in the value is of the order of the squared residual. The result is therefore an estimate that converges from below, unlike the denseopnorm. Ifmax(100, 2*min(m, n))steps pass without convergence the current estimate is returned. The start vector comes from a fixed-seedXoshiro, so repeated calls agree exactly; a fixed vector such asonesdoes not work, because it lies in the null space of every graph Laplacian and gives 0 for[1 -1; -1 1]. The small SVD is O(k^2), so it runs at every step up to 32 and every 8th step after that, or when the recurrence is about to break down. The return type follows the dense method. No new keywords, methods or dependencies.Against
opnorm(Array(A))on nightly the relative error was 1e-15 to 1e-16 for real and complexFloat32/Float64,Int,BoolandRationaleltypes, both rectangular orientations, low-rank matrices, repeated and clustered singular values (1and1 + 1e-6), all stored zeros, and entries scaled by 1e±200. A 90000×90000 2-D Laplacian takes about 1.6 s and matches the analytic value to 2e-14.test/linalg.jlpasses on nightly; the old@test_throwsforp = 2is removed.Left out:
opnormof adjoints, transposes and views of sparse matrices still reaches LinearAlgebra's generic method (elementwise forp = 1, Inf, aMethodErrorfromsvdvals!forp = 2); that is a follow-up touching dispatch. This PR wants a sentence indocs/src/index.mdsaying the sparse 2-norm is an iterative estimate; not backportable, since it is new behaviour.Written by Claude Code (Claude Fable 5.1).
🤖 Generated with Claude Code