LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

`eigen` returns `ComplexF64` eigenvalues for a Hermitian matrix

Open yakovbraver opened this issue 2 years ago • 6 comments

Consider calling eigen for a ComplexF64 matrix which happens to be real-diagonal:

julia> D = ComplexF64[1 0; 0 2];
julia> eigen(D)
Eigen{ComplexF64, ComplexF64, Matrix{ComplexF64}, Vector{ComplexF64}}
values:
2-element Vector{ComplexF64}:
 1.0 + 0.0im
 2.0 + 0.0im
vectors:
2×2 Matrix{ComplexF64}:
 1.0+0.0im  0.0+0.0im
 0.0+0.0im  1.0+0.0im

The eigenvalues are returned in a Vector{ComplexF64} while I would expect a Vector{Float64}, as is the case for any Hermitian matrix:

julia> M = ComplexF64[1 1; 1 2];
julia> eigen(M)
Eigen{ComplexF64, Float64, Matrix{ComplexF64}, Vector{Float64}}
values:
2-element Vector{Float64}:
 0.38196601125010515
 2.618033988749895
vectors:
2×2 Matrix{ComplexF64}:
 -0.850651+0.0im  0.525731+0.0im
  0.525731+0.0im  0.850651+0.0im

Moreover, eigvals does return a Vector{Float64} for the above diagonal matrix D:

julia> eigvals(D)
2-element Vector{Float64}:
 1.0
 2.0

Seems inconsistent?

versioninfo
Julia Version 1.8.3
Commit 0434deb161 (2022-11-14 20:14 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 8

yakovbraver avatar Dec 05 '22 20:12 yakovbraver