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

wrapper for eigen(Matrix A) where A is hermitian by value but not type #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/eigenSelfAdjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ LinearAlgebra.eigen!(A::SymTridiagonal; tol = eps(real(eltype(A))), debug = fals
LinearAlgebra.eigen!(A::Hermitian; tol = eps(real(eltype(A))), debug = false) =
_eigen!(A, tol = tol, debug = debug)


function eigen2!(
A::SymmetricTridiagonalFactorization;
tol = eps(real(float(one(eltype(A))))),
Expand Down Expand Up @@ -709,6 +708,12 @@ function LinearAlgebra.eigen(A::Hermitian)
T = typeof(sqrt(zero(eltype(A))))
return eigen!(LinearAlgebra.copy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Matrix)
if !ishermitian(A)
throw(ArgumentError("eigen not implement for non-Hermitian matrices of generic type (e.g. Matrix{BigFloat})"))
end
return eigen(Hermitian(A))
end

# Aux (should go somewhere else at some point)
function LinearAlgebra.givensAlgorithm(f::Real, g::Real)
Expand Down
10 changes: 10 additions & 0 deletions test/eigengeneral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,13 @@ using Test, GenericLinearAlgebra, LinearAlgebra
end

end

@testset "Wrapper function for eigen(Matrix A) where A is hermitian by value but not by type" begin
# just need to verify that the wrapper function correctly calls eigen(Hermitian(A))
# so no need for multiple numeric tests
a = big(2.0);
A = [1 a; a 0] # A == A^*, but type is Matrix{BigFloat}, not Hermitian{BigFloat, Matrix{BigFloat}}
λs = [(1 - √(1+4a^2))/2 ; (1 + √(1+4a^2))/2]
vals = eigvals(A)
@test sort(vals) ≈ sort(λs) atol=1e-25
end