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 = "ChainRulesTestUtils"
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
version = "0.7.0"
version = "0.7.1"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
45 changes: 43 additions & 2 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,80 @@
# TODO remove these in version 0.7
# We are silently deprecating them as there is no alternative we are providing

function Base.isapprox(a, b::Union{AbstractZero,AbstractThunk}; kwargs...)
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return isapprox(b, a; kwargs...)
end
function Base.isapprox(d_ad::AbstractThunk, d_fd; kwargs...)
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return isapprox(extern(d_ad), d_fd; kwargs...)
end
function Base.isapprox(d_ad::NoTangent, d_fd; kwargs...)
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return error("Tried to differentiate w.r.t. a `NoTangent`")
end
# Call `all` to handle the case where `ZeroTangent` is standing in for a non-scalar zero
function Base.isapprox(d_ad::ZeroTangent, d_fd; kwargs...)
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return all(isapprox.(extern(d_ad), d_fd; kwargs...))
end

isapprox_vec(a, b; kwargs...) = isapprox(first(to_vec(a)), first(to_vec(b)); kwargs...)
Base.isapprox(a, b::Tangent; kwargs...) = isapprox(b, a; kwargs...)
function Base.isapprox(d_ad::Tangent{<:Tuple}, d_fd::Tuple; kwargs...)
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return isapprox_vec(d_ad, d_fd; kwargs...)
end
function Base.isapprox(
d_ad::Tangent{P,<:Tuple}, d_fd::Tangent{P,<:Tuple}; kwargs...
) where {P<:Tuple}
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return isapprox_vec(d_ad, d_fd; kwargs...)
end

function Base.isapprox(
d_ad::Tangent{P,<:NamedTuple{T}}, d_fd::Tangent{P,<:NamedTuple{T}}; kwargs...
) where {P,T}
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return isapprox_vec(d_ad, d_fd; kwargs...)
end

# Must be for same primal
Base.isapprox(d_ad::Tangent{P}, d_fd::Tangent{Q}; kwargs...) where {P,Q} = false
function Base.isapprox(d_ad::Tangent{P}, d_fd::Tangent{Q}; kwargs...) where {P,Q}
Base.depwarn(
"isapprox is deprecated on AbstractTangents and will be removed. " *
"Restructure testing code to use `ChainRulesTestUtils.test_approx` instead.",
:isapprox,
)
return false
end

###############################################

Expand Down