Skip to content

Commit 5f523e9

Browse files
Merge pull request #245 from JuliaDiff/ox/thunktangenteq
Remove test_approx ambig between Thunk and Tangent
2 parents 05caea9 + 126d2b7 commit 5f523e9

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesTestUtils"
22
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3-
version = "1.6.0"
3+
version = "1.7.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/check_result.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ function test_approx(actual::Tangent{P,T}, expected, msg=""; kwargs...) where {T
123123
end
124124
test_approx(x, y::Tangent, msg=""; kwargs...) = test_approx(y, x, msg; kwargs...)
125125

126+
function test_approx(actual::Tangent, expected::AbstractThunk, msg=""; kwargs...)
127+
return test_approx(actual, unthunk(expected), msg; kwargs...)
128+
end
129+
126130
# This catches comparisons of Tangents and Tuples/NamedTuple
127131
# and gives an error message complaining about that. the `@test` will definitely fail
128132
const LegacyZygoteCompTypes = Union{Tuple,NamedTuple}

test/check_result.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ end
7575
FakeNaturalDiffWithIsApprox(1.4),
7676
Tangent{FakeNaturalDiffWithIsApprox}(; x=1.4),
7777
)
78+
79+
# ambig with CRC after:
80+
# https://github.com/JuliaDiff/ChainRulesCore.jl/pull/524#issuecomment-1074037647
81+
test_approx(
82+
Tangent{Tuple{Float64,Float64}}(1.0, 2.0),
83+
@thunk(Tangent{Tuple{Float64,Float64}}(1.0, 2.0)),
84+
)
7885
end
7986
@testset "negative case" begin
8087
@test fails(() -> test_approx(1.0, 2.0))
@@ -90,6 +97,14 @@ end
9097
@test fails(() -> test_approx(@thunk(10 * [[1.0], [2.0]]), [[1.0], [2.0]]))
9198

9299
@test fails(() -> test_approx(@not_implemented("a"), @not_implemented("b")))
100+
101+
# should fail, not ambig error
102+
@test fails() do
103+
test_approx(
104+
Tangent{Tuple{Float64,Float64}}(1.0, 2.0),
105+
@thunk(Tangent{Tuple{Float64,Float64}}(2.0, 2.0)),
106+
)
107+
end
93108
end
94109
@testset "type negative" begin
95110
@test fails() do # these have different primals so should not be equal

0 commit comments

Comments
 (0)