Skip to content

Commit

Permalink
Merge pull request #245 from JuliaDiff/ox/thunktangenteq
Browse files Browse the repository at this point in the history
Remove test_approx ambig between Thunk and Tangent
  • Loading branch information
ChrisRackauckas authored Mar 21, 2022
2 parents 05caea9 + 126d2b7 commit 5f523e9
Show file tree
Hide file tree
Showing 3 changed files with 20 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 = "ChainRulesTestUtils"
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
version = "1.6.0"
version = "1.7.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
4 changes: 4 additions & 0 deletions src/check_result.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ function test_approx(actual::Tangent{P,T}, expected, msg=""; kwargs...) where {T
end
test_approx(x, y::Tangent, msg=""; kwargs...) = test_approx(y, x, msg; kwargs...)

function test_approx(actual::Tangent, expected::AbstractThunk, msg=""; kwargs...)
return test_approx(actual, unthunk(expected), msg; kwargs...)
end

# This catches comparisons of Tangents and Tuples/NamedTuple
# and gives an error message complaining about that. the `@test` will definitely fail
const LegacyZygoteCompTypes = Union{Tuple,NamedTuple}
Expand Down
15 changes: 15 additions & 0 deletions test/check_result.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ end
FakeNaturalDiffWithIsApprox(1.4),
Tangent{FakeNaturalDiffWithIsApprox}(; x=1.4),
)

# ambig with CRC after:
# https://github.com/JuliaDiff/ChainRulesCore.jl/pull/524#issuecomment-1074037647
test_approx(
Tangent{Tuple{Float64,Float64}}(1.0, 2.0),
@thunk(Tangent{Tuple{Float64,Float64}}(1.0, 2.0)),
)
end
@testset "negative case" begin
@test fails(() -> test_approx(1.0, 2.0))
Expand All @@ -90,6 +97,14 @@ end
@test fails(() -> test_approx(@thunk(10 * [[1.0], [2.0]]), [[1.0], [2.0]]))

@test fails(() -> test_approx(@not_implemented("a"), @not_implemented("b")))

# should fail, not ambig error
@test fails() do
test_approx(
Tangent{Tuple{Float64,Float64}}(1.0, 2.0),
@thunk(Tangent{Tuple{Float64,Float64}}(2.0, 2.0)),
)
end
end
@testset "type negative" begin
@test fails() do # these have different primals so should not be equal
Expand Down

2 comments on commit 5f523e9

@mcabbott
Copy link
Member

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/57054

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 v1.7.0 -m "<description of version>" 5f523e963c0d86018074beadf9019c2147975c46
git push origin v1.7.0

Please sign in to comment.