Skip to content

Commit

Permalink
Implement Base.:(==) for thunks (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzgubic authored Jun 9, 2021
1 parent 6e2812e commit 7d667c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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)
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)
@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

2 comments on commit 7d667c5

@mzgubic
Copy link
Member Author

@mzgubic mzgubic commented on 7d667c5 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38492

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.3 -m "<description of version>" 7d667c583bd251a5841e0e4c48b6385286fc165a
git push origin v0.10.3

Please sign in to comment.