Skip to content

Commit

Permalink
Use eigencopy_oftype instead of copy_oftype (#140)
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
andreasnoack authored Sep 12, 2024
1 parent 713250b commit fd56d78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/eigenSelfAdjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -633,29 +633,35 @@ eigen2(A::Hermitian, tol = eps(float(real(one(eltype(A)))))) = eigen2!(copy(A),

# First method of each type here is identical to the method defined in
# LinearAlgebra but is needed for disambiguation
const _eigencopy_oftype = if VERSION >= v"1.9"
LinearAlgebra.eigencopy_oftype
else
LinearAlgebra.copy_oftype
end

function LinearAlgebra.eigvals(A::Hermitian{<:Real})
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(LinearAlgebra.copy_oftype(A, T))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigvals(A::Hermitian{<:Complex})
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(LinearAlgebra.copy_oftype(A, T))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigvals(A::Hermitian)
T = typeof(sqrt(zero(eltype(A))))
return eigvals!(LinearAlgebra.copy_oftype(A, T))
return eigvals!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian{<:Real})
T = typeof(sqrt(zero(eltype(A))))
return eigen!(LinearAlgebra.copy_oftype(A, T))
return eigen!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian{<:Complex})
T = typeof(sqrt(zero(eltype(A))))
return eigen!(LinearAlgebra.copy_oftype(A, T))
return eigen!(_eigencopy_oftype(A, T))
end
function LinearAlgebra.eigen(A::Hermitian)
T = typeof(sqrt(zero(eltype(A))))
return eigen!(LinearAlgebra.copy_oftype(A, T))
return eigen!(_eigencopy_oftype(A, T))
end

# Aux (should go somewhere else at some point)
Expand Down
8 changes: 8 additions & 0 deletions test/eigenselfadjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
@test abs.(eigen(A).vectors) == abs.(eigen(T).vectors) == abs.(eigen(A; sortby=LinearAlgebra.eigsortby).vectors) == abs.(eigen(T; sortby=LinearAlgebra.eigsortby).vectors)
end
end

if VERSION >= v"1.9"
@testset "#139" begin
A = Hermitian(Diagonal([1.0, 2.0]))
@test eigvals(A) == diag(A)
@test eigen(A).values == diag(A)
end
end
end

0 comments on commit fd56d78

Please sign in to comment.