Skip to content
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

LinearAlgebra: specialize is{hermitian,symmetric} for {Sym,}Tridiagonal #41037

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

anaveragehuman
Copy link
Contributor

No description provided.

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some simplifications.

Comment on lines 173 to 174
ishermitian(S::SymTridiagonal{<:Real}) = true
ishermitian(S::SymTridiagonal{<:Complex}) = all(x -> imag(x) == 0, S.dv) && all(x -> imag(x) == 0, S.ev)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ishermitian(S::SymTridiagonal{<:Real}) = true
ishermitian(S::SymTridiagonal{<:Complex}) = all(x -> imag(x) == 0, S.dv) && all(x -> imag(x) == 0, S.ev)
ishermitian(S::SymTridiagonal) = isreal(S.dv) && isreal(S.ev)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearer, but slightly slower (by ~50ns) on my machine with S = SymTridiagonal(rand(100) .+ 0im, rand(100) .+ 0im).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what isreal is good for, and we use it even internally in LinearAlgebra for that purpose.

stdlib/LinearAlgebra/src/tridiag.jl Outdated Show resolved Hide resolved
stdlib/LinearAlgebra/test/tridiag.jl Outdated Show resolved Hide resolved
@dkarrasch dkarrasch merged commit bfa4d38 into JuliaLang:master Jun 2, 2021
@anaveragehuman anaveragehuman deleted the sym branch June 4, 2021 13:56
anaveragehuman added a commit to anaveragehuman/julia that referenced this pull request Jun 4, 2021
…nal)

SymTridiagonal allows `dv` and `ev` to have the same length, in which
case the last element of `ev` isn't part of the matrix. Thus it doesn't
matter, and should be ignored when checking if `ev` is real.

Thanks to @sostock for pointing this out in
JuliaLang#41037 (comment)
shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants