Skip to content

Commit 1f50766

Browse files
authored
Merge pull request #162 from JuliaDiff/ox/depwarnisapprox
Add deprecation warnings to isapprox
2 parents 203fce0 + a0cac6f commit 1f50766

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
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 = "0.7.0"
3+
version = "0.7.1"
44

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

src/deprecated.jl

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,80 @@
11
# TODO remove these in version 0.7
2-
# We are silently deprecating them as there is no alternative we are providing
32

43
function Base.isapprox(a, b::Union{AbstractZero,AbstractThunk}; kwargs...)
4+
Base.depwarn(
5+
"isapprox is deprecated on AbstractTangents and will be removed. " *
6+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
7+
:isapprox,
8+
)
59
return isapprox(b, a; kwargs...)
610
end
711
function Base.isapprox(d_ad::AbstractThunk, d_fd; kwargs...)
12+
Base.depwarn(
13+
"isapprox is deprecated on AbstractTangents and will be removed. " *
14+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
15+
:isapprox,
16+
)
817
return isapprox(extern(d_ad), d_fd; kwargs...)
918
end
1019
function Base.isapprox(d_ad::NoTangent, d_fd; kwargs...)
20+
Base.depwarn(
21+
"isapprox is deprecated on AbstractTangents and will be removed. " *
22+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
23+
:isapprox,
24+
)
1125
return error("Tried to differentiate w.r.t. a `NoTangent`")
1226
end
1327
# Call `all` to handle the case where `ZeroTangent` is standing in for a non-scalar zero
1428
function Base.isapprox(d_ad::ZeroTangent, d_fd; kwargs...)
29+
Base.depwarn(
30+
"isapprox is deprecated on AbstractTangents and will be removed. " *
31+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
32+
:isapprox,
33+
)
1534
return all(isapprox.(extern(d_ad), d_fd; kwargs...))
1635
end
1736

1837
isapprox_vec(a, b; kwargs...) = isapprox(first(to_vec(a)), first(to_vec(b)); kwargs...)
1938
Base.isapprox(a, b::Tangent; kwargs...) = isapprox(b, a; kwargs...)
2039
function Base.isapprox(d_ad::Tangent{<:Tuple}, d_fd::Tuple; kwargs...)
40+
Base.depwarn(
41+
"isapprox is deprecated on AbstractTangents and will be removed. " *
42+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
43+
:isapprox,
44+
)
2145
return isapprox_vec(d_ad, d_fd; kwargs...)
2246
end
2347
function Base.isapprox(
2448
d_ad::Tangent{P,<:Tuple}, d_fd::Tangent{P,<:Tuple}; kwargs...
2549
) where {P<:Tuple}
50+
Base.depwarn(
51+
"isapprox is deprecated on AbstractTangents and will be removed. " *
52+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
53+
:isapprox,
54+
)
2655
return isapprox_vec(d_ad, d_fd; kwargs...)
2756
end
2857

2958
function Base.isapprox(
3059
d_ad::Tangent{P,<:NamedTuple{T}}, d_fd::Tangent{P,<:NamedTuple{T}}; kwargs...
3160
) where {P,T}
61+
Base.depwarn(
62+
"isapprox is deprecated on AbstractTangents and will be removed. " *
63+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
64+
:isapprox,
65+
)
3266
return isapprox_vec(d_ad, d_fd; kwargs...)
3367
end
3468

3569
# Must be for same primal
36-
Base.isapprox(d_ad::Tangent{P}, d_fd::Tangent{Q}; kwargs...) where {P,Q} = false
70+
function Base.isapprox(d_ad::Tangent{P}, d_fd::Tangent{Q}; kwargs...) where {P,Q}
71+
Base.depwarn(
72+
"isapprox is deprecated on AbstractTangents and will be removed. " *
73+
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
74+
:isapprox,
75+
)
76+
return false
77+
end
3778

3879
###############################################
3980

0 commit comments

Comments
 (0)