GeezerVison is showing github.com — Let xLAQZ0 fall back to xHGEQZ when LWORK is below the multishift need by rmlarsen · Pull Request #1518 · Reference-LAPACK/lapack
Conversation
AI disclosure: This PR was prepared with Claude Code.
Summary
xLAQZ0 documents LWORK >= max(1,N), but for N at or above its crossover (ILAENV with ISPEC = 12, 75 by default) it needs MAX( ITEMP1+2*NW**2, ITEMP2+2*NBR**2 ) entries, 45075 for N = 100, and otherwise returns INFO = -19 (-18 for CLAQZ0 and ZLAQZ0) through XERBLA. xGGEV3 and xGGES3 pass on what is left of their own workspace and document minima that do not include this (8*N, 6*N+16 and 2*N), so a call with the documented minimum LWORK stops in the reference XERBLA: DGGEV3 with N = 200 and LWORK = 1600 prints " ** On entry to DLAQZ0 parameter number 19 had an illegal value", and so do DGGES3 with LWORK = 1216 and ZGGEV3 with LWORK = 400. With the LWORK from the drivers' workspace queries everything works.
Description
The multishift code with aggressive early deflation needs workspace for the deflation window and for the sweep, in addition to the small-matrix recursion. xLAQZ0 computes that requirement from workspace queries of xLAQZ3 and xLAQZ4 and treats a smaller LWORK as an argument error, although the documentation promises that max(1,N) is enough. For N below the crossover xLAQZ0 calls xHGEQZ, which needs only N entries, so the documented minimum is correct only there.
Fix
When LWORK is smaller than the requirement but at least max(1,N), xLAQZ0 now calls xHGEQZ, as it already does for N < NMIN, and returns. This is how xGGHD3 and xGEHRD behave when their workspace is short, and xLAQR0, the standard-eigenvalue analogue, also accepts LWORK >= max(1,N). With this, the documented minima of xLAQZ0, xGGEV3 and xGGES3 are correct and need no change in the drivers. The *> entry for LWORK says that the double-shift algorithm is used when the workspace is short.
- LWORK <
max(1,N) still returns INFO = -19 (-18 for the complex routines) from xLAQZ0 itself.
- The workspace query still returns the optimal size, and after the fallback WORK(1) is set to that same value, as the documentation says (
xHGEQZ itself leaves N there).
- Results with LWORK at or above the queried optimum are unchanged; the code path is the same.
- The recursive calls are not affected.
xLAQZ3 calls xLAQZ0 with REC + 1, once as a query and once with LWORK-2*JW**2, and itself requires LWORK to be at least the query result plus 2*JW**2, so the inner call always has what it needs and never takes the fallback. For REC >= 2 xLAQZ0 already calls xHGEQZ.
The change is made in slaqz0.f, dlaqz0.f, claqz0.f and zlaqz0.f.
Reproducer
program repro
implicit none
integer, parameter :: n = 100
double precision :: a(n,n), b(n,n), q(n,n), z(n,n)
double precision :: ar(n), ai(n), beta(n), w(n)
integer :: i, j, info
call random_number(a)
call random_number(b)
do j = 1, n
do i = j+2, n
a(i,j) = 0
end do
do i = j+1, n
b(i,j) = 0
end do
end do
! LWORK = N is the documented minimum.
call dlaqz0('S', 'I', 'I', n, 1, n, a, n, b, n, ar, ai, beta, q, n, z, n, &
w, n, 0, info)
print '(a,i0)', 'info = ', info
end program repro
On master: ** On entry to DLAQZ0 parameter number 19 had an illegal value and the program stops. With this change: info = 0.
Regression test
Test 8 of xDRGEV3 (the SGV, DGV, CGV and ZGV paths) forms a Hessenberg-triangular pencil from the lower triangles of A and B and calls xLAQZ0 directly with LWORK = N, followed by a guard of four entries that must stay unchanged. The suite sets the crossover to 10 through XLAENV, so the sizes 10, 15 and 20 of dgd.in are above it. The test checks INFO, the guard, the residuals of A = Q S Z' and B = Q T Z', the orthogonality of Q and Z, that T is upper triangular and S upper (quasi-)triangular, and that ALPHA and BETA agree with the diagonal entries (for the real routines also the 2-by-2 blocks, through xGET53) of S and T. With LWORK = N the call takes the fallback, where xHGEQZ initializes Q and Z itself for WANTQ = WANTZ = 'I', so the test does not depend on the problem described under "Not changed here". It calls xLAQZ0 rather than xGGEV3 so that it does not depend on xGGHD3, which has its own workspace defect (see below). It needs N >= 2 so that the guard fits in the LWORK that xDRGEV3 requires.
The test calls xGET51, which needs 2*N**2 entries of WORK, so the minimum LWORK that xDRGEV3 enforces and documents is now MAX( 8*N, 2*N**2 ) (2*N**2 for CDRGEV3 and ZDRGEV3) instead of MAX( 8*N, N*(N+1) ) (N*(N+1)); its MAXWRK follows. The suite's caller in xCHKEE passes NMAX*(5*NMAX+5)+1 (real) or NMAX*(5*NMAX+20) (complex) entries with NMAX = 132, which covers it.
With threshold 0, the largest ratio of test 8 in the GV run of each precision was 3.10 (S), 2.55 (D), 2.12 (C) and 2.06 (Z) against the threshold of 10.
On master, 78 of the 1248 tests of each of the SGV, DGV, CGV and ZGV runs (sgd.in, dgd.in, cgd.in, zgd.in) fail, all of them test 8, with INFO = -19 (-18 for the complex routines). With this change they pass, as do the other tests of those runs (SGS, DGS, CGS and ZGS report 1560 tests and the earlier GV driver runs 1092 in each precision). Each matrix now adds 8 instead of 7 to the count of tests of the xDRGEV3 runs.
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 5755812 LAPACK tests (5755814 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. That is 624 LAPACK tests more per API than on master, the tests added here. 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
- Check LWORK against the blocked code's workspace for every NH in xGGHD3 #1504 fixes
xGGHD3, which on master overruns its WORK for 33 <= N <= 128 at the documented minimum LWORK of xGGEV3 and xGGES3 before they reach xLAQZ0. The two changes are independent. Check LWORK against the blocked code's workspace for every NH in xGGHD3 #1504 adds a test 14 to xDRGES3; this PR adds test 8 to xDRGEV3, so the files differ and no conflict is expected. For the full effect of both, a call of xGGEV3 or xGGES3 at the documented minimum needs both.
- With enough workspace,
xLAQZ0 called with WANTQ = 'I' or WANTZ = 'I' for N at or above the crossover returns Q and Z that do not reproduce the input: the final call to xHGEQZ is made with the original WANTQ and WANTZ, which re-initializes Q and Z to the identity and discards the accumulated transformations. For N = 100 and the optimal LWORK, the residual of A = Q S Z' is of order 1 with 'I' and 1e-14 with 'V' and Q = Z = I on input. xGGEV3 and xGGES3 pass 'V', so they are not affected, and the new test calls xLAQZ0 with 'I' only in the fallback, where xHGEQZ does all the work. I left this alone.
- The WORK(1) value on exit is not consistent in
xLAQZ0 as a whole: the N < NMIN path and the multishift path, which finishes with a call of xHGEQZ, leave N there, while the query returns the optimal size and the documentation says that WORK(1) returns the optimal LWORK. Only the new fallback sets the queried value. I did not change the other exits, since that is not part of this defect.
Checklist
- The documentation has been updated. (The LWORK entry of
xLAQZ0 now describes the fallback; the minima of xGGEV3 and xGGES3 are now correct as documented.)
- 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.
xLAQZ0 documents LWORK >= max(1,N), but once N reaches its crossover
(ILAENV with ISPEC = 12, 75 by default) it needs LWORKREQ = MAX(
ITEMP1+2*NW**2, ITEMP2+2*NBR**2) entries, 45075 for N = 100, and
returned INFO = -19 (-18 for the complex routines) through XERBLA when
LWORK was smaller. xGGEV3 and xGGES3 hand xLAQZ0 what is left of their
own workspace and document minima (8*N, 6*N+16, 2*N) that do not
include that requirement, so a call with the documented minimum LWORK
stopped in XERBLA: DGGEV3 with N = 200 and LWORK = 1600 printed
" ** On entry to DLAQZ0 parameter number 19 had an illegal value", and
so did DGGES3 with LWORK = 1216 and ZGGEV3 with LWORK = 400. A
direct call of DLAQZ0 with N = 100 and LWORK = 100 fails the same way.
xLAQZ0 now does what xGGHD3 and xGEHRD do when their workspace is
short: if LWORK is smaller than LWORKREQ but at least max(1,N), it
calls xHGEQZ, which it already calls for N < NMIN and which needs only
N entries, sets WORK( 1 ) to the optimal size that a query returns, and
returns. LWORK < max(1,N) still gives INFO = -19 (-18)
from xLAQZ0 itself, and the workspace query still returns LWORKREQ.
The recursive calls from xLAQZ3 are not affected: xLAQZ3 checks that
the LWORK it passes down covers the optimum of the inner xLAQZ0 query,
so the inner call never takes the fallback. Results with LWORK >=
LWORKREQ are unchanged. The LWORK entry of the documentation now says
that the double-shift algorithm is used when the workspace is short.
Test: xDRGEV3 (SGV, DGV, CGV and ZGV paths) gets a test 8. It forms a
Hessenberg-triangular pencil from the lower triangles of A and B and
calls xLAQZ0 directly with LWORK = N and four guard entries after
WORK( N ); the suite's crossover is 10, so N = 10, 15 and 20 are above
it. The fallback's xHGEQZ initializes Q and Z itself for WANTQ = WANTZ
= 'I'. The test checks INFO, the guard, the residuals of A = Q S Z' and
B = Q T Z', the orthogonality of Q and Z, the structure of S and T, and
that ALPHA and BETA agree with the diagonal entries and 2-by-2 blocks of
S and T. The test calls xGET51, which needs 2*N**2 entries of WORK, so
the minimum LWORK that xDRGEV3 requires and documents is now
MAX( 8*N, 2*N**2 ) (2*N**2 for the complex routines). On the parent
commit 78 of the 1248 tests of each of the SGV, DGV, CGV and ZGV runs
fail, all test 8 with INFO = -19 (-18). With the change they pass.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
codecov
Bot
commented
Nov 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 82.57576% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.67%. Comparing base (ef55c9b) to head (f8d7f29).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.
Additional details and impacted files

@@ Coverage Diff @@
## master #1518 +/- ##
==========================================
+ Coverage 70.63% 70.67% +0.03%
==========================================
Files 6243 6243
Lines 501290 501642 +352
Branches 23516 23516
==========================================
+ Hits 354100 354518 +418
+ Misses 146327 146261 -66
Partials 863 863
... and 8 files 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...f8d7f29. Read the comment docs.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
CALL ZLACPY( ' ', N, N, A, LDA, S, LDA )
|
|
|
CALL ZLACPY( ' ', N, N, B, LDA, T, LDA )
|
|
|
DO 245 I = 1, NGUARD
|
|
|
WORK( N+I ) = DCMPLX( GUARD, GUARD )
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DCMPLX is a non-standard intrinsic. 773fd2f ("TESTING: replace non-standard double complex intrinsics") removed every use from TESTING because NAG Fortran only accepts it under -dcfuns, and this reintroduces it (here and line 903). The NAG jobs are skipped on fork PRs (they finish in a few seconds here) but do build on master, so this would only show up after merge. Use CMPLX( ..., KIND=... ) with a kind parameter, as that commit did.
Found in an AI-assisted self-review (Claude Code).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f8d7f29: both uses are now CMPLX( ..., KIND=DP ).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The test added on this branch builds its double complex values with
DCMPLX, a VAX extension that NAG Fortran only accepts under -dcfuns.
773fd2f removed every such use from TESTING, and the NAG jobs do not
run on pull requests from forks, so the build would only break after
the merge.
Use CMPLX( ..., KIND=DP ) with a DP kind parameter, as that commit
did. The values are the same; the complex16 LAPACK tests of this
branch run 1151385 tests with no failures.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This branch has not been deployed
No deployments
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.
|