-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
implement equality for ComposedFunction structurally #54877
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -201,6 +201,37 @@ end | |||||||||||
|
||||||||||||
end | ||||||||||||
|
||||||||||||
@testset "ComposedFunction hash eq" begin | ||||||||||||
@test sin∘cos == sin∘cos | ||||||||||||
@test isequal(sin∘cos, sin∘cos) | ||||||||||||
@test !isequal(sin∘cos, sin∘asin) | ||||||||||||
@test ==(sin∘cos, sin∘cos) | ||||||||||||
@test !==(sin∘cos, sin∘asin) | ||||||||||||
@test hash(sin∘cos) == hash(sin∘cos) | ||||||||||||
@test hash(sin∘cos) != hash(sin∘tan) | ||||||||||||
|
||||||||||||
Base.@kwdef mutable struct F | ||||||||||||
isequal::Bool = false | ||||||||||||
eq::Bool = false | ||||||||||||
end | ||||||||||||
function Base.isequal(f1::F, f2::F) | ||||||||||||
f1.isequal | ||||||||||||
end | ||||||||||||
function Base.:(==)(f1::F, f2::F) | ||||||||||||
f1.eq | ||||||||||||
end | ||||||||||||
f2 = F() ∘ F() | ||||||||||||
@test isequal(F(isequal=true) ∘ F(isequal=true) , f2) | ||||||||||||
@test !isequal(F(isequal=true) ∘ F(isequal=false) , f2) | ||||||||||||
@test !isequal(F(isequal=false) ∘ F(isequal=true) , f2) | ||||||||||||
@test !isequal(F(isequal=false) ∘ F(isequal=false) , f2) | ||||||||||||
|
||||||||||||
@test ==(F(eq=true) ∘ F(eq=true) , f2) | ||||||||||||
@test !==(F(eq=true) ∘ F(eq=false) , f2) | ||||||||||||
@test !==(F(eq=false) ∘ F(eq=true) , f2) | ||||||||||||
@test !==(F(eq=false) ∘ F(eq=false) , f2) | ||||||||||||
end | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Not sure, but presumably we'd like to intepret There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a good point, but orthogonal to this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, right now julia> missing∘missing
missing ∘ missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think so. Right now we have the excuse that
Composition doesn't need to handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, sorry I misread some parenthesis in your test. I read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My takeaway from #54881 is ot not implement special logic for missing in composed function equality in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's possible to support |
||||||||||||
|
||||||||||||
@testset "Nested ComposedFunction's stability" begin | ||||||||||||
f(x) = (1, 1, x...) | ||||||||||||
g = (f ∘ (f ∘ f)) ∘ (f ∘ f ∘ f) | ||||||||||||
|
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.
Support
missing
and other non-Bool results of==
by not short-circuiting.