-
-
Notifications
You must be signed in to change notification settings - Fork 30
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,9 +461,34 @@ issymmetric(A::Hermitian{<:Real}) = true | |
issymmetric(A::Hermitian{<:Complex}) = isreal(A) | ||
issymmetric(A::Symmetric) = true | ||
|
||
# check if the symmetry is known from the type | ||
_issymmetric(::Union{SymSymTri, Hermitian{<:Real}}) = true | ||
_issymmetric(::Any) = false | ||
""" | ||
issymmetrictype(T::Type) | ||
|
||
Return whether every instance `x` of the type `T` satisfies `issymmetric(x) == tue`, | ||
that is, the fact that the instance is symmetric is known from its type. | ||
|
||
!!! note | ||
An instance `x::T` may still be symmetric when `issymmetrictype(T)` returns `false`. | ||
""" | ||
issymmetrictype(::Type) = false | ||
issymmetrictype(::Type{<:Union{Symmetric,Hermitian{<:Real}}}) = true | ||
issymmetrictype(::Type{<:Real}) = true | ||
issymmetrictype(::Type{<:AbstractFloat}) = false | ||
issymmetrictype(::Type{Complex{T}}) where {T} = issymmetrictype(T) | ||
|
||
""" | ||
ishermitiantype(T::Type) | ||
|
||
Return whether every instance `x` of the type `T` satisfies `ishermitian(x) == tue`, | ||
that is, the fact that the instance is hermitian is known from its type. | ||
|
||
!!! note | ||
An instance `x::T` may still be hermitian when `ishermitiantype(T)` returns `false`. | ||
""" | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. That seems highly questionable to me, as opposed to e.g. we have have a type-based 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 |
||
|
||
adjoint(A::Hermitian) = A | ||
transpose(A::Symmetric) = A | ||
|
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
?
Uh oh!
There was an error while loading. Please reload this page.
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 containNaN
as a field.