Skip to content

Report a NaN or an infinity in xBDSVDMR3 and xGESVDMR3 through a negative INFO - #1483

Merged
langou merged 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:bdsvdmr3-nan-info
Nov 15, 2026
Merged

langou merged 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:bdsvdmr3-nan-info

Conversation

@rmlarsen

@rmlarsen rmlarsen commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

AI disclosure: This PR was prepared with Claude Code.

Summary

xBDSVDMR3 and xGESVDMR3 (#1361) report a NaN or an infinity in their input as a positive INFO: N+1 in xBDSVDMR3 for D or E, passed on by xGESVDMR3 as MIN(M,N)+1 for A. When singular vectors are requested, xGESVDMR3 returns INFO = 0 with NS = 0 instead on three of its four paths, because the xORMBR calls after the bidiagonal SVD overwrite the INFO (#1482). This PR applies the rule that #1382 applies to xGEEV, xGESDD, xGELSD and xBDSDC, extending the NaN check that #1136 added to xGEEV: a NaN or an infinity in an input array is reported as INFO = -(position of the array), without calling XERBLA. It is the follow-up asked about in this comment on #1382.

routine input before after
xBDSVDMR3 NaN or infinity in D N+1 -5
xBDSVDMR3 NaN or infinity in E N+1 -6
xGESVDMR3 NaN or infinity in A, singular values only MIN(M,N)+1 -6
xGESVDMR3 NaN or infinity in A, with singular vectors 0 and NS = 0 on three of the four paths -6
CGESVDMR3, ZGESVDMR3 an entry with finite parts whose absolute value overflows 0, with NaN singular values -6
LAPACKE_?gesvdmr3 NaN in A (LAPACKE's own NaN check) -6 -7

Neither Fortran routine calls XERBLA for 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 scans D and then E in separate loops, so that the two can be told apart, and returns -5 or -6. INFO = N+2 (the xBDSDC fallback returned a non-finite result) and the fallback's own INFO stay positive: they report a failed computation, not bad input.
  • {s,d,c,z}gesvdmr3.f: right after ANRM = xLANGE( 'M', ... ), return -6 if ANRM is a NaN or exceeds xLAMCH( '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 to xGEEV, xGESDD and xGELSD. Without it, a NaN in A reaches the bidiagonal unscaled, and an infinity is scaled by zero into a NaN; xBDSVDMR3 then reports N+1. A finite A, scaled into [SMLNUM, BIGNUM], gives a finite 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 with finite real and imaginary parts whose absolute value overflows also gives -6; the largest singular value of A would overflow too. The INFO descriptions of CGESVDMR3 and ZGESVDMR3 say so.
  • {s,d,c,z}gesvdmr3.f: the INFO description drops a line, inherited from xGESVDX, about an INFO = N*2+1 that xGESVDMR3 never returns. It contradicted the description of the positive values above it, and for N = 1 it named the same value as MIN(M,N)+2.
  • lapacke_{s,d,c,z}gesvdmr3.c: the NaN check of A returned -6, but A is the seventh argument of LAPACKE_?gesvdmr3. With the Fortran change alone, a NaN would have come back as -6 and an infinity, which the NaN check does not catch, as -7 (the Fortran -6 after LAPACKE's shift for MATRIX_LAYOUT). The NaN check now returns -7 as well.

LAPACKE_?bdsvdmr3 needs no change: it already returns -6 / -7 for a NaN in D / E from its own NaN check, which is the new Fortran -5 / -6 after the shift.

Regression tests

  • xERRBD: xBDSVDMR3 with an infinity in D (-5) and a NaN in E (-6).
  • xERRED: xGESVDMR3 with a NaN and with an infinity in A (-6).

Each case also fails if XERBLA is 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 of xERRBD and xERRED grow to the minimum sizes for these 2-by-2 and 2-by-1 problems. xERRED joins the NAG -Onopropagate list in CMAKE/LAPACKTestHelpers.cmake, which keeps the compiler from folding the SQRT( -ONE ) and ONE / ZERO that build the NaN and the infinity.

#1382 also adds xERRED to that list (together with xERRLS), so whichever of the two is merged second needs a one-line rebase there. The statement labels and FORMAT numbers 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 no gesvdmr3 test on master. For all four precisions and both layouts, LAPACKE_?gesvdmr3 with singular vectors now returns -7 for a NaN in A, with the NaN check on and off, and for an infinity; master returned -6 for the NaN with the check on and 0 in the other cases. LAPACKE_dbdsvdmr3 returns -6 / -7 for a NaN or an infinity in D / E; master returned N+1 for an infinity. #1484 adds a gesvdmr3 test to the high-level tests. A NaN sweep of A can join it once both PRs are in, since the value it expects is the -7 from 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 _64 API: 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 in VL or VU passes the argument checks of both routines (VL.LT.ZERO and VU.LE.VL are false for a NaN), and the call returns NS = 0 with INFO = 0. xBDSVDX, xGESVDX, xSTEVX, xSYEVX and the other RANGE = 'V' routines use the same comparisons, so changing only the MR3 routines would make them diverge from the xBDSVDX interface they mirror; that is better handled across the family.

xGESVDMR3 loses a positive INFO from xBDSVDMR3 (a failed xBDSDC fallback, or N+2) when JOBU = 'V' or JOBVT = 'V', in three of its four paths: the xORMBR / xORMQR / xORMLQ calls after the bidiagonal SVD write INFO and reset it to zero. xGESVDX, which it was modelled on, does the same after xBDSVDX. That is filed as #1482, with a reproducer, and not changed here.

LAPACKE_?gesvdx, from which LAPACKE_?gesvdmr3 was copied, also returns -6 for a NaN in A, its seventh argument. It is released, so that is left for a separate change.

LAPACKE_?gesvdmr3 allocates less IWORK, and in complex less RWORK, than xGESVDMR3 needs, so every call with singular vectors writes past the end of a buffer. That is fixed in #1484.

Checklist

  • The documentation has been updated. (INFO descriptions of xBDSVDMR3 and xGESVDMR3.)
  • If the PR solves a specific issue, it is set to be closed on merge. (No tracking issue.)

@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.05970% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.21%. Comparing base (0c51225) to head (0c72b39).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
TESTING/EIG/cerred.f 88.23% 2 Missing ⚠️
TESTING/EIG/derrbd.f 88.88% 2 Missing ⚠️
TESTING/EIG/derred.f 88.23% 2 Missing ⚠️
TESTING/EIG/serrbd.f 88.88% 2 Missing ⚠️
TESTING/EIG/serred.f 88.23% 2 Missing ⚠️
TESTING/EIG/zerred.f 88.23% 2 Missing ⚠️
LAPACKE/src/lapacke_cgesvdmr3.c 0.00% 1 Missing ⚠️
LAPACKE/src/lapacke_dgesvdmr3.c 0.00% 1 Missing ⚠️
LAPACKE/src/lapacke_sgesvdmr3.c 0.00% 1 Missing ⚠️
LAPACKE/src/lapacke_zgesvdmr3.c 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           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            
Components Coverage Δ
BLAS 99.73% <ø> (ø)
CBLAS 97.10% <ø> (ø)
LAPACK 83.63% <100.00%> (+<0.01%) ⬆️
LAPACKE 2.17% <0.00%> (ø)
TMGLIB 55.69% <ø> (ø)
BLAS testing 88.77% <ø> (ø)
CBLAS testing 89.65% <ø> (ø)
LAPACK testing 82.39% <88.46%> (+<0.01%) ⬆️
LAPACKE testing ∅ <ø> (∅)
Files with missing lines Coverage Δ
SRC/cgesvdmr3.f 95.39% <100.00%> (+0.05%) ⬆️
SRC/dbdsvdmr3.f 75.53% <100.00%> (+2.26%) ⬆️
SRC/dgesvdmr3.f 95.25% <100.00%> (+0.06%) ⬆️
SRC/sbdsvdmr3.f 75.53% <100.00%> (+2.26%) ⬆️
SRC/sgesvdmr3.f 95.25% <100.00%> (+0.06%) ⬆️
SRC/zgesvdmr3.f 95.39% <100.00%> (+0.05%) ⬆️
LAPACKE/src/lapacke_cgesvdmr3.c 0.00% <0.00%> (ø)
LAPACKE/src/lapacke_dgesvdmr3.c 0.00% <0.00%> (ø)
LAPACKE/src/lapacke_sgesvdmr3.c 0.00% <0.00%> (ø)
LAPACKE/src/lapacke_zgesvdmr3.c 0.00% <0.00%> (ø)
... and 6 more

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c51225...0c72b39. Read the comment docs.

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>
…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>
@langou
langou merged commit 254a4c2 into Reference-LAPACK:master Nov 15, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants