Skip to content

Add issymmetrictype and ishermitiantype#1436

Open
jishnub wants to merge 4 commits into
masterfrom
jishnub/issymmetric_type
Open

Add issymmetrictype and ishermitiantype#1436
jishnub wants to merge 4 commits into
masterfrom
jishnub/issymmetric_type

Conversation

@jishnub

@jishnub jishnub commented Sep 7, 2025

Copy link
Copy Markdown
Member

Add functions that determine if all instances of a type T satisfy issymmetric/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.

@codecov

codecov Bot commented Sep 8, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.85%. Comparing base (98723df) to head (a5975d8).
⚠️ Report is 54 commits behind head on master.

Files with missing lines Patch % Lines
src/symmetric.jl 11.11% 8 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jishnub jishnub force-pushed the jishnub/issymmetric_type branch from a951fec to efc43b4 Compare September 8, 2025 11:21
Comment thread src/symmetric.jl
issymmetrictype(::Type) = false
issymmetrictype(::Type{<:Union{Symmetric,Hermitian{<:Real}}}) = true
issymmetrictype(::Type{<:Real}) = true
issymmetrictype(::Type{<:AbstractFloat}) = false

Copy link
Copy Markdown
Member

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

?

@jishnub jishnub Sep 10, 2025

Copy link
Copy Markdown
Member Author

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.

Comment thread src/symmetric.jl
ishermitiantype(::Type) = false
ishermitiantype(::Type{<:Union{Symmetric{<:Real},Hermitian}}) = true
ishermitiantype(::Type{<:Real}) = true
ishermitiantype(::Type{<:AbstractFloat}) = false

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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

@stevengj stevengj Sep 11, 2025

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants