GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Avoid overflow of the two-factor scaling in xLAQGE, xLAQGB and the xLAQSY family by rmlarsen · Pull Request #1507 · Reference-LAPACK/lapack Conversation
Contributor
AI disclosure: This PR was prepared with Claude Code. Summary
Description The scale factors computed by 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
Reproducer program repro implicit none double precision :: a(2,2), ap(3), s(2), r(2), c(2), rowcnd, colcnd, amax double precision :: den integer :: info character :: eq den = 4.9406564584124654d-324 ! 2**(-1074), the smallest subnormal ! General: row 1 is subnormal, so R(1) = 2**1022; column 2 has C(2) = 2**52. a = reshape([2d0*den, 1d0, den, 1d-20], [2, 2]) call dgeequ(2, 2, a, 2, r, c, rowcnd, colcnd, amax, info) call dlaqge(2, 2, a, 2, r, c, rowcnd, colcnd, amax, eq) print *, 'dlaqge equed =', eq, ' A(1,2) =', a(1, 2), ' (expected 1)' ! Symmetric positive definite 2x2 matrix [d d; d d] in packed storage. ap = den call dppequ('U', 2, ap, s, rowcnd, amax, info) call dlaqsp('U', 2, ap, s, rowcnd, amax, eq) print *, 'dlaqsp equed =', eq, ' AP =', ap, ' (expected 1 1 1)' end program repro On master: With the fix: Regression test
Separately, 20000 random 6-by-6 matrices with entries spread over about 60 decades were equilibrated and scaled with Test suite The full test suite passes, configured as in CI ( Not changed here
Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…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 <[email protected]>
rmlarsen
marked this pull request as draft
rmlarsen
marked this pull request as ready for review
|
There was an error while loading. Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## master #1507 +/- ## ========================================== + Coverage 70.63% 70.72% +0.08% ========================================== Files 6243 6243 Lines 501290 502134 +844 Branches 23516 23516 ========================================== + Hits 354100 355128 +1028 + Misses 146327 146143 -184 Partials 863 863
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Harness.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * | ||
| * ZLAQGE | ||
| * | ||
| A( 1, 1 ) = DCMPLX( TWO*DEN, ZERO ) |
There was a problem 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 (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).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d1dc835: all 31 uses are now CMPLX( ..., KIND=DP ).
Sorry, something went wrong.
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 1151229 tests with no failures. Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.