Repository navigation
add NaN checks for input matrix A in GEEV, return error if NaN are in matrix A, NaNs in input are detected with LANGE (needed for scaling) - #1136
Merged
langou merged 2 commits intoMar 24, 2026
Conversation
amontoison
approved these changes
Jun 19, 2025
TiborGY
reviewed
Jun 19, 2025
TiborGY
left a comment
There was a problem hiding this comment.
Perhaps it would be worth noting in the documentation that these subroutines check for NaNs in A.
E.g. something like this:
*> \param[in,out] A
*> \verbatim
*> A is DOUBLE PRECISION array, dimension (LDA,N)
*> On entry, the N-by-N matrix A, which must not contain any NaN elements.
*> On exit, A has been overwritten.
*> Note: A is checked for NaNs on entry, and an error exit is performed if any are found.
*> \endverbatim
TiborGY
reviewed
Oct 6, 2025
| $ LDVR, | ||
| $ WORK, LWORK, RWORK, INFO ) | ||
| implicit none | ||
| IMPLICIT NONE |
There was a problem hiding this comment.
The diff has a lot of formatting changes. Perhaps it would be a good idea to split this PR into a "meaningful changes" PR and a pure formatting changes PR?
Contributor
Author
There was a problem hiding this comment.
Thanks for the feedback. In a perfect world, I agree with your comment. Let us merge and I'll try to be better next time.
ilayn
added a commit
to ilayn/semicolon-lapack
that referenced
this pull request
Oct 26, 2026
…nd subnormal pivots (#41) - DGEEV/DGEEVX undo the scaling of every eigenvalue isolated by balancing (ILO is 0-based; translation error). - DLASD2/DLASD7 keep the deflated singular values in order. Reference-LAPACK/lapack#1140 Reference-LAPACK/lapack#1138 - DLAED4 takes the geometric-mean step when the update overshoots the bracket. New test_dlaed4_overshoot. Reference-LAPACK/lapack#1191 Reference-LAPACK/lapack#1166 - xLAEIN applies its acceptance test to the growth of the vector. Reference-LAPACK/lapack#1400 - xGEEV returns INFO = -4 for a matrix containing a NaN. New test_?geev_nan. Reference-LAPACK/lapack#1136 Reference-LAPACK/lapack#1128 - xSPTRF/xHPTRF report a NaN pivot in INFO. xCHKSP/xCHKHP gain a NaN-pivot case. Reference-LAPACK/lapack#1378 Reference-LAPACK/lapack#1393 - xGBTF2/xGBTRF divide by a pivot below SFMIN. xCHKGB gains matrix type 9. Reference-LAPACK/lapack#1379
2 tasks done
rmlarsen
added a commit
to rmlarsen/lapack
that referenced
this pull request
Nov 6, 2026
…ugh a negative INFO Following review, and the rule of Reference-LAPACK#1136 for xGEEV: when the norm that a routine computes for scaling is a NaN, or here also an infinity, return INFO = -(position of the array) instead of a positive INFO. xGELSD tests ANRM right after xLANGE and returns INFO = -4. xGESDD's existing NaN guard on ANRM also catches an infinity; without that, an infinity in A reaches xBDSDC as a NaN and would come back as INFO = -5, which in xGESDD's argument list names LDA. xLALSD and xBDSDC, which returned INFO = 1 at their scaling sites in the previous revision, now test D and then E with xLANGE right after the N = 0 quick return and return -5/-6 and -4/-5. The test comes before the lower-to-upper rotation, which mixes E into D, and covers every path, including the xLASDQ paths of xBDSDC. As in xGESDD, none of these returns calls XERBLA: the caller gets control back. The error-exit tests check every new return and that XERBLA is not called: xGELSD with a NaN and an infinity and xLALSD with a bad D and E in xERRLS, xBDSDC with a bad D and E in xERRBD, and xGESDD with a NaN and an infinity in xERRED, which joins the NAG -Onopropagate list. On master every new case fails except xGESDD with a NaN (Reference-LAPACK#469). A sweep of 22380 cases (NaN, +Inf and -Inf at every position of A, or of D and E; all precisions, UPLO, JOBZ and COMPQ values, sizes on both sides of the divide and conquer threshold) returns the expected INFO everywhere without reaching XERBLA, and the outputs for finite input are bit-identical to master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rmlarsen
added a commit
to rmlarsen/lapack
that referenced
this pull request
Nov 8, 2026
…finity in A Following review: xGEEV has returned INFO = -4 for a NaN in A since Reference-LAPACK#1136, but it called XERBLA first, and the reference XERBLA stops the program. Return without calling XERBLA, as xGESDD and xGELSD do, so that the caller gets control back. Test an infinity as well. An infinity in A passed the NaN test, was scaled by zero in xGEEV's own scaling, which leaves a NaN in its place and zeros elsewhere, and came back as INFO = 0 with every eigenvalue a NaN. Since an infinite ANRM also exceeds BIGNUM, the test now comes right after xLANGE, before the scaling branches, in the same form as in xGELSD and xGESDD. xERRED checks both cases, and that XERBLA is not called. With the parent's xGEEV the NaN case calls XERBLA and the infinity case returns INFO = 0, in all precisions. Also following review, xERRLS records what the least-squares drivers do with a NaN in B, which none of them checks: for each of xGELS, xGELST, xGETSLS, xGELSS, xGELSY and xGELSD, a NaN in one column of B gives INFO = 0, the solution for the other column, and a NaN in the solution for its own, without calling XERBLA. These cases pass on the parent as well; they pin down the current behavior. An infinity in B is not tested: every driver scales B by zero when its norm is infinite and by infinity when it undoes the scaling, so the whole solution comes back NaN, and whether to change that is left open. The full LAPACK test suite passes, with and without the _64 API. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 tasks done
rmlarsen
added a commit
to rmlarsen/lapack
that referenced
this pull request
Nov 9, 2026
…tive INFO xBDSVDMR3 rejects a NaN or an infinity in D or E before any work and returns INFO = N+1 without calling XERBLA. xGESVDMR3 passes that on as INFO = MIN(M,N)+1 when A contains one, since a NaN reaches the bidiagonal unscaled and an infinity is scaled by zero into a NaN; when singular vectors are requested, the xORMBR calls that follow overwrite it on three of the four paths (Reference-LAPACK#1482), and the call returns INFO = 0 with NS = 0. Follow instead the rule that Reference-LAPACK#1382 applies to xGEEV, xGESDD, xGELSD and xBDSDC, extending the NaN check that Reference-LAPACK#1136 added to xGEEV: when the input contains a NaN or an infinity, return INFO = -(position of the array), without calling XERBLA, so that the caller gets control back. xBDSVDMR3 now tests D and then E, in separate loops so that the two can be told apart, and returns -5 or -6. xGESVDMR3 tests ANRM right after xLANGE, before the scaling, and returns -6, with the test that Reference-LAPACK#1382 uses. A finite A, scaled into [SMLNUM, BIGNUM], gives a finite bidiagonal, so xBDSVDMR3's test no longer fires from xGESVDMR3. For a complex A, xLANGE takes the absolute value of each entry, so an entry whose real and imaginary parts are finite but whose absolute value overflows also returns -6: the largest singular value of A would overflow too, and the parent returned INFO = 0 with NaN singular values. INFO = N+2 and the fallback's INFO stay positive: they report a failed computation, not bad input. The INFO descriptions of both routines document the change, and the one of xGESVDMR3 drops a line, inherited from xGESVDX, about an INFO = N*2+1 that xGESVDMR3 never returns. LAPACKE_?bdsvdmr3 already returns -6 / -7 for a NaN in D / E from its own NaN check, which is the new Fortran -5 / -6 after LAPACKE's shift for MATRIX_LAYOUT. The NaN check of LAPACKE_?gesvdmr3 returned -6 for A, which is its seventh argument, so a NaN would have come back as -6 and an infinity as -7; it now returns -7. LAPACKE_?gesvdx, from which it was copied, has the same -6, but it is released and is left alone. Neither routine is in a release yet, so no released interface changes. xERRBD checks xBDSVDMR3 with an infinity in D (-5) and a NaN in E (-6), and xERRED checks xGESVDMR3 with a NaN and with an infinity in A (-6), each also failing if XERBLA is called. On the parent, the xBDSVDMR3 cases return 3 (N+1) and the xGESVDMR3 cases 2 (MIN(M,N)+1). Both routines check their workspace before the input, so the work arrays of xERRBD and xERRED grow to the minimum sizes for these small problems, and xERRED joins the NAG -Onopropagate list that keeps the compiler from folding SQRT( -ONE ) and ONE / ZERO. The full test suite passes, with and without the _64 API. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rmlarsen
added a commit
to rmlarsen/lapack
that referenced
this pull request
Nov 14, 2026
…tive INFO xBDSVDMR3 rejects a NaN or an infinity in D or E before any work and returns INFO = N+1 without calling XERBLA. xGESVDMR3 passes that on as INFO = MIN(M,N)+1 when A contains one, since a NaN reaches the bidiagonal unscaled and an infinity is scaled by zero into a NaN; when singular vectors are requested, the xORMBR calls that follow overwrite it on three of the four paths (Reference-LAPACK#1482), and the call returns INFO = 0 with NS = 0. Follow instead the rule that Reference-LAPACK#1382 applies to xGEEV, xGESDD, xGELSD and xBDSDC, extending the NaN check that Reference-LAPACK#1136 added to xGEEV: when the input contains a NaN or an infinity, return INFO = -(position of the array), without calling XERBLA, so that the caller gets control back. xBDSVDMR3 now tests D and then E, in separate loops so that the two can be told apart, and returns -5 or -6. xGESVDMR3 tests ANRM right after xLANGE, before the scaling, and returns -6, with the test that bidiagonal, so xBDSVDMR3's test no longer fires from xGESVDMR3. For a complex A, xLANGE takes the absolute value of each entry, so an entry whose real and imaginary parts are finite but whose absolute value overflows also returns -6: the largest singular value of A would overflow too, and the parent returned INFO = 0 with NaN singular values. INFO = N+2 and the fallback's INFO stay positive: they report a failed computation, not bad input. The INFO descriptions of both routines document the change, and the one of xGESVDMR3 drops a line, inherited from xGESVDX, about an INFO = N*2+1 that xGESVDMR3 never returns. LAPACKE_?bdsvdmr3 already returns -6 / -7 for a NaN in D / E from its own NaN check, which is the new Fortran -5 / -6 after LAPACKE's shift for MATRIX_LAYOUT. The NaN check of LAPACKE_?gesvdmr3 returned -6 for A, which is its seventh argument, so a NaN would have come back as -6 and an infinity as -7; it now returns -7. LAPACKE_?gesvdx, from which it was copied, has the same -6, but it is released and is left alone. Neither routine is in a release yet, so no released interface changes. xERRBD checks xBDSVDMR3 with an infinity in D (-5) and a NaN in E (-6), and xERRED checks xGESVDMR3 with a NaN and with an infinity in A (-6), each also failing if XERBLA is called. On the parent, the xBDSVDMR3 cases return 3 (N+1) and the xGESVDMR3 cases 2 (MIN(M,N)+1). Both routines check their workspace before the input, so the work arrays of xERRBD and xERRED grow to the minimum sizes for these small problems, and xERRED joins the NAG -Onopropagate list that keeps the compiler from folding SQRT( -ONE ) and ONE / ZERO. The full test suite passes, with and without the _64 API. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds a NaN check on the entries of the input matrix A in GEEV,
GEEV would now return error
INFO = -4if there are NaNs in matrix A in input.NaNs in input are detected with LANGE. Since LANGE is called for scaling anyway, there is no extra cost.
This follows @angsch's suggestion in issue #1128. This uses
DISNANinstead ofDISFINITE(as initially suggested). I am not opposed to create aDISFINITEfunction and use it, but I think it needs more decisions and consensus.See as well PR#471 for a "similar" behavior.