Skip to content
Merged
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
15 changes: 9 additions & 6 deletions stdlib/LinearAlgebra/src/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function bunchkaufman!(A::StridedMatrix{<:BlasFloat}, rook::Bool = false; check:
end
end

bkcopy_oftype(A, S) = eigencopy_oftype(A, S)
bkcopy_oftype(A::Symmetric{<:Complex}, S) = Symmetric(copytrito!(similar(parent(A), S, size(A)), A.data, A.uplo), sym_uplo(A.uplo))

"""
bunchkaufman(A, rook::Bool=false; check = true) -> S::BunchKaufman

Expand Down Expand Up @@ -206,7 +209,7 @@ julia> S.L*S.D*S.L' - A[S.p, S.p]
```
"""
bunchkaufman(A::AbstractMatrix{T}, rook::Bool=false; check::Bool = true) where {T} =
bunchkaufman!(eigencopy_oftype(A, typeof(sqrt(oneunit(T)))), rook; check = check)
bunchkaufman!(bkcopy_oftype(A, typeof(sqrt(oneunit(T)))), rook; check = check)

BunchKaufman{T}(B::BunchKaufman) where {T} =
BunchKaufman(convert(Matrix{T}, B.LD), B.ipiv, B.uplo, B.symmetric, B.rook, B.info)
Expand Down Expand Up @@ -1540,7 +1543,7 @@ function bunchkaufman(A::AbstractMatrix{TS},
rook::Bool = false;
check::Bool = true
) where TS <: ClosedScalar{TR} where TR <: ClosedReal
return bunchkaufman!(eigencopy_oftype(A, TS), rook; check)
return bunchkaufman!(bkcopy_oftype(A, TS), rook; check)
end

function bunchkaufman(A::AbstractMatrix{TS},
Expand All @@ -1562,15 +1565,15 @@ function bunchkaufman(A::AbstractMatrix{TS},
# We promote input to BigInt to avoid overflow problems
if TA == Nothing
if TS <: Integer
M = Rational{BigInt}.(eigencopy_oftype(A, TS))
M = Rational{BigInt}.(bkcopy_oftype(A, TS))
else
M = Complex{Rational{BigInt}}.(eigencopy_oftype(A, TS))
M = Complex{Rational{BigInt}}.(bkcopy_oftype(A, TS))
end
else
if TS <: Integer
M = TA(Rational{BigInt}.(eigencopy_oftype(A, TS)), Symbol(A.uplo))
M = TA(Rational{BigInt}.(bkcopy_oftype(A, TS)), Symbol(A.uplo))
else
M = TA(Complex{Rational{BigInt}}.(eigencopy_oftype(A, TS)),
M = TA(Complex{Rational{BigInt}}.(bkcopy_oftype(A, TS)),
Symbol(A.uplo))
end
end
Expand Down
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/symmetriceigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Call `copytrito!` instead of `copy_similar` to only copy the matching triangular half
eigencopy_oftype(A::Hermitian, S) = Hermitian(copytrito!(similar(parent(A), S, size(A)), A.data, A.uplo), sym_uplo(A.uplo))
eigencopy_oftype(A::Symmetric, S) = Symmetric(copytrito!(similar(parent(A), S, size(A)), A.data, A.uplo), sym_uplo(A.uplo))
eigencopy_oftype(A::Symmetric{<:Complex}, S) = copyto!(similar(parent(A), S), A)

default_eigen_alg(A) = DivideAndConquer()

Expand Down
7 changes: 7 additions & 0 deletions stdlib/LinearAlgebra/test/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,11 @@ end
@test S[1,2] == S[Int8(1),UInt16(2)] == S[big(1), Int16(2)]
end

@testset "complex Symmetric" begin
D = diagm(0=>ComplexF64[1,2])
S = Symmetric(D)
H = hessenberg(S)
@test H.H == D
end

end # module TestHessenberg
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/symmetriceigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,10 @@ end
@test D.vectors ≈ D32.vectors
end

@testset "complex Symmetric" begin
S = Symmetric(rand(ComplexF64,2,2))
λ, v = eigen(S)
@test S * v ≈ v * Diagonal(λ)
end

end # module TestSymmetricEigen
Loading