Skip to content

Return INFO = -5 or -6 from xGEES, xGEESX and xGEEVX for a NaN or an infinity in A - #1499

Open
rmlarsen wants to merge 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:gees-geevx-nonfinite-input
Open

rmlarsen wants to merge 1 commit into
Reference-LAPACK:masterfrom
rmlarsen:gees-geevx-nonfinite-input

Conversation

@rmlarsen

Copy link
Copy Markdown
Contributor

AI disclosure: This PR was prepared with Claude Code.

Summary

This extends #1382, which made xGEEV return INFO = -4 without calling XERBLA for a NaN or an infinity in A, to the three sibling drivers xGEES, xGEESX and xGEEVX. They have no such test, and misbehave on non-finite input in two ways. Found by reading the sibling of #1382.

With one infinity at A(2,3) of a 6-by-6 matrix, DGEES, DGEESX and DGEEVX (every BALANC) return INFO = 0 and NaN eigenvalues. With a NaN at the same place, DGEEVX with BALANC = 'S' or 'B' stops the program: ** On entry to DGEBAL parameter number 3 had an illegal value. With BALANC = 'N' or 'P', and in DGEES and DGEESX, which balance with 'P', a NaN comes back as INFO = 6 (the QR algorithm "did not converge").

Description

An infinity in A makes ANRM = xLANGE( 'M', ... ) infinite. That exceeds BIGNUM, so the driver scales A by CSCALE / ANRM = 0: the infinity becomes 0 * Inf, a NaN, and every other entry becomes zero. A NaN in A is not tested either. xGEBAL with 'S' or 'B' detects it and calls XERBLA, and the reference XERBLA stops the process. The other balancing options hand the NaN to xHSEQR, which reports a non-convergence.

Fix

In {s,d,c,z}gees.f, {s,d,c,z}geesx.f and {s,d,c,z}geevx.f, right after ANRM = xLANGE( 'M', ... ) and before the scaling branches, return without calling XERBLA if ANRM is a NaN or exceeds xLAMCH( 'Overflow' ), in the same form as xGEEV. INFO is minus the position of A in the argument list:

routine INFO
xGEES -5
xGEESX -6
xGEEVX -6

As in xGEEV, a NaN is reported the same way as an infinity. The INFO descriptions document this, and for the complex routines, where xLANGE takes the absolute value of each entry, they add that an entry whose absolute value overflows is reported too, as CGEEV and ZGEEV do. Twelve source files. Nothing changes for finite input.

Behavior change: a caller that today gets INFO > 0 from one of these drivers for a NaN, or INFO = 0 with NaN eigenvalues for an infinity, now gets a negative INFO.

Reproducer

program repro
  implicit none
  integer, parameter :: n = 6
  double precision :: a(n, n), wr(n), wi(n), v(n, n), w(1000), s(n), abnrm, r1(n), r2(n), rce, rcv
  double precision, volatile :: z
  integer :: iwork(100), ilo, ihi, info, sdim
  logical :: bwork(n)
  logical, external :: sel
  z = 0
  call fill(a); a(2, 3) = 1 / z
  call dgees('N', 'N', sel, n, a, n, sdim, wr, wi, v, n, w, 1000, bwork, info)
  print '(a,i0,a,f5.1)', 'DGEES  , Inf: INFO = ', info, ', WR(1) = ', wr(1)
  call fill(a); a(2, 3) = 1 / z
  call dgeesx('N', 'N', sel, 'N', n, a, n, sdim, wr, wi, v, n, rce, rcv, w, 1000, iwork, 100, bwork, info)
  print '(a,i0,a,f5.1)', 'DGEESX , Inf: INFO = ', info, ', WR(1) = ', wr(1)
  call fill(a); a(2, 3) = 1 / z
  call dgeevx('B', 'N', 'N', 'N', n, a, n, wr, wi, v, n, v, n, ilo, ihi, s, abnrm, r1, r2, w, 1000, iwork, info)
  print '(a,i0,a,f5.1)', 'DGEEVX , Inf: INFO = ', info, ', WR(1) = ', wr(1)
  call fill(a); a(2, 3) = z / z
  call dgeevx('S', 'N', 'N', 'N', n, a, n, wr, wi, v, n, v, n, ilo, ihi, s, abnrm, r1, r2, w, 1000, iwork, info)
  print '(a,i0)', 'DGEEVX , NaN: INFO = ', info
