-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't throw in cholfact if matrix is not Hermitian #23315
Conversation
Make an Enum for info codes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In LAPACK, a positive info code corresponds to the index of the non-positive diagonal entry. However, we don't use that information right now so it is not critical. We could use a negative error code because they are only used in LAPACK when the input is invalid so that should never happen.
test/linalg/cholesky.jl
Outdated
@test_throws ArgumentError cholfact!(copy(A)) | ||
@test_throws ArgumentError chol(A) | ||
@test_throws ArgumentError Base.LinAlg.chol!(copy(A)) | ||
@test cholfact(A).info == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe test with !issuccess
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, that's better.
Right now the |
Right, since a negative info code will error before we exit the LAPACK module, we could use a negative code for non-hermitian. And add a |
@@ -32,6 +32,15 @@ end | |||
struct PosDefException <: Exception | |||
info::BlasInt | |||
end | |||
function Base.showerror(io::IO, ex::PosDefException) | |||
print(io, "PosDefException: matrix is not ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR: PosDefException: matrix is not Hermitian.
is maybe not the nicest though. Should we instead have a CholeskyException
that print one of
ERROR: CholeskyException: Cholesky factorization failed; matrix is not Hermitian.
ERROR: CholeskyException: Cholesky factorization failed; matrix is not positive definite.
Edit: Cholesky
probably not needed, instead:
ERROR: CholeskyException: factorization failed; matrix is not Hermitian.
ERROR: CholeskyException: factorization failed; matrix is not positive definite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think PosDef
is fine. We use the definition that requires the matrix to be Hermitian
consistently. Some users have been taught the other definition that allows for non-Hermitian matrices but I think the error message is sufficiently clear about the reason for the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, as the PR currently? Or should I drop the second commit?
0c1d8fd
to
34f9ba6
Compare
No. I think it is fine as it is. |
As discussed here and comments below.
We could perhaps dedicate an info code for non-hermitianness, like
-1
or something instead? Then we could throw a more targeted error message (similar to what we had before this PR) or throw aHermitianException
, instead ofThoughts?