Skip to content

TESTING/MATGEN: guard zero leading element in ZLAGHE - #1365

Merged
langou merged 1 commit into
Reference-LAPACK:masterfrom
nakatamaho:fix-zlaghe-zero-leading
Aug 24, 2026
Merged

langou merged 1 commit into
Reference-LAPACK:masterfrom
nakatamaho:fix-zlaghe-zero-leading

Conversation

@nakatamaho

Copy link
Copy Markdown
Contributor

Summary

ZLAGHE computes the phase of a Householder reflector with expressions of the form:

WA = ( WN / ABS( A( K+I, I ) ) )*A( K+I, I )

When WN is nonzero but the leading element is exactly zero, this evaluates as Inf * 0 and produces NaNs. This can occur at higher precision because rounding may make the leading element exactly zero while the remaining vector has a nonzero norm.

This patch handles both reflector-generation loops:

  • zero norm: use WA = ZERO, TAU = ZERO;
  • nonzero norm with zero leading element: use WA = DCMPLX(WN,0);
  • otherwise preserve the existing phase computation.

Choosing a positive-real phase is valid for a zero leading element and produces a finite reflector with TAU = 1.

Motivation

The issue was observed through MPLAPACK's MPFR binary128 (113-bit) ZHB test with N=20, K=16, clustered eigenvalues. ZLAGHE returned a matrix containing NaN, which later caused CSTEQR to fail. The same case did not reproduce at 112 or 114 bits.

Validation

  • gfortran -ffixed-form -ffixed-line-length-72 -fsyntax-only TESTING/MATGEN/zlaghe.f
  • The corresponding generated C++ path in MPLAPACK was tested with the 113-bit reproducer; the ZHB case completed without NaN and passed all six checks.

@langou

langou commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Should we push the same change for 'CLAGHE' too? if yes, @nakatamaho, can you do it?

@nakatamaho

Copy link
Copy Markdown
Contributor Author

I'll reaise a PR soon

@nakatamaho

Copy link
Copy Markdown
Contributor Author

#1366 here it is. Thanks!

langou pushed a commit that referenced this pull request Aug 24, 2026
CLAGHE formed the phase of a Householder reflector as (WN / ABS(WORK(1))) * WORK(1), and used the analogous expression in the band-reduction loop. If WN is nonzero while the leading element rounds to zero, this evaluates as Inf * 0 and contaminates the generated Hermitian matrix with NaNs.

Use a finite positive-real phase when the leading element is zero, while preserving the zero-norm and ordinary phase paths. This is the complex-single counterpart of PR #1365's ZLAGHE fix.
@langou
langou merged commit 790d7dd into Reference-LAPACK:master Aug 24, 2026
43 of 44 checks passed
@langou

langou commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Thanks!

ilayn added a commit to ilayn/semicolon-lapack that referenced this pull request Oct 26, 2026
…ects (#43)

- Use the DLAMCH constant the Fortran asks for in 35 routines (and their
  s/c copies). DBL_EPSILON stood in for DLAMCH('Epsilon'), which is half
  of it, or the reverse. In xLAGTS this doubled the pivot tolerance, and
  inverse iteration in xSTEIN failed on tight clusters, so ZHEEVX/ZHPEVX
  returned INFO > 0 where reference LAPACK succeeds.
- xGEDMD returns after XERBLA in the NaN checks of X and Y.
  Reference-LAPACK/lapack#1395
- ZLAGHE/CLAGHE guard a zero leading element of the reflector.
  Reference-LAPACK/lapack#1365
  Reference-LAPACK/lapack#1366
- xTSQR01 checks the GEMLQ('R','N') residual it computes.
  Reference-LAPACK/lapack#1364
- xDRVES: Fortran xSLECT with SELOPT = 0, complete test 13, and the
  documented xGEES exit codes N+1 and N+2.
  Reference-LAPACK/lapack#1355
- IL/IU drawn from the full [1, N] range in the CHKST, DRVST, DRVSG,
  CHKBD and DRVBD drivers, and the xDRVBD GESVDX tests ported line by
  line.
  Reference-LAPACK/lapack#1347
- xDRVLS random right-hand sides and EPS, real QZ drivers SAFMIN/ULP, RFP
  driver parameters from the *test_rfp.in files, invented singular values
  removed from the xDRVBD generator, new seed for zDRVST/zDRVST2STG.
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