contains
  subroutine fill(a)
    double precision :: a(n, n)
    integer :: i, j
    do j = 1, n
      do i = 1, n
        a(i, j) = 1 + mod(3*i + 5*j, 7) / 7d0
      end do
    end do
  end subroutine
end program
logical function sel(a, b)
  double precision :: a, b
  sel = a > 0
end function

Master:

DGEES  , Inf: INFO = 0, WR(1) =   NaN
DGEESX , Inf: INFO = 0, WR(1) =   NaN
DGEEVX , Inf: INFO = 0, WR(1) =   NaN
 ** On entry to DGEBAL parameter number  3 had an illegal value

With this change:

DGEES  , Inf: INFO = -5, WR(1) =   0.0
DGEESX , Inf: INFO = -6, WR(1) =   0.0
DGEEVX , Inf: INFO = -6, WR(1) =   0.0
DGEEVX , NaN: INFO = -6

(WR is not set on the new path, so its printed value is whatever the array held.) With a NaN in place of the infinity, master returns INFO = 6 from DGEES and DGEESX.

Regression test

xERRED follows the xGEEV case of #1382. For each of xGEES, xGEESX and xGEEVX, in all four precisions, it puts a NaN and then an infinity at A(2,1) of a 2-by-2 matrix, and for xGEEVX repeats that with BALANC = 'N', 'P', 'S' and 'B'. A case fails if INFO is not the value above or if XERBLA is called (the test XERBLA records the call instead of stopping). Twelve cases per precision.

With only the test changes on top of master, in every precision every xGEES (2 of 2), xGEESX (2 of 2) and xGEEVX (8 of 8) case fails (*** DGEEVX did not return INFO = -6 without calling XERBLA for a matrix with a NaN or an infinity (INFO = 0) ***, and INFO = 2 for some complex cases), and the xGEEVX NaN cases with BALANC = 'S' and 'B' also log the xGEBAL XERBLA call. With the fix all pass: xGEES 8 tests done, xGEESX 9, xGEEVX 19 (18 in the complex precisions).

Test suite

The full test suite passes, configured as in CI (CBLAS=ON, LAPACKE=ON, LAPACKE_WITH_TMG=ON) with the _64 API. All 333 CTest entries pass, with 5755188 LAPACK tests (5755190 for the _64 API), 11973112 LAPACKE tests, 319677 BLAS tests and 645492 CBLAS tests for each API, and 0 numerical errors and 0 other errors. These are the counts of master; the error-exit tests are not counted. A second build with CI's gfortran flags (-O2 -Wall -Wno-unused-dummy-argument -Wno-unused-variable -Wno-unused-label -Werror=conversion -fimplicit-none -frecursive -fcheck=all) passes the suite as well, and the changed files compile with the same warnings as on master. The builds used GNU Fortran and GCC 15.2.0 with CMAKE_BUILD_TYPE=Release on x86-64 Linux.

Not changed here

  • The generalized drivers xGGES, xGGEV and their variants scale by the norms of A and B in the same way and have no such test either. They are not changed here.

Checklist

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

…infinity in A

This extends the change to xGEEV in Reference-LAPACK#1382 to its three sibling
drivers.  xGEEV returns INFO = -4 without calling XERBLA when xLANGE of
A is a NaN or exceeds xLAMCH( 'Overflow' ).  xGEES, xGEESX and xGEEVX
test neither, with two consequences.

An infinity in A makes ANRM infinite, which exceeds BIGNUM, so the
driver scales A by CSCALE / ANRM = 0.  The infinity becomes 0 * Inf, a
NaN, and every other entry becomes zero.  DGEES, DGEESX and DGEEVX with
every BALANC return INFO = 0 and all-NaN eigenvalues for a 6-by-6 matrix
with one infinity at A(2,3).

