-
-
Notifications
You must be signed in to change notification settings - Fork 32
Ensure inverse of Symmetric{<:,Diagonal} returns same type #1439
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1439 +/- ##
=======================================
Coverage 93.89% 93.90%
=======================================
Files 34 34
Lines 15920 15922 +2
=======================================
+ Hits 14948 14951 +3
+ Misses 972 971 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
You do need to add a test for #1438. You probably want to preserve the type of the number in You probably want to do something similar for |
Since #1438 is not needed for this PR, it should be a separate PR. |
|
||
# Ensure doubly wrapped matrices use efficient diagonal methods and return a Symmetric/Hermitian type | ||
inv(A::Symmetric{<:Number,<:Diagonal}) = Symmetric(inv(A.data), sym_uplo(A.uplo)) | ||
inv(A::Hermitian{<:Number,<:Diagonal}) = Hermitian(inv(real(A.data)), sym_uplo(A.uplo)) |
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.
To avoid the issue of returning a real-eltype matrix for a complex-eltype argument, this should perhaps be
inv(A::Hermitian{<:Number,<:Diagonal}) = Hermitian(inv(real(A.data)), sym_uplo(A.uplo)) | |
inv(A::Hermitian{T,S}) where {T<:Number, S<:Diagonal} = Hermitian{T,S}(inv(real(A.data)), A.uplo) |
?
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 suppose that's possible, but a Hermitian Diagonal matrix is actually always a real Diagonal matrix, so we can deduce from the type alone that the inverse is always a real diagonal matrix. This also holds for quaternion and octonion valued matrices. If there is a number type where becomes a problem, then using real
might also be a problem.
Fixes #1437
Does not add a test for 1438, but let me know if I should.
Feedback is welcome!