-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
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
c430b0d
to
53e8d86
Compare
There was a problem hiding this 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":
julia/stdlib/LinearAlgebra/src/factorization.jl
Lines 67 to 69 in 1910a76
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 |
Oh, good point! |
stdlib/LinearAlgebra/src/eigen.jl
Outdated
@@ -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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Could I get a review for this? Would be nice to fix this, since it currently causes test failures with ChainRules. |
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)
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
At least the newly added field
rcondv
may containundef
values, sothese 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