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

Implement Base.:(==) for thunks #367

Merged
merged 2 commits into from
Jun 9, 2021
Merged

Implement Base.:(==) for thunks #367

merged 2 commits into from
Jun 9, 2021

Conversation

mzgubic
Copy link
Member

@mzgubic mzgubic commented Jun 9, 2021

Needed for defining to_vec for @thunks, which is needed for testing all kinds of differentials

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

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?

Copy link
Member

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)
Copy link
Member

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

@mzgubic mzgubic merged commit 7d667c5 into master Jun 9, 2021
@mzgubic mzgubic deleted the mz/== branch June 9, 2021 16:12
@johnnychen94
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants