Skip to content

Commit 18a811f

Browse files
committed
correct sorting order
1 parent 8f2c309 commit 18a811f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/implementations/eig.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ end
129129

130130
# Diagonal logic
131131
# --------------
132+
eig_sortby(x::T) where {T <: Number} = T <: Complex ? (real(x), imag(X)) : x
132133
function eig_full!(A::Diagonal, DV, alg::DiagonalAlgorithm)
133134
check_input(eig_full!, A, DV, alg)
134135
D, V = DV
135136
diagA = diagview(A)
136-
I = sortperm(diagA; by = real)
137+
I = sortperm(diagA; by = eig_sortby)
137138
if D === A
138139
permute!(diagA, I)
139140
else
@@ -150,7 +151,7 @@ function eig_vals!(A::Diagonal, D::AbstractVector, alg::DiagonalAlgorithm)
150151
check_input(eig_vals!, A, D, alg)
151152
Ad = diagview(A)
152153
D === Ad || copy!(D, Ad)
153-
sort!(D; by = real)
154+
sort!(D; by = eig_sortby)
154155
return D
155156
end
156157

0 commit comments

Comments
 (0)