Repository navigation
Keep gramcover accurate when squares leave range - #87
Merged
Merged
Conversation
`gramcover(A)` and `gramcover(A, w)` sum `abs(w[i]) * A[i,j]^2` per column and take one square root. An entry below about 1e-162 squares to zero and one above about 1e154 squares to `Inf`, so a column whose 2-norm is an ordinary number could get a scale of 0 or `Inf`: `gramcover([1e-170 1.0])` returned `[0.0, 1.0]`, which does not cover `A'*A`. The plain sum of squares is kept as the first pass. A column whose sum is below `floatmin`, infinite, or `NaN` is accumulated again as a running `hypot` over its terms `sqrt(abs(w[i])) * abs(A[i,j])`. The scale is then accurate to the documented `O(n_j * eps)` whenever the largest term in the column is at least `floatmin`, and is `Inf` only when the norm exceeds `floatmax`. The existing inflation factor bounds the rounding of both forms. The weight now enters each term as `sqrt(abs(w[i]))` before squaring, so weighted results change in the last bits. Entries are converted to floating point before squaring, which keeps the squares of large integer entries from wrapping. When no column needs the second pass the time is unchanged: 1.43 ms for a dense 2000x500 matrix and 0.14 ms for a sparse matrix with 100000 nonzeros. When every column needs it, the sparse case takes 1.3 ms. Using `hypot` for every entry instead takes 13.6 ms and 1.1 ms. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
=======================================
Coverage 98.79% 98.79%
=======================================
Files 23 23
Lines 6286 6302 +16
=======================================
+ Hits 6210 6226 +16
Misses 76 76 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
gramcover(A)andgramcover(A, w)sumabs(w[i]) * A[i,j]^2per column and take one square root. An entry below about 1e-162 squares to zero and one above about 1e154 squares toInf, so a column whose 2-norm is an ordinary number could get a scale of 0 orInf:gramcover([1e-170 1.0])returned[0.0, 1.0], which does not coverA'*A.The plain sum of squares is kept as the first pass. A column whose sum is below
floatmin, infinite, orNaNis accumulated again as a runninghypotover its termssqrt(abs(w[i])) * abs(A[i,j]). The scale is then accurate to the documentedO(n_j * eps)whenever the largest term in the column is at leastfloatmin, and isInfonly when the norm exceedsfloatmax. The existing inflation factor bounds the rounding of both forms.The weight now enters each term as
sqrt(abs(w[i]))before squaring, so weighted results change in the last bits. Entries are converted to floating point before squaring, which keeps the squares of large integer entries from wrapping.When no column needs the second pass the time is unchanged: 1.43 ms for a dense 2000x500 matrix and 0.14 ms for a sparse matrix with 100000 nonzeros. When every column needs it, the sparse case takes 1.3 ms. Using
hypotfor every entry instead takes 13.6 ms and 1.1 ms.Assisted-by: Claude Opus 5.5 noreply@anthropic.com