Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix equality of eigen factorizations #41132

Merged
merged 7 commits into from
Jun 14, 2021
Merged

fix equality of eigen factorizations #41132

merged 7 commits into from
Jun 14, 2021

Conversation

simeonschaub
Copy link
Member

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

@simeonschaub simeonschaub added regression Regression in behavior compared to a previous version linear algebra Linear algebra labels Jun 8, 2021
@DilumAluthge DilumAluthge requested a review from andreasnoack June 8, 2021 16:07
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
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to overload hash and isequal too, currently defined here:

julia> methods(hash, (Factorization, UInt))
# 1 method for generic function "hash":

Base.hash(F::Factorization, h::UInt) = mapreduce(f -> hash(getfield(F, f)), hash, 1:nfields(F); init=h)
Base.:(==)( F::T, G::T) where {T<:Factorization} = all(f -> getfield(F, f) == getfield(G, f), 1:nfields(F))
Base.isequal(F::T, G::T) where {T<:Factorization} = all(f -> isequal(getfield(F, f), getfield(G, f)), 1:nfields(F))::Bool

@simeonschaub
Copy link
Member Author

Oh, good point!

@@ -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, h))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this hash the type of the factorization as well? I kept it consistent with the previous behavior, but perhaps that should be changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this now to include Eigen in the hash.

@simeonschaub simeonschaub reopened this Jun 9, 2021
@simeonschaub
Copy link
Member Author

Could I get a review for this? Would be nice to fix this, since it currently causes test failures with ChainRules.

@simeonschaub simeonschaub merged commit bc3ce48 into master Jun 14, 2021
@simeonschaub simeonschaub deleted the sds/fix_eigen_eq branch June 14, 2021 16:05
@simeonschaub simeonschaub added the equality Issues relating to equality relations: ==, ===, isequal label Jun 16, 2021
KristofferC pushed a commit that referenced this pull request Jun 17, 2021
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

(cherry picked from commit bc3ce48)
@KristofferC KristofferC mentioned this pull request Jun 17, 2021
20 tasks
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
equality Issues relating to equality relations: ==, ===, isequal linear algebra Linear algebra regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eigen tests fail on nightly
3 participants