GeezerVison is showing github.com — Fix the xLAEIN growth test for real eigenvalues and in CLAEIN/ZLAEIN by rmlarsen · Pull Request #1520 · Reference-LAPACK/lapack
Conversation
rmlarsen
commented
Nov 22, 2026
•
edited by langou
Loading
Uh oh!
There was an error while loading. Please reload this page.
AI disclosure: This PR was prepared with Claude Code.
Summary
Since #1400 the acceptance test of xLAEIN uses a threshold GROWTO = TENTH / ( N*EPS3 ), which overflows to +Inf when the matrix norm is small. xHSEIN passes EPS3 = HNORM*ULP, so N*EPS3 falls below about 0.1/HUGE for a Hessenberg matrix of norm below about 0.1/(HUGE*N*ULP) (about 6e-295 for N = 4 in double precision). No vector can then be accepted, every eigenvector is reported as not converged and xHSEIN returns INFO equal to the number of failures, although the matrix is well conditioned and all its entries are normal. A well-conditioned 4-by-4 matrix of norm of order 10, scaled by 2**-1020 (entries of order 1e-307) with accurate eigenvalues supplied, gives INFO = 4 from DHSEIN; ZHSEIN fails from a scale of 2**-990. In single precision the same happens from a scale of 2**-120 (SHSEIN, norm about 7.5e-36), a range that is much more likely to matter. Before #1400 these matrices worked, down to norms of about 1e-303 in double precision.
This PR fixes the test for CLAEIN, ZLAEIN and for real eigenvalues in SLAEIN and DLAEIN. The complex-conjugate-pair path of SLAEIN and DLAEIN is not changed (see Not changed here).
Description
#1400 made the test apply to the growth V1NORM/(SCALE*V0NORM) of the solve rather than to V1NORM alone, with GROWTO = TENTH / ( N*EPS3 ) replacing TENTH / ROOTN. The test itself is right. The threshold is formed as a reciprocal, though. Once HNORM is below about 0.1/(HUGE*N*ULP), GROWTO is +Inf, GROWTO*SCALE*V0NORM is Inf or NaN, and V1NORM.GE. that is never true.
Fix
For CLAEIN, ZLAEIN and the real-eigenvalue path of SLAEIN and DLAEIN, the test is now V0NORM.GT.ZERO .AND. V1NORM.GE.( TENTH*SCALE )*( V0NORM / ( N*EPS3 ) ). V0NORM is the 1-norm of a vector that has been scaled to 2-norm EPS3*SQRT(N), or built from EPS3 and EPS3*ROOTN for a restart, so V0NORM / ( N*EPS3 ) is of order one and nothing overflows. The test is still applied to the growth, as in #1400.
The V0NORM.GT.ZERO condition keeps a starting vector that has underflowed to zero (an initial vector of magnitude 1e-37 in single precision, say, scaled to norm EPS3*SQRT(N) with EPS3 of order 1e-40) from being accepted: with V0NORM = 0 the right-hand side is zero and 0 >= 0 holds. I did not require SCALE.GT.ZERO. In these paths zero pivots are replaced by EPS3, so SCALE = 0 with a nonzero starting vector can only come from the rescaling in xLATRS underflowing after very large growth, which is exactly a vector to accept. In my samples a SCALE.GT.ZERO requirement rejected valid vectors (717 of 6000 in double precision, 387 in single precision), all of them in the complex-pair path of SLAEIN and DLAEIN, which this PR does not change: requiring it in the pair path only gave the same counts, and requiring it in the real-eigenvalue path only changed nothing.
One behavior changes at ordinary norms, through V0NORM.GT.ZERO. With INITV = 'U' and a zero column supplied as starting vector (a real eigenvalue, or any eigenvalue in CLAEIN/ZLAEIN), master accepts the zero vector (0 >= 0) and returns an all-NaN vector with INFO = 0. Now the routine restarts from its own vector and returns a proper eigenvector. For DHSEIN('R','Q','U') on H = [4 1 0; 1 3 1; 0 1 1] with VR = 0, master returns NaN with INFO = 0 and this change returns a finite vector of unit max-norm. The complex-pair path of SLAEIN and DLAEIN still returns NaN for a zero starting vector, as before.
In the complex-pair path of SLAEIN and DLAEIN the test is left exactly as on master, and GROWTO is now formed only there; a comment says why the two paths differ.
The rearranged product could round differently from the old one. I compared the vectors, INFO and IFAIL returned by xHSEIN of this branch with those of master on 6000 random Hessenberg matrices per precision (random, Jordan-like, clustered eigenvalues, split matrices, perturbed eigenvalues, with and without initial vectors, scaled by 2**-200 to 2**200 in double and by 2**-60 to 2**60 in single precision). The outputs are bit-for-bit identical in all four precisions.
Reproducer
Found by scaling a well-conditioned system by powers of two.
program repro
implicit none
integer, parameter :: n = 4
double precision :: h0(n,n), h(n,n), wr(n), wi(n), wr0(n), wi0(n)
double precision :: z(n,n), vl(n,n), vr(n,n), work(1000), sc
integer :: info, m, ifl(n), ifr(n), e
logical :: sel(n)
h0 = reshape((/ 4d0,1d0,0d0,0d0, 1d0,3d0,1d0,0d0, &
2d0,1d0,2d0,1d0, 1d0,2d0,1d0,1d0 /), (/ n, n /))
h = h0
call dhseqr('E', 'N', n, 1, n, h, n, wr0, wi0, z, n, work, 1000, info)
do e = -900, -1020, -60
sc = 2d0**(e/2) * 2d0**(e - e/2) ! power of two, entries stay normal
h = h0*sc
wr = wr0*sc
wi = wi0*sc
sel = .true.
call dhsein('R', 'Q', 'N', sel, n, h, n, wr, wi, vl, n, vr, n, n, m, &
work, ifl, ifr, info)
print '(a,i6,a,i2)', 'scale 2^', e, ' dhsein info =', info
end do
end program repro
On master:
scale 2^ -900 dhsein info = 0
scale 2^ -960 dhsein info = 0
scale 2^ -1020 dhsein info = 4
With this change:
scale 2^ -900 dhsein info = 0
scale 2^ -960 dhsein info = 0
scale 2^ -1020 dhsein info = 0
Regression test
The existing near-underflow types of xCHKHS do not get near the failing range. Their norm is about SQRT(UNFL)*N/ULP, around 1e-137 in double precision and 1e-12 in single precision. For matrix types 9 to 11 (entries not much smaller than the norm), xCHKHS now repeats tests 12 and 13, the residuals of the eigenvectors from xHSEIN, with H and its eigenvalues scaled down to a norm of 0.01*UNFL/(N*ULP). There N*ULP*norm(H) is far below 0.1*UNFL and the entries are still normal. The scaled results are folded into RESULT(12) and RESULT(13) with MAX, and a nonzero INFO from the scaled call counts as a failure, so no test is added and the test count does not change. The header of each file says so under tests (12) and (13). The scaled matrix is kept in Z, which is not used after test 5, the scaled eigenvalues in WORK beyond the part used by xHSEIN and xGET22, and the eigenvectors in EVECTR and EVECTL, which tests 16 and 17 recompute afterwards, so no documented output of xCHKHS is changed by the check. The check is skipped where subnormal numbers are flushed to zero: at this scale EPS3 = HNORM*ULP of xHSEIN is subnormal, so on such a machine it would be zero, no vector can be found, and xHSEIN would rightly report failure.
In SCHKHS and DCHKHS the scaled test is only run when all eigenvalues came out real, because the complex-pair path of SLAEIN and DLAEIN is not changed and cannot give meaningful vectors at this scale (see below). The complex routines have no such restriction.
On master, the new check fails 114 results in each of SCHKHS and DCHKHS and 180 in each of CCHKHS and ZCHKHS over the five parameter sets of nep.in, with xHSEIN returning INFO > 0. They are all tests 12 and 13 of types 9 to 11. With this change they pass. The largest ratio of the two tests over types 9 to 11 is 2.3 (DCHKHS), 2.75 (SCHKHS), 1.9 (CCHKHS) and 2.8 (ZCHKHS) against the threshold of 20.
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. 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 complex-conjugate-pair path of
SLAEIN and DLAEIN still forms GROWTO as a reciprocal. For a norm below 0.1/(HUGE*N*ULP) it reports INFO > 0 as on master, and for norms between about UNFL*N/ULP and that bound it returns inaccurate vectors with INFO = 0 (a residual of about 0.1 of the norm in a 5-by-5 test matrix), on master and before xLAEIN: apply the growth test to the growth, not to |x| alone #1400 as well. The pivot test of that path treats pivots up to SMLNUM = UNFL*(N/ULP) as zero, an absolute floor, so the path cannot give a meaningful vector there whatever the growth test does. Changing only the test would turn today's INFO > 0 into INFO = 0 with a meaningless vector (about 2000 such cases in my double precision sample), so I left it. It needs its own fix, covering the floor and the growth test together.
- Matrices with subnormal entries are not covered: with this change
xHSEIN still fails for the 4-by-4 matrix above at a scale of 2**-1050, where the entries are subnormal.
Checklist
- The documentation has been updated. (Not needed: the routines do what they document; only comments inside the code changed.)
- If the PR solves a specific issue, it is set to be closed on merge. (No tracking issue.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
codecov
Bot
commented
Nov 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 65.43210% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.65%. Comparing base (fab6f2c) to head (cd283c7).
✅ All tests successful. No failed tests found.
Additional details and impacted files

@@ Coverage Diff @@
## master #1520 +/- ##
==========================================
- Coverage 70.65% 70.65% -0.01%
==========================================
Files 6243 6243
Lines 501410 501564 +154
Branches 23516 23516
==========================================
+ Hits 354296 354394 +98
- Misses 146251 146307 +56
Partials 863 863
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 fab6f2c...cd283c7. Read the comment docs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Since f4b5da4 (Reference-LAPACK#1400) the acceptance test of the inverse iteration
in xLAEIN compares V1NORM with GROWTO*SCALE*V0NORM, where GROWTO is
formed once as TENTH / ( N*EPS3 ). xHSEIN passes EPS3 = HNORM*ULP,
so for a Hessenberg matrix of norm below about 0.1/(HUGE*N*ULP)
(about 6e-295 for N = 4 in double precision) N*EPS3 falls below
about 0.1/HUGE and GROWTO overflows to +Inf. The test can then never
hold: every vector is reported as not converged and xHSEIN returns
INFO equal to the number of failures, although the matrix is well
conditioned and all its entries are normal. Before that commit
GROWTO was TENTH/ROOTN and the routines worked down to norms of
about 1e-303.
For example, a well-conditioned 4-by-4 matrix scaled by 2**-1020
(double precision, entries of order 1e-307, accurate eigenvalues
supplied) gives INFO = 4 from DHSEIN, and the same happens in ZHSEIN
from a scale of 2**-990. In single precision it fails from a scale
of 2**-120 of an O(1) matrix.
CLAEIN and ZLAEIN, and SLAEIN and DLAEIN for a real eigenvalue, now
compare V1NORM with ( TENTH*SCALE )*( V0NORM / ( N*EPS3 ) ) and
also require V0NORM > 0. V0NORM is the 1-norm of a vector scaled to
2-norm EPS3*SQRT(N), so the ratio is of order one and nothing
overflows. The test is still applied to the growth
V1NORM/(SCALE*V0NORM), as f4b5da4 intended. SCALE > 0 is not
required: in these paths zero pivots are replaced by EPS3, so
SCALE = 0 with a nonzero starting vector can only come from the
rescaling in xLATRS underflowing after very large growth, which is
exactly a vector to accept.
One behavior changes at ordinary norms, through V0NORM > 0: with
INITV = 'U' and a zero column supplied as starting vector (a real
eigenvalue, or any eigenvalue in CLAEIN/ZLAEIN), the parent accepts
the zero vector (0 >= 0) and returns an all-NaN vector with INFO = 0.
Now the routine restarts from its own vector and returns a proper
eigenvector. For DHSEIN('R','Q','U') on H = [4 1 0; 1 3 1; 0 1 1]
with VR = 0 the parent returns NaN with INFO = 0, and this change
returns a finite vector of unit max-norm. The complex-pair path of
SLAEIN and DLAEIN still returns NaN there, as before.
The complex-pair path of SLAEIN and DLAEIN keeps the test as it was,
with GROWTO now formed only there. Its pivot test treats pivots up
to SMLNUM = UNFL*(N/ULP) as zero, an absolute floor, so for norms of
about SMLNUM and below it cannot give a meaningful vector whatever
the growth test does. Changing only the test would turn the INFO > 0
that the overflow gives there into INFO = 0 with a meaningless
vector, and requiring SCALE > 0 there rejects vectors that are
valid: in my samples the 717 (D) and 387 (S) valid vectors that a
SCALE > 0 requirement rejected were all in this path. That path
needs its own fix and keeps its behavior.
On 6000 random Hessenberg matrices per precision (random, Jordan-like,
clustered, split, perturbed eigenvalues, with and without initial
vectors, scales 2**-200 to 2**200) the vectors, INFO and IFAIL
values from xHSEIN are bit-for-bit identical to those of the parent
commit. On 6000 matrices per precision at scales 2**-900 to 2**-1015
(single precision: 2**-90 to 2**-124), no result that was valid on
the parent got worse, and 845 (D), 925 (S), 2701 (C) and 2619 (Z)
that failed with INFO > 0 on the parent give valid vectors.
Test: in xCHKHS, for matrix types 9 to 11, whose entries are not
much smaller than the norm (and, in the real routines, only when all
eigenvalues came out real, because of the complex-pair path above),
tests 12 and 13 are repeated with H and its eigenvalues scaled down
to a norm of 0.01*UNFL/(N*ULP). There N*ULP*norm(H) is far below
0.1*UNFL, but the entries are still normal. The scaled matrix and
eigenvalues are kept in Z and in WORK, not in documented outputs, and
the check is skipped where subnormal numbers are flushed to zero
(there EPS3 = HNORM*ULP would be zero). On the parent commit
xHSEIN returns INFO > 0 there and tests 12 and 13 fail: 114 results
in each of S and D, 180 in each of C and Z, over the five parameter
sets of nep.in. All pass now, with a largest ratio of about 3
against the threshold of 20. The existing near-underflow types do
not get there: they only go down to about SQRT(UNFL), far above the
failing range.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
langou
langou approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|