Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert #495 #503

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.11.0"
version = "1.11.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
17 changes: 0 additions & 17 deletions src/tangent_types/tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ struct Tangent{P,T} <: AbstractTangent
# Note: If T is a Tuple/Dict, then P is also a Tuple/Dict
# (but potentially a different one, as it doesn't contain differentials)
backing::T

function Tangent{P,T}(backing) where {P,T}
if P <: Tuple
T <: Tuple || _backing_error(P, T, Tuple)
elseif P <: AbstractDict
T <: AbstractDict || _backing_error(P, T, AbstractDict)
elseif P === Any # can be anything
else # Any other struct (including NamedTuple)
T <: NamedTuple || _backing_error(P, T, NamedTuple)
end
return new(backing)
end
end

function Tangent{P}(; kwargs...) where {P}
Expand All @@ -57,11 +45,6 @@ function Tangent{P}(d::Dict) where {P<:Dict}
return Tangent{P,typeof(d)}(d)
end

function _backing_error(P, G, E)
msg = "Tangent for the primal $P should be backed by a $E type, not by $G."
return throw(ArgumentError(msg))
end

function Base.:(==)(a::Tangent{P,T}, b::Tangent{P,T}) where {P,T}
return backing(a) == backing(b)
end
Expand Down
22 changes: 1 addition & 21 deletions test/tangent_types/tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ end
@test typeof(Tangent{Tuple{}}()) == Tangent{Tuple{},Tuple{}}
end

@testset "constructor" begin
t = (1.0, 2.0)
nt = (x=1, y=2.0)
d = Dict(:x => 1.0, :y => 2.0)
vals = [1, 2]

@test_throws ArgumentError Tangent{typeof(t),typeof(nt)}(nt)
@test_throws ArgumentError Tangent{typeof(t),typeof(d)}(d)

@test_throws ArgumentError Tangent{typeof(d),typeof(nt)}(nt)
@test_throws ArgumentError Tangent{typeof(d),typeof(t)}(t)

@test_throws ArgumentError Tangent{typeof(nt),typeof(vals)}(vals)
@test_throws ArgumentError Tangent{typeof(nt),typeof(d)}(d)
@test_throws ArgumentError Tangent{typeof(nt),typeof(t)}(t)

@test_throws ArgumentError Tangent{Foo,typeof(d)}(d)
@test_throws ArgumentError Tangent{Foo,typeof(t)}(t)
end

@testset "==" begin
@test Tangent{Foo}(; x=0.1, y=2.5) == Tangent{Foo}(; x=0.1, y=2.5)
@test Tangent{Foo}(; x=0.1, y=2.5) == Tangent{Foo}(; y=2.5, x=0.1)
Expand Down Expand Up @@ -134,7 +114,7 @@ end
@test_throws MethodError reverse(Tangent{Foo}(; x=1.0, y=2.0))

d = Dict(:x => 1, :y => 2.0)
cdict = Tangent{typeof(d),typeof(d)}(d)
cdict = Tangent{Foo,typeof(d)}(d)
@test_throws MethodError reverse(Tangent{Foo}())
end

Expand Down