From bc3ce48636b700d153d2c84614aaea8cb8843d43 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Mon, 14 Jun 2021 18:05:07 +0200 Subject: [PATCH] fix equality of eigen factorizations (#41132) 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 --- stdlib/LinearAlgebra/src/eigen.jl | 10 ++++++++++ stdlib/LinearAlgebra/test/eigen.jl | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/stdlib/LinearAlgebra/src/eigen.jl b/stdlib/LinearAlgebra/src/eigen.jl index 04825be663eef..3341a2a9bc744 100644 --- a/stdlib/LinearAlgebra/src/eigen.jl +++ b/stdlib/LinearAlgebra/src/eigen.jl @@ -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 diff --git a/stdlib/LinearAlgebra/test/eigen.jl b/stdlib/LinearAlgebra/test/eigen.jl index 487c72d2e01f4..6ac0dc6852df9 100644 --- a/stdlib/LinearAlgebra/test/eigen.jl +++ b/stdlib/LinearAlgebra/test/eigen.jl @@ -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