-
Notifications
You must be signed in to change notification settings - Fork 63
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
Implement Base.:(==)
for thunks
#367
Conversation
@@ -1,6 +1,12 @@ | |||
@testset "Thunk" begin | |||
@test @thunk(3) isa Thunk | |||
|
|||
@testset "==" begin | |||
@test @thunk(3.2) == InplaceableThunk(@thunk(3.2), x -> x + 3.2) |
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.
Do we want to have this? Or should we separate between Thunks and InplaceableThnks?
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.
(@thunk(3.2))
== 3.2
Inplacable(@thunk(3.2), _->error("this shouldn;t be hit"))
== 3.2
Thus by transitivity thye must be equal to each other
@@ -13,6 +13,10 @@ end | |||
return element, (val, new_state) | |||
end | |||
|
|||
Base.:(==)(a::AbstractThunk, b::AbstractThunk) = unthunk(a) == unthunk(b) |
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.
There are some special case we might be able to optimize the positive cases like a===b
to avoid unthunking.
idk if worth it though
Looks like it adds some new ambiguities and makes Aqua CI unhappy now: Ambiguity #1
==(a::ChainRulesCore.AbstractThunk, b) in ChainRulesCore at /Users/jc/.julia/packages/ChainRulesCore/EgLlm/src/differentials/thunks.jl:26
==(::Any, ::Missing) in Base at missing.jl:76
Ambiguity #2
==(a, b::ChainRulesCore.AbstractThunk) in ChainRulesCore at /Users/jc/.julia/packages/ChainRulesCore/EgLlm/src/differentials/thunks.jl:27
==(::Missing, ::Any) in Base at missing.jl:75
Ambiguity #3
==(a::ChainRulesCore.AbstractThunk, b) in ChainRulesCore at /Users/jc/.julia/packages/ChainRulesCore/EgLlm/src/differentials/thunks.jl:26
==(w, v::WeakRef) in Base at gcutils.jl:5
Ambiguity #4
==(a, b::ChainRulesCore.AbstractThunk) in ChainRulesCore at /Users/jc/.julia/packages/ChainRulesCore/EgLlm/src/differentials/thunks.jl:27
==(w::WeakRef, v) in Base at gcutils.jl:4 |
Needed for defining
to_vec
for@thunk
s, which is needed for testing all kinds of differentials