GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pass the unscaled eigenvalues to the selection function in CGGES, ZGGES, CGGES3 and ZGGES3 by rmlarsen · Pull Request #1519 · Reference-LAPACK/lapack

Conversation

@rmlarsen

@rmlarsen rmlarsen commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

AI disclosure: This PR was prepared with Claude Code.

Summary

When CGGES, ZGGES, CGGES3 or ZGGES3 scale A or B and SORT = 'S', the selection function receives ALPHA and BETA scaled twice instead of in the units of the input. A selection that depends on magnitudes then picks the wrong eigenvalues, and the driver can return INFO = N+2 for a well-conditioned problem. ZGGES on the 2-by-2 pencil A = s*[0.5 1; 0 2], B = I with a selection function that selects |ALPHA| > s returns INFO = 4 for s = 1e200 and for s = 1e-200, and INFO = 0 for s = 1. The eigenvalues returned are correct; only what SELCTG sees, and so the ordering and INFO, is wrong. Found by reading xGGESX, which has this step right.

Description

The drivers scale A (and B) to bring its largest entry into [SMLNUM, BIGNUM] with xLASCL( 'G', 0, 0, ANRM, ANRMTO, ... ). Before calling SELCTG, "Undo scaling on eigenvalues before selecting" calls xLASCL on ALPHA and BETA with the same argument order, ANRM, ANRMTO. xLASCL multiplies by CTO/CFROM, so this multiplies by ANRMTO/ANRM a second time instead of undoing the scaling. xGGESX and the real drivers xGGES and xGGES3 pass ANRMTO, ANRM. CGGES3 and ZGGES3 copied the order from CGGES and ZGGES, where it dates from the original code.

xTGSEN recomputes ALPHA and BETA and the final undo-scaling is correct, so the returned eigenvalues are right. In the example, SELCTG sees eigenvalues of size 1e75 (s = 1e200) or 1e-77 (s = 1e-200) instead of 1e200 or 1e-200, selects none, and nothing is reordered. The final check then finds the selected eigenvalue behind the unselected one, sets INFO = N+2 and recomputes SDIM. A selection that is true for all or for none of the eigenvalues is not affected, and neither is a selection that depends only on signs, such as xLCTES (positive scale factors do not change signs). That is why the existing tests with scaled matrix types did not catch it.

Fix

Swap the two scale arguments of the four xLASCL calls that undo the scaling of ALPHA and BETA before the selection, in CGGES, ZGGES, CGGES3 and ZGGES3. Problems for which neither A nor B is scaled behave exactly as before.

Reproducer

module sel_mod
  real(8) :: thr
contains
  logical function sel(alpha, beta)   ! select the eigenvalues with |ALPHA| > thr
    complex(8) :: alpha, beta
    sel = abs(alpha) > thr
  end function
end module

program repro
  use sel_mod
  implicit none
  integer, parameter :: n = 2, lwork = 64
  complex(8) :: a(n,n), b(n,n), alpha(n), beta(n), vsl(1,1), vsr(1,1), work(lwork)
  real(8) :: rwork(8*n), s
  logical :: bwork(n)
  integer :: sdim, info, k
  do k = -200, 200, 200
    s = 10.0d0**k
    thr = s                      ! the eigenvalues are 0.5*s and 2*s: only 2*s is selected
    a = (0.0d0, 0.0d0)
    b = (0.0d0, 0.0d0)
    a(1,1) = 0.5d0*s
    a(1,2) = s
    a(2,2) = 2.0d0*s
    b(1,1) = 1.0d0
    b(2,2) = 1.0d0
    call zgges('N', 'N', 'S', sel, n, a, n, b, n, sdim, alpha, beta, vsl, 1, vsr, 1, &
               work, lwork, rwork, bwork, info)
    print '(a,i5,a,i2,a,i2,a,2es10.2e3)', 'A scaled by 1e', k, ': SDIM =', sdim, &
          ', INFO =', info, ', |ALPHA| =', abs(alpha)
  end do
end program

On master:

A scaled by 1e -200: SDIM = 1, INFO = 4, |ALPHA| = 5.00E-201 2.00E-200
A scaled by 1e    0: SDIM = 1, INFO = 0, |ALPHA| = 2.00E+000 5.00E-001
A scaled by 1e  200: SDIM = 1, INFO = 4, |ALPHA| = 5.00E+199 2.00E+200

