Skip to content

Commit

Permalink
fix equality of eigen factorizations (JuliaLang#41132)
Browse files Browse the repository at this point in the history
At least the newly added field `rcondv` may contain `undef` values, so
these can cause the same eigen factorizations not to compare equal. Not
100% sure whether the other fields should be ignored as well, but since
we didn't have them before, it seems at least consistent to ignore them
here.

fixes JuliaDiff/ChainRules.jl#422
  • Loading branch information
simeonschaub authored Jun 14, 2021
1 parent 876da30 commit bc3ce48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/src/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ function show(io::IO, mime::MIME{Symbol("text/plain")}, F::Union{Eigen,Generaliz
nothing
end

function Base.hash(F::Eigen, h::UInt)
return hash(F.values, hash(F.vectors, hash(Eigen, h)))
end
function Base.:(==)(A::Eigen, B::Eigen)
return A.values == B.values && A.vectors == B.vectors
end
function Base.isequal(A::Eigen, B::Eigen)
return isequal(A.values, B.values) && isequal(A.vectors, B.vectors)
end

# Conversion methods

## Can we determine the source/result is Real? This is not stored in the type Eigen
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,11 @@ end
@test eigmax(A') == eigmax(copy(A'))
end

@testset "equality of eigen factorizations" begin
A = randn(3, 3)
@test eigen(A) == eigen(A)
@test hash(eigen(A)) == hash(eigen(A))
@test isequal(eigen(A), eigen(A))
end

end # module TestEigen

0 comments on commit bc3ce48

Please sign in to comment.