A NaN in A is not caught either.  xGEEVX with BALANC = 'S' or 'B' calls
xGEBAL, which detects the NaN, calls XERBLA ("On entry to DGEBAL
parameter number 3 had an illegal value"), and the reference XERBLA
stops the program.  With BALANC = 'N' or 'P', and in xGEES and xGEESX,
which balance with 'P', the NaN comes back as INFO > 0 from xHSEQR.

Test ANRM right after xLANGE, before the scaling branches, in the same
form as xGEEV, and return INFO = -5 for xGEES, -6 for xGEESX and -6 for
xGEEVX, the position of A in each argument list, without calling
XERBLA.  A NaN is reported like an infinity, as in xGEEV.  The INFO
descriptions say so.  For the complex routines xLANGE takes the absolute
value of each entry, so an entry with finite real and imaginary parts
whose absolute value overflows is reported the same way, as in CGEEV and
ZGEEV; the descriptions say that too.

Callers that today get INFO > 0 from xGEES, xGEESX or xGEEVX with
BALANC = 'N' or 'P' for a NaN, or INFO = 0 and NaN eigenvalues for an
infinity, now get a negative INFO.  Nothing changes for finite input.

Test: xERRED calls each of the three drivers in all four precisions with
a NaN and with an infinity at A(2,1) of a 2-by-2 matrix, and xGEEVX with
each of BALANC = 'N', 'P', 'S' and 'B', and fails if INFO is not the
expected negative value or if XERBLA is called.  On the parent every
case fails.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.42857% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.64%. Comparing base (ef55c9b) to head (e3d603b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
TESTING/EIG/cerred.f 90.16% 6 Missing ⚠️
TESTING/EIG/derred.f 90.16% 6 Missing ⚠️
TESTING/EIG/serred.f 90.16% 6 Missing ⚠️
TESTING/EIG/zerred.f 90.16% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1499      +/-   ##
==========================================
+ Coverage   70.63%   70.64%   +0.01%     
==========================================
  Files        6243     6243              
  Lines      501290   501570     +280     
  Branches    23516    23516              
==========================================
+ Hits       354100   354353     +253     
- Misses     146327   146353      +26     
- Partials      863      864       +1     
Components Coverage Δ
BLAS 99.71% <ø> (-0.03%) ⬇️
CBLAS 96.95% <ø> (ø)
LAPACK 83.73% <100.00%> (+<0.01%) ⬆️
LAPACKE 4.18% <ø> (ø)
TMGLIB 55.69% <ø> (ø)
BLAS testing 88.79% <ø> (ø)
CBLAS testing 89.65% <ø> (ø)
LAPACK testing 82.41% <90.16%> (+0.01%) ⬆️
LAPACKE testing ∅ <ø> (∅)
Files with missing lines Coverage Δ
SRC/cgees.f 97.59% <100.00%> (+0.09%) ⬆️
SRC/cgeesx.f 91.26% <100.00%> (+0.26%) ⬆️
SRC/cgeevx.f 96.25% <100.00%> (+0.07%) ⬆️
SRC/dgees.f 86.20% <100.00%> (+0.29%) ⬆️
SRC/dgeesx.f 84.00% <100.00%> (+0.27%) ⬆️
SRC/dgeevx.f 95.90% <100.00%> (+0.07%) ⬆️
SRC/sgees.f 86.20% <100.00%> (+0.29%) ⬆️
SRC/sgeesx.f 84.00% <100.00%> (+0.27%) ⬆️
SRC/sgeevx.f 95.90% <100.00%> (+0.07%) ⬆️
SRC/zgees.f 97.59% <100.00%> (+0.09%) ⬆️
... and 6 more

... and 1 file with indirect coverage changes


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 ef55c9b...e3d603b. Read the comment docs.

This branch has not been deployed

No deployments
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.

1 participant