@@ -90,9 +90,8 @@ struct ExplicitTangent{P <: Tuple} <: AbstractTangentSpace
90
90
partials:: P
91
91
end
92
92
93
- @eval struct TaylorTangent{C <: Tuple } <: AbstractTangentSpace
93
+ struct TaylorTangent{C <: Tuple } <: AbstractTangentSpace
94
94
coeffs:: C
95
- TaylorTangent (coeffs) = $ (Expr (:new , :(TaylorTangent{typeof (coeffs)}), :coeffs ))
96
95
end
97
96
98
97
"""
@@ -140,24 +139,17 @@ struct UniformTangent{U} <: AbstractTangentSpace
140
139
val:: U
141
140
end
142
141
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
-
151
142
"""
152
143
struct TangentBundle{N, B, P}
153
144
154
145
Represents a tangent bundle as an explicit primal together
155
146
with some representation of (potentially a product of) the tangent space.
156
147
"""
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
161
153
162
154
const ExplicitTangentBundle{N, B, P} = TangentBundle{N, B, ExplicitTangent{P}}
163
155
@@ -166,17 +158,17 @@ check_tangent_invariant(lp, N) = @assert lp == 2^N - 1
166
158
167
159
function ExplicitTangentBundle {N} (primal:: B , partials:: P ) where {N, B, P}
168
160
check_tangent_invariant (length (partials), N)
169
- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
161
+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
170
162
end
171
163
172
164
function ExplicitTangentBundle {N,B} (primal:: B , partials:: P ) where {N, B, P}
173
165
check_tangent_invariant (length (partials), N)
174
- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
166
+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
175
167
end
176
168
177
169
function ExplicitTangentBundle {N,B,P} (primal:: B , partials:: P ) where {N, B, P}
178
170
check_tangent_invariant (length (partials), N)
179
- _TangentBundle ( Val {N} (), primal, ExplicitTangent {P} (partials))
171
+ TangentBundle {N} (primal, ExplicitTangent {P} (partials))
180
172
end
181
173
182
174
function Base. show (io:: IO , x:: ExplicitTangentBundle )
@@ -203,7 +195,7 @@ const TaylorBundle{N, B, P} = TangentBundle{N, B, TaylorTangent{P}}
203
195
204
196
function TaylorBundle {N, B} (primal:: B , coeffs) where {N, B}
205
197
check_taylor_invariants (coeffs, primal, N)
206
- _TangentBundle ( Val {N} (), primal, TaylorTangent (coeffs))
198
+ TangentBundle {N} (primal, TaylorTangent (coeffs))
207
199
end
208
200
209
201
function check_taylor_invariants (coeffs, primal, N)
215
207
@ChainRulesCore . non_differentiable check_taylor_invariants (coeffs, primal, N)
216
208
217
209
function TaylorBundle {N} (primal, coeffs) where {N}
218
- _TangentBundle ( Val {N} (), primal, TaylorTangent (coeffs))
210
+ TangentBundle {N} (primal, TaylorTangent (coeffs))
219
211
end
220
212
221
213
function Base. show (io:: IO , x:: TaylorBundle{1} )
@@ -230,25 +222,13 @@ function Base.getindex(tb::TaylorBundle, tti::CanonicalTangentIndex)
230
222
tb. tangent. coeffs[count_ones (tti. i)]
231
223
end
232
224
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
-
245
225
const 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))
252
232
253
233
const ZeroBundle{N, B} = UniformBundle{N, B, ZeroTangent}
254
234
const DNEBundle{N, B} = UniformBundle{N, B, NoTangent}
0 commit comments