Skip to content

Commit 4e8a343

Browse files
committed
First version of complex eigenvalue solver
1 parent 9d967cc commit 4e8a343

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/eigenGeneral.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function wilkinson(Hmm, t, d)
7272
end
7373

7474
# We currently absorb extra unsupported keywords in kwargs. These could e.g. be scale and permute. Do we want to check that these are false?
75-
function _schur!(H::HessenbergFactorization{T}; tol = eps(T), debug = false, shiftmethod = :Francis, maxiter = 100*size(H, 1), kwargs...) where T<:Real
75+
function _schur!(H::HessenbergFactorization{T}; tol = eps(real(T)), debug = false, shiftmethod = :Francis, maxiter = 100*size(H, 1), kwargs...) where T
7676
n = size(H, 1)
7777
istart = 1
7878
iend = n
@@ -119,7 +119,7 @@ function _schur!(H::HessenbergFactorization{T}; tol = eps(T), debug = false, shi
119119
Hm1m1 = HH[iend - 1, iend - 1]
120120
d = Hm1m1*Hmm - HH[iend, iend - 1]*HH[iend - 1, iend]
121121
t = Hm1m1 + Hmm
122-
t = iszero(t) ? eps(one(t)) : t # introduce a small pertubation for zero shifts
122+
t = iszero(t) ? eps(real(one(t))) : t # introduce a small pertubation for zero shifts
123123
debug && @printf("block start is: %6d, block end is: %6d, d: %10.3e, t: %10.3e\n", istart, iend, d, t)
124124

125125
if shiftmethod == :Francis
@@ -131,7 +131,7 @@ function _schur!(H::HessenbergFactorization{T}; tol = eps(T), debug = false, shi
131131
debug && @printf("Wilkinson-like shift! Subdiagonal is: %10.3e, last subdiagonal is: %10.3e\n", HH[iend, iend - 1], HH[iend - 1, iend - 2])
132132
_d = t*t - 4d
133133

134-
if _d >= 0
134+
if isreal(_d) && _d >= 0
135135
# real eigenvalues
136136
a = t/2
137137
b = sqrt(_d)/2
@@ -247,10 +247,10 @@ LinearAlgebra.eigvals!(A::StridedMatrix; kwargs...) = _eigvals!(A; kwa
247247
LinearAlgebra.eigvals!(H::HessenbergMatrix; kwargs...) = _eigvals!(H, kwargs...)
248248
LinearAlgebra.eigvals!(H::HessenbergFactorization; kwargs...) = _eigvals!(H, kwargs...)
249249

250-
function _eigvals!(S::Schur{T}; tol = eps(T)) where T
250+
function _eigvals!(S::Schur{T}; tol = eps(real(T))) where T
251251
HH = S.data
252252
n = size(HH, 1)
253-
vals = Vector{Complex{T}}(undef, n)
253+
vals = Vector{complex(T)}(undef, n)
254254
i = 1
255255
while i < n
256256
Hii = HH[i, i]

test/eigengeneral.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ using Test, GenericLinearAlgebra, LinearAlgebra
22

33
@testset "The General eigenvalue problem" begin
44

5-
@testset "General eigen problem with n=$n" for n in (10, 100, 200)
6-
A = randn(n,n)
5+
cplxord = t -> (real(t), imag(t))
6+
7+
@testset "General eigen problem with n=$n and element type=$T" for
8+
n in (10, 23, 100),
9+
T in (Float64, Complex{Float64})
10+
11+
A = randn(T, n, n)
712
vGLA = GenericLinearAlgebra._eigvals!(copy(A))
813
vLAPACK = eigvals(A)
914
vBig = eigvals(big.(A)) # not defined in LinearAlgebra so will dispatch to the version in GenericLinearAlgebra
10-
@test sort(real(vGLA)) sort(real(vLAPACK))
11-
@test sort(imag(vGLA)) sort(imag(vLAPACK))
12-
@test sort(real(vGLA)) sort(real(map(Complex{Float64}, vBig)))
13-
@test sort(imag(vGLA)) sort(imag(map(Complex{Float64}, vBig)))
15+
@test sort(vGLA, by = cplxord) sort(vLAPACK, by = cplxord)
16+
@test sort(vGLA, by = cplxord) sort(complex(eltype(A)).(vBig), by = cplxord)
1417
end
1518

1619
@testset "make sure that solver doesn't hang" begin

0 commit comments

Comments
 (0)