Skip to content

Commit 9153237

Browse files
author
Miha Zgubic
committed
take out _backing_error function
1 parent e40c501 commit 9153237

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/tangent_types/tangent.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,12 @@ struct Tangent{P,T} <: AbstractTangent
2727
backing::T
2828

2929
function Tangent{P,T}(backing) where {P,T}
30-
function backing_error(P, G, E)
31-
msg = "Tangent for the primal $P should be backed by a $E type, not by $G."
32-
return throw(ArgumentError(msg))
33-
end
34-
3530
if P <: Tuple
36-
T <: Tuple || backing_error(P, T, Tuple)
31+
T <: Tuple || _backing_error(P, T, Tuple)
3732
elseif P <: AbstractDict
38-
T <: AbstractDict || backing_error(P, T, AbstractDict)
39-
else
40-
T <: NamedTuple || backing_error(P, T, NamedTuple)
33+
T <: AbstractDict || _backing_error(P, T, AbstractDict)
34+
else # Any other struct (including NamedTuple)
35+
T <: NamedTuple || _backing_error(P, T, NamedTuple)
4136
end
4237
return new(backing)
4338
end
@@ -61,6 +56,11 @@ function Tangent{P}(d::Dict) where {P<:Dict}
6156
return Tangent{P,typeof(d)}(d)
6257
end
6358

59+
function _backing_error(P, G, E)
60+
msg = "Tangent for the primal $P should be backed by a $E type, not by $G."
61+
throw(ArgumentError(msg))
62+
end
63+
6464
function Base.:(==)(a::Tangent{P,T}, b::Tangent{P,T}) where {P,T}
6565
return backing(a) == backing(b)
6666
end

0 commit comments

Comments
 (0)