@@ -90,9 +90,8 @@ struct ExplicitTangent{P <: Tuple} <: AbstractTangentSpace
9090 partials:: P
9191end
9292
93- @eval struct TaylorTangent{C <: Tuple } <: AbstractTangentSpace
93+ struct TaylorTangent{C <: Tuple } <: AbstractTangentSpace
9494 coeffs:: C
95- TaylorTangent (coeffs) = $ (Expr (:new , :(TaylorTangent{typeof (coeffs)}), :coeffs ))
9695end
9796
9897"""
@@ -140,24 +139,17 @@ struct UniformTangent{U} <: AbstractTangentSpace
140139 val:: U
141140end
142141
143- function _TangentBundle end
144-
145- @eval struct TangentBundle{N, B, P <: AbstractTangentSpace } <: AbstractTangentBundle{N, B}
146- primal:: B
147- tangent:: P
148- global _TangentBundle (:: Val{N} , primal:: B , tangent:: P ) where {N, B, P} = $ (Expr (:new , :(TangentBundle{N, Core. Typeof (primal), typeof (tangent)}), :primal , :tangent ))
149- end
150-
151142"""
152143 struct TangentBundle{N, B, P}
153144
154145Represents a tangent bundle as an explicit primal together
155146with some representation of (potentially a product of) the tangent space.
156147"""
157- TangentBundle
158-
159- TangentBundle {N} (primal:: B , tangent:: P ) where {N, B, P<: AbstractTangentSpace } =
160- _TangentBundle (Val {N} (), primal, tangent)
148+ struct TangentBundle{N, B, P <: AbstractTangentSpace } <: AbstractTangentBundle{N, B}
149+ primal:: B
150+ tangent:: P
151+ TangentBundle {N} (B, P) where {N} = new {N, typeof(B), typeof(P)} (B,P)
152+ end
161153
162154const ExplicitTangentBundle{N, B, P} = TangentBundle{N, B, ExplicitTangent{P}}
163155
@@ -166,17 +158,17 @@ check_tangent_invariant(lp, N) = @assert lp == 2^N - 1
166158
167159function ExplicitTangentBundle {N} (primal:: B , partials:: P ) where {N, B, P}
168160 check_tangent_invariant (length (partials), N)
169- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
161+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
170162end
171163
172164function ExplicitTangentBundle {N,B} (primal:: B , partials:: P ) where {N, B, P}
173165 check_tangent_invariant (length (partials), N)
174- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
166+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
175167end
176168
177169function ExplicitTangentBundle {N,B,P} (primal:: B , partials:: P ) where {N, B, P}
178170 check_tangent_invariant (length (partials), N)
179- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
171+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
180172end
181173
182174function Base. show (io:: IO , x:: ExplicitTangentBundle )
@@ -203,7 +195,7 @@ const TaylorBundle{N, B, P} = TangentBundle{N, B, TaylorTangent{P}}
203195
204196function TaylorBundle {N, B} (primal:: B , coeffs) where {N, B}
205197 check_taylor_invariants (coeffs, primal, N)
206- _TangentBundle ( Val {N} (), primal, TaylorTangent (coeffs))
198+ TangentBundle {N} (primal, TaylorTangent (coeffs))
207199end
208200
209201function check_taylor_invariants (coeffs, primal, N)
215207@ChainRulesCore . non_differentiable check_taylor_invariants (coeffs, primal, N)
216208
217209function TaylorBundle {N} (primal, coeffs) where {N}
218- _TangentBundle ( Val {N} (), primal, TaylorTangent (coeffs))
210+ TangentBundle {N} (primal, TaylorTangent (coeffs))
219211end
220212
221213function Base. show (io:: IO , x:: TaylorBundle{1} )
@@ -230,25 +222,13 @@ function Base.getindex(tb::TaylorBundle, tti::CanonicalTangentIndex)
230222 tb. tangent. coeffs[count_ones (tti. i)]
231223end
232224
233- function truncate (tt:: TaylorTangent , order:: Val{N} ) where {N}
234- TaylorTangent (tt. coeffs[1 : N])
235- end
236-
237- function truncate (ut:: UniformTangent , order:: Val )
238- ut
239- end
240-
241- function truncate (tb:: TangentBundle , order:: Val )
242- _TangentBundle (order, tb. primal, truncate (tb. tangent, order))
243- end
244-
245225const UniformBundle{N, B, U} = TangentBundle{N, B, UniformTangent{U}}
246- UniformBundle {N, B, U} (primal:: B , partial:: U ) where {N,B,U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (partial))
247- UniformBundle {N, B, U} (primal:: B ) where {N,B,U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (U. instance))
248- UniformBundle {N, B} (primal:: B , partial:: U ) where {N,B,U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (partial))
249- UniformBundle {N} (primal, partial:: U ) where {N,U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (partial))
250- UniformBundle {N, <:Any, U} (primal, partial:: U ) where {N, U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (U. instance))
251- UniformBundle {N, <:Any, U} (primal) where {N, U} = _TangentBundle ( Val {N} (), primal, UniformTangent {U} (U. instance))
226+ UniformBundle {N, B, U} (primal:: B , partial:: U ) where {N,B,U} = TangentBundle {N} (primal, UniformTangent {U} (partial))
227+ UniformBundle {N, B, U} (primal:: B ) where {N,B,U} = TangentBundle {N} (primal, UniformTangent {U} (U. instance))
228+ UniformBundle {N, B} (primal:: B , partial:: U ) where {N,B,U} = TangentBundle {N} (primal, UniformTangent {U} (partial))
229+ UniformBundle {N} (primal, partial:: U ) where {N,U} = TangentBundle {N} (primal, UniformTangent {U} (partial))
230+ UniformBundle {N, <:Any, U} (primal, partial:: U ) where {N, U} = TangentBundle {N} (primal, UniformTangent {U} (U. instance))
231+ UniformBundle {N, <:Any, U} (primal) where {N, U} = TangentBundle {N} (primal, UniformTangent {U} (U. instance))
252232
253233const ZeroBundle{N, B} = UniformBundle{N, B, ZeroTangent}
254234const DNEBundle{N, B} = UniformBundle{N, B, NoTangent}
0 commit comments