JuliaLang / LinearAlgebra.jl

Julia Linear Algebra standard library
Other
13 stars 0 forks source link

Regression in tridiagonal hermitian `eigen` for `Complex{Int}` elements #1048

Closed jishnub closed 10 months ago

jishnub commented 10 months ago

The following works on v1.10, but fails on the current master (presumably after JuliaLang/julia#49546):

julia> dv, ev = fill(complex(2), 4), fill(3-4im, 3);

julia> HT = Hermitian(Tridiagonal(ev, dv, ev))
4×4 Hermitian{Complex{Int64}, Tridiagonal{Complex{Int64}, Vector{Complex{Int64}}}}:
 2+0im  3-4im    ⋅      ⋅  
 3+4im  2+0im  3-4im    ⋅  
   ⋅    3+4im  2+0im  3-4im
   ⋅      ⋅    3+4im  2+0im

julia> eigen(HT)
ERROR: InexactError: Int64(0.6)
Stacktrace:
 [1] Int64
   @ ./float.jl:963 [inlined]
 [2] convert
   @ ./number.jl:7 [inlined]
 [3] Complex
   @ ./complex.jl:14 [inlined]
 [4] Complex
   @ ./complex.jl:43 [inlined]
 [5] convert
   @ ./number.jl:7 [inlined]
 [6] setindex!
   @ ./array.jl:969 [inlined]
 [7] eigen(A::Hermitian{Complex{Int64}, Tridiagonal{Complex{Int64}, Vector{Complex{Int64}}}}; kwargs::@Kwargs{})
   @ LinearAlgebra ~/packages/julias/julia-latest/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetriceigen.jl:315
 [8] eigen(A::Hermitian{Complex{Int64}, Tridiagonal{Complex{Int64}, Vector{Complex{Int64}}}})
   @ LinearAlgebra ~/packages/julias/julia-latest/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetriceigen.jl:299
 [9] top-level scope
   @ REPL[28]:1

julia> versioninfo()
Julia Version 1.11.0-DEV.1229
Commit 8dc2c30f166 (2024-01-08 03:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  WORD_SIZE: 64
  LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  LD_LIBRARY_PATH = :/usr/lib/x86_64-linux-gnu/gtk-3.0/modules
  JULIA_EDITOR = subl

whereas on v1.10:

julia> eigen(HT)
Eigen{ComplexF64, Float64, Matrix{ComplexF64}, Vector{Float64}}
values:
4-element Vector{Float64}:
 -6.090169943749451
 -1.0901699437494692
  5.0901699437494825
 10.090169943749475
vectors:
4×4 Matrix{ComplexF64}:
  0.347956+0.130855im  -0.563005-0.211728im  0.563005+0.211728im   0.347956+0.130855im
  -0.16842-0.577441im   0.104089+0.356878im  0.104089+0.356878im    0.16842+0.577441im
 -0.360901+0.481201im  -0.223049+0.297398im  0.223049-0.297398im  -0.360901+0.481201im
  0.371748-0.0im        0.601501+0.0im       0.601501+0.0im       -0.371748-0.0im

The element types should perhaps be widened to float.

CC: @MasonProtter

The test failure was seen in a CI run for ToeplitzMatrices.jl, but oddly, the test appears to pass on macOS.

giordano commented 10 months ago

but oddly, the test appears to pass on macOS.

Quoting from https://github.com/JuliaLinearAlgebra/ToeplitzMatrices.jl/actions/runs/7443266043/job/20247904856#step:3:11

Commit 103e50a764e (2024-01-06 01:37 UTC)

and that commit is before ecb668bdf111d8b2be28296eed90cee76074635d, the merge commit of JuliaLang/julia#49546.

jishnub commented 10 months ago

Wow that makes sense, thanks for looking into this!

MasonProtter commented 10 months ago

Ah crap, good catch sorry about that @jishnub