Repository navigation
LSMR: return x = 0 instead of NaN when Aᴴb = 0 - #169
Merged
Merged
Conversation
The early return compared ‖Aᴴb‖ = α * β with the tolerance only after normalising by β and α, so b = 0 or Aᴴb = 0 divided by zero and returned NaN. Check before normalising; x = 0 then solves the (damped) least-squares problem exactly.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #169 +/- ##
==========================================
- Coverage 88.42% 86.65% -1.77%
==========================================
Files 36 36
Lines 3964 3918 -46
==========================================
- Hits 3505 3395 -110
- Misses 459 523 +64 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Jutho
reviewed
Sep 24, 2026
Co-authored-by: Jutho <Jutho@users.noreply.github.com>
Owner
|
Thanks, test failures seem unrelated, but will require me to take a look into this before tagging a new version. |
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.
lssolvewith LSMR returnsNaNs whenb = 0, or more generally whenAᴴb = 0:The exact solution is
x = 0in both cases, also with dampingλ, since the gradient-Aᴴbof the objective vanishes there. The initialisation dividesubyβ = ‖b‖andvbyαbefore the early-return check onζ̄ = α * β = ‖Aᴴb‖, so that check seesNaNand never fires.This PR moves the early return before the normalisation, computing
‖Aᴴb‖directly. It also treats an exactly vanishing‖Aᴴb‖as converged, so the case is handled withtol = 0too. The main loop is unchanged.I hit this through ImplicitDifferentiation.jl, whose
IterativeLeastSquaresSolvercallslssolveon tangents and cotangents, so any zero tangent producedNaNderivatives.The new testset covers
b = 0andb ≠ 0withAᴴb = 0, with and without damping andtol ∈ (0, 1e-8), over the existing wrap modes. It fails 182 of 200 checks onmasterand passes with this change. The existing lssolve and issue tests still pass locally (Julia 1.13).