-
-
Notifications
You must be signed in to change notification settings - Fork 31
Add issymmetrictype
and ishermitiantype
#1436
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1436 +/- ##
==========================================
- Coverage 93.89% 93.85% -0.04%
==========================================
Files 34 34
Lines 15920 15927 +7
==========================================
+ Hits 14948 14949 +1
- Misses 972 978 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a951fec
to
efc43b4
Compare
issymmetrictype(::Type) = false | ||
issymmetrictype(::Type{<:Union{Symmetric,Hermitian{<:Real}}}) = true | ||
issymmetrictype(::Type{<:Real}) = true | ||
issymmetrictype(::Type{<:AbstractFloat}) = false |
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.
Shouldn't it be
issymmetrictype(::Type{<:Number}) = true
?
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.
The exception is NaN
, which isn't equal to itself. I didn't want to make this more generic in case the number types contain NaN
as a field.
ishermitiantype(::Type) = false | ||
ishermitiantype(::Type{<:Union{Symmetric{<:Real},Hermitian}}) = true | ||
ishermitiantype(::Type{<:Real}) = true | ||
ishermitiantype(::Type{<:AbstractFloat}) = false |
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 don't understand this AbstractFloat
rule?
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.
This is to stay consistent with the current behavior
julia> issymmetric(NaN)
false
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.
That seems highly questionable to me, as opposed to issymmetric(::Number) = true
and ishermitian(x::Number) = isreal(x)
.
e.g. we have have a type-based issymmetric
test for floating-point Symmetric
matrices, even though they can also have NaN
values.
julia> A = Symmetric(fill(NaN, 3,3))
3×3 Symmetric{Float64, Matrix{Float64}}:
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
julia> A == A'
false
julia> issymmetric(A)
true
Add functions that determine if all instances of a type
T
satisfyissymmetric
/ishermitian
without having to check the values. In other words, the symmetry is known at compile time from the type.The main use case for this would be if we wish to have
Symmetric
/Hermitian
broadcasting in the future, where we would want to generate the destination by checking if the arguments are all symmetric.