Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "0.10.2"
version = "0.10.3"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
4 changes: 4 additions & 0 deletions src/differentials/thunks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Base.:(==)(a::AbstractThunk, b) = unthunk(a) == b
Base.:(==)(a, b::AbstractThunk) = a == unthunk(b)

"""
@thunk expr

Expand Down
6 changes: 6 additions & 0 deletions test/differentials/thunks.jl
Original file line number Diff line number Diff line change
@@ -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

@test @thunk(3.2) == 3.2
@test 3.2 == InplaceableThunk(@thunk(3.2), x -> x + 3.2)
end

@testset "show" begin
rep = repr(Thunk(rand))
@test occursin(r"Thunk\(.*rand.*\)", rep)
Expand Down