Repository navigation
Report a NaN or an infinity in xBDSVDMR3 and xGESVDMR3 through a negative INFO - #1483
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1483 +/- ##
========================================
Coverage 70.20% 70.21%
========================================
Files 6237 6237
Lines 500437 500555 +118
Branches 23536 23536
========================================
+ Hits 351336 351450 +114
- Misses 148639 148643 +4
Partials 462 462
Continue to review full report in Codecov by Harness.
|
2 tasks done
rmlarsen
force-pushed
the
bdsvdmr3-nan-info
branch
from
November 9, 2026 02:28
ccb9f39 to
f128414
Compare
rmlarsen
added a commit
to rmlarsen/lapack
that referenced
this pull request
Nov 9, 2026
CGEEV, ZGEEV, CGESDD, ZGESDD, CGELSD and ZGELSD test the xLANGE 'M' norm of A for a NaN or a value above the overflow threshold. For a complex A, xLANGE takes the absolute value of each entry, so an entry whose real and imaginary parts are finite but whose absolute value overflows also returns INFO = -4. Master returns INFO = 0 for such a matrix, with NaN eigenvalues or singular values, because the scaling by BIGNUM / ANRM is a scaling by zero. The INFO descriptions now say so, as Reference-LAPACK#1483 does for CGESVDMR3 and ZGESVDMR3. Comments only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 tasks done
…tive INFO xBDSVDMR3 rejects a NaN or an infinity in D or E before any work and returns INFO = N+1 without calling XERBLA. xGESVDMR3 passes that on as INFO = MIN(M,N)+1 when A contains one, since a NaN reaches the bidiagonal unscaled and an infinity is scaled by zero into a NaN; when singular vectors are requested, the xORMBR calls that follow overwrite it on three of the four paths (Reference-LAPACK#1482), and the call returns INFO = 0 with NS = 0. Follow instead the rule that Reference-LAPACK#1382 applies to xGEEV, xGESDD, xGELSD and xBDSDC, extending the NaN check that Reference-LAPACK#1136 added to xGEEV: when the input contains a NaN or an infinity, return INFO = -(position of the array), without calling XERBLA, so that the caller gets control back. xBDSVDMR3 now tests D and then E, in separate loops so that the two can be told apart, and returns -5 or -6. xGESVDMR3 tests ANRM right after xLANGE, before the scaling, and returns -6, with the test that bidiagonal, so xBDSVDMR3's test no longer fires from xGESVDMR3. For a complex A, xLANGE takes the absolute value of each entry, so an entry whose real and imaginary parts are finite but whose absolute value overflows also returns -6: the largest singular value of A would overflow too, and the parent returned INFO = 0 with NaN singular values. INFO = N+2 and the fallback's INFO stay positive: they report a failed computation, not bad input. The INFO descriptions of both routines document the change, and the one of xGESVDMR3 drops a line, inherited from xGESVDX, about an INFO = N*2+1 that xGESVDMR3 never returns. LAPACKE_?bdsvdmr3 already returns -6 / -7 for a NaN in D / E from its own NaN check, which is the new Fortran -5 / -6 after LAPACKE's shift for MATRIX_LAYOUT. The NaN check of LAPACKE_?gesvdmr3 returned -6 for A, which is its seventh argument, so a NaN would have come back as -6 and an infinity as -7; it now returns -7. LAPACKE_?gesvdx, from which it was copied, has the same -6, but it is released and is left alone. Neither routine is in a release yet, so no released interface changes. xERRBD checks xBDSVDMR3 with an infinity in D (-5) and a NaN in E (-6), and xERRED checks xGESVDMR3 with a NaN and with an infinity in A (-6), each also failing if XERBLA is called. On the parent, the xBDSVDMR3 cases return 3 (N+1) and the xGESVDMR3 cases 2 (MIN(M,N)+1). Both routines check their workspace before the input, so the work arrays of xERRBD and xERRED grow to the minimum sizes for these small problems, and xERRED joins the NAG -Onopropagate list that keeps the compiler from folding SQRT( -ONE ) and ONE / ZERO. The full test suite passes, with and without the _64 API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rmlarsen
force-pushed
the
bdsvdmr3-nan-info
branch
from
November 14, 2026 22:07
f128414 to
0c72b39
Compare
langou
approved these changes
Nov 15, 2026
langou
approved these changes
Nov 15, 2026
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.
AI disclosure: This PR was prepared with Claude Code.
Summary
xBDSVDMR3andxGESVDMR3(#1361) report a NaN or an infinity in their input as a positiveINFO:N+1inxBDSVDMR3forDorE, passed on byxGESVDMR3asMIN(M,N)+1forA. When singular vectors are requested,xGESVDMR3returnsINFO = 0withNS = 0instead on three of its four paths, because thexORMBRcalls after the bidiagonal SVD overwrite theINFO(#1482). This PR applies the rule that #1382 applies toxGEEV,xGESDD,xGELSDandxBDSDC, extending the NaN check that #1136 added toxGEEV: a NaN or an infinity in an input array is reported asINFO = -(position of the array), without callingXERBLA. It is the follow-up asked about in this comment on #1382.xBDSVDMR3DN+1-5xBDSVDMR3EN+1-6xGESVDMR3A, singular values onlyMIN(M,N)+1-6xGESVDMR3A, with singular vectors0andNS = 0on three of the four paths-6CGESVDMR3,ZGESVDMR30, with NaN singular values-6LAPACKE_?gesvdmr3A(LAPACKE's own NaN check)-6-7Neither Fortran routine calls
XERBLAfor these returns, before or after: the caller gets control back. Nothing changes for finite input. None of these routines has been released yet, so no released interface changes.Fix
{s,d}bdsvdmr3.f: the existing finiteness check now scansDand thenEin separate loops, so that the two can be told apart, and returns-5or-6.INFO = N+2(thexBDSDCfallback returned a non-finite result) and the fallback's ownINFOstay positive: they report a failed computation, not bad input.{s,d,c,z}gesvdmr3.f: right afterANRM = xLANGE( 'M', ... ), return-6ifANRMis a NaN or exceedsxLAMCH( 'Overflow' ), the test that Report a NaN or an infinity in the input of xGELSD, xGESDD, xGEEV, xLALSD and xBDSDC through INFO instead of stopping in XERBLA #1382 adds toxGEEV,xGESDDandxGELSD. Without it, a NaN inAreaches the bidiagonal unscaled, and an infinity is scaled by zero into a NaN;xBDSVDMR3then reportsN+1. A finiteA, scaled into[SMLNUM, BIGNUM], gives a finite bidiagonal, soxBDSVDMR3's test no longer fires fromxGESVDMR3. For a complexA,xLANGEtakes the absolute value of each entry, so an entry with finite real and imaginary parts whose absolute value overflows also gives-6; the largest singular value ofAwould overflow too. TheINFOdescriptions ofCGESVDMR3andZGESVDMR3say so.{s,d,c,z}gesvdmr3.f: theINFOdescription drops a line, inherited fromxGESVDX, about anINFO = N*2+1thatxGESVDMR3never returns. It contradicted the description of the positive values above it, and forN = 1it named the same value asMIN(M,N)+2.lapacke_{s,d,c,z}gesvdmr3.c: the NaN check ofAreturned-6, butAis the seventh argument ofLAPACKE_?gesvdmr3. With the Fortran change alone, a NaN would have come back as-6and an infinity, which the NaN check does not catch, as-7(the Fortran-6after LAPACKE's shift forMATRIX_LAYOUT). The NaN check now returns-7as well.LAPACKE_?bdsvdmr3needs no change: it already returns-6/-7for a NaN inD/Efrom its own NaN check, which is the new Fortran-5/-6after the shift.Regression tests
xERRBD:xBDSVDMR3with an infinity inD(-5) and a NaN inE(-6).xERRED:xGESVDMR3with a NaN and with an infinity inA(-6).Each case also fails if
XERBLAis called. With the routines of master every case fails in all precisions (*** DBDSVDMR3 did not return INFO = -5 without calling XERBLA for input with a NaN or an infinity (INFO = 3) ***,*** ZGESVDMR3 did not return INFO = -6 without calling XERBLA for a matrix with a NaN or an infinity (INFO = 2) ***). Both routines check their workspace before the input, so the work arrays ofxERRBDandxERREDgrow to the minimum sizes for these 2-by-2 and 2-by-1 problems.xERREDjoins the NAG-Onopropagatelist inCMAKE/LAPACKTestHelpers.cmake, which keeps the compiler from folding theSQRT( -ONE )andONE / ZEROthat build the NaN and the infinity.#1382 also adds
xERREDto that list (together withxERRLS), so whichever of the two is merged second needs a one-line rebase there. The statement labels andFORMATnumbers of the new tests differ from those of #1382, so the test files themselves merge without conflict.The LAPACKE side was checked with a standalone program, because the LAPACKE high-level tests (
LAPACKE/testing/high_level) have nogesvdmr3test on master. For all four precisions and both layouts,LAPACKE_?gesvdmr3with singular vectors now returns-7for a NaN inA, with the NaN check on and off, and for an infinity; master returned-6for the NaN with the check on and0in the other cases.LAPACKE_dbdsvdmr3returns-6/-7for a NaN or an infinity inD/E; master returnedN+1for an infinity. #1484 adds agesvdmr3test to the high-level tests. A NaN sweep ofAcan join it once both PRs are in, since the value it expects is the-7from this PR.Test suite
The full test suite passes on this branch, configured as in CI (
CBLAS=ON,LAPACKE=ON,LAPACKE_WITH_TMG=ON) with the_64API: all 313 CTest entries, with 5739011 LAPACK tests, 11973112 LAPACKE tests, 319677 BLAS tests and 645492 CBLAS tests for each API, 0 numerical errors and 0 other errors (13th Gen Intel(R) Core(TM) i7-13700HX, Linux under WSL2, GNU Fortran and GCC 15.2.0,CMAKE_BUILD_TYPE=Release).Not changed here
With
RANGE = 'V', a NaN inVLorVUpasses the argument checks of both routines (VL.LT.ZEROandVU.LE.VLare false for a NaN), and the call returnsNS = 0withINFO = 0.xBDSVDX,xGESVDX,xSTEVX,xSYEVXand the otherRANGE = 'V'routines use the same comparisons, so changing only theMR3routines would make them diverge from thexBDSVDXinterface they mirror; that is better handled across the family.xGESVDMR3loses a positiveINFOfromxBDSVDMR3(a failedxBDSDCfallback, orN+2) whenJOBU = 'V'orJOBVT = 'V', in three of its four paths: thexORMBR/xORMQR/xORMLQcalls after the bidiagonal SVD writeINFOand reset it to zero.xGESVDX, which it was modelled on, does the same afterxBDSVDX. That is filed as #1482, with a reproducer, and not changed here.LAPACKE_?gesvdx, from whichLAPACKE_?gesvdmr3was copied, also returns-6for a NaN inA, its seventh argument. It is released, so that is left for a separate change.LAPACKE_?gesvdmr3allocates lessIWORK, and in complex lessRWORK, thanxGESVDMR3needs, so every call with singular vectors writes past the end of a buffer. That is fixed in #1484.Checklist
INFOdescriptions ofxBDSVDMR3andxGESVDMR3.)