Repository navigation
Conversation
…AQSY family xLAQGE and xLAQGB (EQUED = 'B') and xLAQSY, xLAQSP, xLAQSB, xLAQHE, xLAQHP and xLAQHB scale each entry with two factors, written CJ*R( I )*A( I, J ) or CJ*S( I )*A( I, J ). Fortran evaluates the product of the two factors first. The factors that xGEEQU, xGBEQU, xPOEQU, xPPEQU and xPBEQU compute can each be large, and when both are, the product overflows to Inf although the scaled entry CJ*R( I )*A( I, J ) is O(1) because A( I, J ) is tiny. For example, A = [ 2*d d ; 1 1e-20 ] with d = 2**(-1074) gives R( 1 ) = 2**1022 and C( 2 ) = 2**52 in DGEEQU, so DLAQGE computes the factor 2**1074 for A( 1, 2 ), which is Inf, and returns Inf where the exact result is 1. The same happens through DGBEQU and DLAQGB. For a symmetric positive definite matrix with all entries equal to d, DPOEQU, DPPEQU and DPBEQU return S = 2**537, and DLAQSY, DLAQSP and DLAQSB return Inf for every entry (the exact result is 1); the Hermitian routines also overflow in the factor CJ*CJ used for the diagonal. This reaches xGESVX and xGBSVX with FACT = 'E' (and the xPOSVX, xPPSVX and xPBSVX drivers) with finite input. Form the factor T = CJ*R( I ) (CJ*S( I ), CJ*CJ) as before, and use T*A( I, J ) unless T overflows, so the result for every input whose factor product does not overflow is unchanged bit for bit. If T overflows, apply the larger of the two factors to A( I, J ) first and the smaller second, as MIN( CJ, R( I ) )*( MAX( CJ, R( I ) )*A( I, J ) ). The first multiply lifts the tiny entry into the normal range, so only the second rounds. For the diagonal of the Hermitian routines the two factors are equal and the entry is scaled by CJ twice. With A( I, J ) = 0 the result is 0 as before. Test: xCHKEQ (the EQ path) now also calls xLAQGE, xLAQGB, xLAQSY, xLAQSP, xLAQSB (and, for complex, xLAQHE, xLAQHP, xLAQHB) after the matching equilibration routine on 2-by-2 matrices with subnormal entries, for both UPLO values (the complex symmetric and Hermitian cases use an off-diagonal entry with a nonzero imaginary part), and requires every scaled entry to agree with the exact value to within the test threshold. On the parent commit the test fails in all four precisions (the entries are Inf); with this change it passes. The test is skipped if the machine does not have subnormal numbers. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Please upload reports for the commit d1dc835 to get more accurate results.
Additional details and impacted files@@ Coverage Diff @@
## master #1507 +/- ##
==========================================
+ Coverage 70.63% 70.70% +0.06%
==========================================
Files 6243 6243
Lines 501290 502014 +724
Branches 23516 23516
==========================================
+ Hits 354100 354932 +832
+ Misses 146327 146219 -108
Partials 863 863
Continue to review full report in Codecov by Harness.
|
| * | ||
| * ZLAQGE | ||
| * | ||
| A( 1, 1 ) = DCMPLX( TWO*DEN, ZERO ) |
There was a problem hiding this comment.
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 (31 uses in this file, lines 483-698). 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).
There was a problem hiding this comment.
Fixed in d1dc835: all 31 uses are now CMPLX( ..., KIND=DP ).
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 1151229 tests with no failures. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AI disclosure: This PR was prepared with Claude Code.
Summary
xLAQGEandxLAQGB(EQUED = 'B'), andxLAQSY,xLAQSP,xLAQSB,xLAQHE,xLAQHPandxLAQHB, scale each entry by two factors written asCJ*R( I )*A( I, J )orCJ*S( I )*A( I, J ). Fortran multiplies the two factors first, and that product can overflow to Inf although the scaled entry is O(1). With d = 2^-1074,DGEEQUon A = [ 2d d ; 1 1e-20 ] returns R(1) = 2^1022 and C(2) = 2^52, andDLAQGEthen sets A(1,2) to Inf instead of 1. For the symmetric positive definite matrix with all entries equal to d,DPOEQU,DPPEQUandDPBEQUreturn S = 2^537, andDLAQSY,DLAQSPandDLAQSBreturn Inf for every entry instead of 1. The input is finite and the exact scaled result is representable.Description
The scale factors computed by
xGEEQU,xGBEQU(and thexGEEQUBvariants) are clamped only to [SAFMIN, 1/SAFMIN], so R and C can both be about 2^1022, and the product CJR(I) can reach 2^2044.xPOEQU,xPPEQUandxPBEQUreturn S = 1/sqrt(A(I,I)), which is 2^537 for a subnormal diagonal entry, so CJS(I) can reach 2^1074. In both cases the entry A(I,J) being scaled is correspondingly tiny and the final result is at most about 1. The Hermitian routines also use CJ*CJ for the diagonal. The routines are reached throughxGESVXandxGBSVXwith FACT = 'E', and throughxPOSVX,xPPSVXandxPBSVX, with finite input.Fix
The factor T = CJR(I) (or CJS(I), or CJ*CJ) is formed as before and used as before unless it overflows, so every input whose factor product does not overflow gives bit-for-bit the same result. If T overflows, the entry is computed as
MIN( CJ, R(I) )*( MAX( CJ, R(I) )*A(I,J) ): the larger factor is applied to A(I,J) first, which lifts the tiny entry into the normal range so that only the second multiply rounds, then the smaller. For the diagonal of the Hermitian routines both factors are equal and the entry is multiplied by CJ twice. With A(I,J) = 0 the result is 0.xLAQGE/xLAQGBonly change the 'B' branch, because the row-only and column-only branches use a single factor.xLASCL2,xLARSCL2and thexxdrivers use a single factor and are not affected.xLAQZ*do not use these formulas.Reproducer
On master:
With the fix:
Regression test
xCHKEQ(the EQ path) now also callsxLAQGE,xLAQGB,xLAQSY,xLAQSPandxLAQSB(andxLAQHE,xLAQHP,xLAQHBfor complex) after the matching equilibration routine, on 2-by-2 matrices with subnormal entries, for UPLO = 'U' and 'L'. The complex symmetric and Hermitian cases use an off-diagonal entry with a nonzero imaginary part. It requires every scaled entry to agree with the exact value to within the test threshold andEQUEDto be 'B' or 'Y' as expected. The test is skipped on a machine without subnormal numbers. On master the new check fails in all four precisions (value Infinity); with this changeAll tests for SEQ, DEQ, CEQ and ZEQ routines passed the threshold.Separately, 20000 random 6-by-6 matrices with entries spread over about 60 decades were equilibrated and scaled with
DLAQGE,DLAQSY,ZLAQHEandSLAQGE(in the range of single precision). A checksum of every result bit was identical before and after the change, as was a 2-by-2 matrix with entries of 1e306 to 1.7e308, for which the factor is subnormal.Test suite
The full test suite passes, configured as in CI (
CBLAS=ON,LAPACKE=ON,LAPACKE_WITH_TMG=ON) with the_64API. All 333 CTest entries pass, with 5755188 LAPACK tests (5755190 for the_64API), 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 equilibration tests are not counted in them. 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 withCMAKE_BUILD_TYPE=Releaseon x86-64 Linux.Not changed here
xGEEQUgives a subnormal factor CJ*R(I), and the scaled entry can lose a few ulps. This is not changed.xCHKEQroutines (forxGEEQUBandxGBEQUB), so whichever is merged second needs a trivial rebase of theRESLTSslots.Checklist