Skip to content

Commit

Permalink
inv of Symmetric and Hermitian matrices, with more eltypes than BlasF…
Browse files Browse the repository at this point in the history
…loats (JuliaLang#22882)
  • Loading branch information
fredrikekre authored and tkelman committed Aug 4, 2017
1 parent 1d7e8b2 commit 09f059a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions base/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ function _inv(A::HermOrSym)
end
B
end
inv(A::Hermitian{T,S}) where {T<:BlasFloat,S<:StridedMatrix} = Hermitian{T,S}(_inv(A), A.uplo)
inv(A::Symmetric{T,S}) where {T<:BlasFloat,S<:StridedMatrix} = Symmetric{T,S}(_inv(A), A.uplo)
inv(A::Hermitian{<:Any,<:StridedMatrix}) = Hermitian(_inv(A), Symbol(A.uplo))
inv(A::Symmetric{<:Any,<:StridedMatrix}) = Symmetric(_inv(A), Symbol(A.uplo))

eigfact!(A::RealHermSymComplexHerm{<:BlasReal,<:StridedMatrix}) = Eigen(LAPACK.syevr!('V', 'A', A.uplo, A.data, 0.0, 0.0, 0, 0, -1.0)...)

Expand Down
24 changes: 11 additions & 13 deletions test/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ end
end
end

@testset "inversion" begin
for uplo in (:U, :L)
@test inv(Symmetric(asym, uplo))::Symmetric inv(asym)
@test inv(Hermitian(aherm, uplo))::Hermitian inv(aherm)
@test inv(Symmetric(a, uplo))::Symmetric inv(Matrix(Symmetric(a, uplo)))
if eltya <: Real
@test inv(Hermitian(a, uplo))::Hermitian inv(Matrix(Hermitian(a, uplo)))
end
end
end

# Revisit when implemented in julia
if eltya != BigFloat
@testset "cond" begin
Expand All @@ -185,19 +196,6 @@ end
@test cond(Hermitian(aherm)) cond(aherm)
end

@testset "inversion" begin
@test inv(Symmetric(asym)) inv(asym)
@test inv(Hermitian(aherm)) inv(aherm)
for uplo in (:U, :L)
@test inv(Symmetric(asym, uplo)) inv(full(Symmetric(asym, uplo)))
@test inv(Hermitian(aherm, uplo)) inv(full(Hermitian(aherm, uplo)))
@test inv(Symmetric(a, uplo)) inv(full(Symmetric(a, uplo)))
if eltya <: Real
@test inv(Hermitian(a, uplo)) inv(full(Hermitian(a, uplo)))
end
end
end

@testset "symmetric eigendecomposition" begin
if eltya <: Real # the eigenvalues are only real and ordered for Hermitian matrices
d, v = eig(asym)
Expand Down

0 comments on commit 09f059a

Please sign in to comment.