With the fix (the selected eigenvalue now comes first for every s):

A scaled by 1e -200: SDIM = 1, INFO = 0, |ALPHA| = 2.00E-200 5.00E-201
A scaled by 1e    0: SDIM = 1, INFO = 0, |ALPHA| = 2.00E+000 5.00E-001
A scaled by 1e  200: SDIM = 1, INFO = 0, |ALPHA| = 2.00E+200 5.00E+199

Regression test

  • New selection function CLCTSM/ZLCTSM (in clctes.f/zlctes.f). It selects an eigenvalue whose ALPHA has negative real part and whose BETA is nonzero, but only if ALPHA or BETA lies outside [sqrt(safe minimum), 1/sqrt(safe minimum)]. xLCTES cannot be used, because it depends only on signs.
  • CDRGES, ZDRGES, CDRGES3 and ZDRGES3 first run xGGES/xGGES3 with SORT = 'S' and xLCTSM on eight fixed 2-by-2 diagonal pencils, with s = overflow**0.75 or its reciprocal (about 1e231 and 1e-231 in double precision): A = diag(s, -s) or diag(-s, s) with B = I, and A = diag(1, -1) or diag(-1, 1) with B = s*I. This uses the A-above-BIGNUM, A-below-SMLNUM, B-above-BIGNUM and B-below-SMLNUM scaling branches. Each must return INFO = 0, SDIM = 1, and the selected eigenvalue first in (ALPHA, BETA). With the eigenvalues passed in the right units, exactly one of the two is selected. With them scaled twice, neither is, so nothing is reordered whenever the selected eigenvalue is second, and INFO = N+2. The pencils are fixed and have no entries or eigenvalues near the selection boundary, so the result does not depend on random matrices, the compiler or FMA. These checks are counted in the number of tests run but are not among the numbered tests, which are unchanged (no test numbering is added).
  • On the parent commit, 4 of the 8 pencils fail in each of CDRGES, CDRGES3, ZDRGES and ZDRGES3 (all with INFO = 4 and SDIM = 1, one per scaling branch); with the fix all pass. This was the same in a default Release build, a build with CI's gfortran flags (-O2 -Wall ... -fcheck=all) and a build with -O3 -march=native.

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 5755220 LAPACK tests (5755222 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 32 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

  • Open PR Unscale ALPHA and BETA in xGGES, xGGES3 and xGGESX after a QZ failure #1500 changes the same four SRC files (and the other xGGES drivers) a few lines further down, on the QZ-failure path, and announces this defect as a separate fix. The diffs do not overlap, so they should rebase trivially.
  • Open PR Check LWORK against the blocked code's workspace for every NH in xGGHD3 #1504 adds a test numbered 14 to the same ?drges3.f drivers and describes slot 13 as unused there. This PR adds no numbered test, but the two both edit those files, so whichever is merged second needs a small rebase.
  • In the complex test drivers, the SDIM check of test 12 stores its failure in RESULT( 13 ), while only RESULT( 1:12 ) are reported, so it can never fail (the real drivers use RESULT( 12 )). Not changed here.
  • The real drivers, xGGESX, xGEES and xGEESX already undo the scaling in the right order before selecting; xGGEV, xGGEV3 and xGGEVX have no selection.

Checklist

  • The documentation has been updated. (Not needed: the drivers now do what they document.)
  • 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.

All reactions
@codecov

codecov Bot commented Nov 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.66%. Comparing base (fab6f2c) to head (dcceb7d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
TESTING/EIG/cdrges.f 91.17% 3 Missing ⚠️
TESTING/EIG/cdrges3.f 91.17% 3 Missing ⚠️
TESTING/EIG/zdrges.f 91.17% 3 Missing ⚠️
TESTING/EIG/zdrges3.f 91.17% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1519    +/-   ##
========================================
  Coverage   70.65%   70.66%            
========================================
  Files        6243     6243            
  Lines      501410   501560   +150     
  Branches    23516    23516            
========================================
+ Hits       354296   354434   +138     
- Misses     146251   146263    +12     
  Partials      863      863            
Components Coverage Δ
BLAS 99.73% <ø> (ø)
CBLAS 96.95% <ø> (ø)
LAPACK 83.77% <ø> (ø)
LAPACKE 4.18% <ø> (ø)
TMGLIB 55.69% <ø> (ø)
BLAS testing 88.79% <ø> (ø)
CBLAS testing 89.65% <ø> (ø)
LAPACK testing 82.42% <92.00%> (+<0.01%) ⬆️
LAPACKE testing ∅ <ø> (∅)
Files with missing lines Coverage Δ
SRC/cgges.f 92.90% <ø> (ø)
SRC/cgges3.f 92.81% <ø> (ø)
SRC/zgges.f 92.90% <ø> (ø)
SRC/zgges3.f 92.81% <ø> (ø)
TESTING/EIG/clctes.f 88.23% <100.00%> (+8.23%) ⬆️
TESTING/EIG/zlctes.f 88.23% <100.00%> (+8.23%) ⬆️
TESTING/EIG/cdrges.f 80.24% <91.17%> (+1.73%) ⬆️
TESTING/EIG/cdrges3.f 80.63% <91.17%> (+1.63%) ⬆️
TESTING/EIG/zdrges.f 80.24% <91.17%> (+1.73%) ⬆️
TESTING/EIG/zdrges3.f 80.63% <91.17%> (+1.63%) ⬆️

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rmlarsen @claude
Pass xGGES and xGGES3 selection functions the unscaled eigenvalues (c…
dcceb7d
…omplex)

CGGES, ZGGES, CGGES3 and ZGGES3 scale A (and B) when its largest entry
lies outside [SMLNUM, BIGNUM], computing the scaled matrix with
xLASCL( ANRM, ANRMTO ). Before calling SELCTG, with SORT = 'S', they
undo the scaling on ALPHA and BETA, but wrote the arguments of xLASCL
in the same order as the forward scaling instead of reversed. xLASCL
multiplies by CTO/CFROM, so ALPHA was multiplied by ANRMTO/ANRM a
second time rather than divided. The expert drivers xGGESX and the real
drivers xGGES/xGGES3 have the order right.

The user's SELCTG therefore saw eigenvalues that were scaled twice
instead of being in the units of the input. The returned ALPHA and BETA
are right, because xTGSEN recomputes them and the final undo-scaling is
correct, but the selection is not. With the 2-by-2 pencil
A = s*[0.5 1; 0 2], B = I and a SELCTG that selects |ALPHA| > s, ZGGES
with s = 1e200 (and s = 1e-200) saw eigenvalues of size 1e75 (and 1e-77),
selected neither, and did not reorder. The final check then found the
selected eigenvalue after the unselected one and returned INFO = N+2,
although the problem is well conditioned and can be ordered; with s = 1
it returned INFO = 0. With a selection that is true for every eigenvalue
(or for none) the effect is only on SDIM bookkeeping, so it went
unnoticed.

Swap the two scale arguments of the four xLASCL calls on ALPHA and BETA.
Unscaled problems (neither matrix scaled) are unaffected.

Test: the existing selection function xLCTES only depends on the signs
of the real and imaginary parts of ALPHA/BETA, which positive scale
factors do not change, so no scaled matrix type could expose this. Add
xLCTSM (c, z), which selects an eigenvalue with negative real part of
ALPHA and nonzero BETA only if ALPHA or BETA is far outside
[sqrt(safmin), 1/sqrt(safmin)]. CDRGES, ZDRGES, CDRGES3 and ZDRGES3 now
first run xGGES/xGGES3 with SORT = 'S' and xLCTSM on eight fixed 2-by-2
diagonal pencils: A = diag(s, -s) or diag(-s, s) with s about
overflow**0.75 or its reciprocal and B = I, and A = diag(1, -1) or
diag(-1, 1) with B = s*I for the same two s. So the A-large, A-small,
B-large and B-small scaling branches are all used, and in half of the
pencils the eigenvalue to select is not first. Each must return INFO = 0,
SDIM = 1 and the selected eigenvalue first. On the parent commit the four
pencils with the selected eigenvalue second fail with INFO = N+2 (4 of 8
in each of the four drivers); with the fix all pass, in a default, a
CI-flags and an -O3 -march=native build. The pencils are fixed, so no
random matrix type is involved.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@rmlarsen
rmlarsen force-pushed the gges-complex-select-unscale branch from 9d4cbd4 to dcceb7d Compare November 25, 2026 23:03
langou
langou approved these changes Nov 27, 2026
View reviewed changes
@langou
langou merged commit b7c328a into Reference-LAPACK:master Nov 27, 2026
60 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@langou langou langou approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@rmlarsen @langou
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.