@@ -14,9 +14,9 @@ struct ∂☆new{N}; end
1414# but the nth order case does also work for this
1515function (:: ∂☆new{1 })(B:: Type , xs:: AbstractTangentBundle{1} ...)
1616 primal_args = map (primal, xs)
17- the_primal = B <: Tuple ? B ( primal_args) : B (primal_args ... )
18-
19- tangent_tup = map (x -> partial (x, 1 ) , xs)
17+ the_primal = _construct (B, primal_args)
18+
19+ tangent_tup = map (first_partial , xs)
2020 the_partial = if B<: Tuple
2121 Tangent {B, typeof(tangent_tup)} (tangent_tup)
2222 else
2929
3030function (:: ∂☆new{N})(B:: Type , xs:: AbstractTangentBundle{N} ...) where {N}
3131 primal_args = map (primal, xs)
32- the_primal = B <: Tuple ? B ( primal_args) : B (primal_args ... )
32+ the_primal = _construct (B, primal_args)
3333
3434 the_partials = ntuple (Val {N} ()) do ii
3535 iith_order_type = ii== 1 ? B : Any # the type of the higher order tangents isn't worth tracking
@@ -46,6 +46,10 @@ function (::∂☆new{N})(B::Type, xs::AbstractTangentBundle{N}...) where {N}
4646 return TaylorBundle {N, B} (the_primal, the_partials)
4747end
4848
49+ _construct (:: Type{B} , args) where B<: Tuple = B (args)
50+ # Hack for making things that do not have public constructors constructable:
51+ @generated _construct (B:: Type , args) = :($ (Expr (:splatnew , :B , :args )))
52+
4953@generated (:: ∂☆new{N})(B:: Type ) where {N} = return :(ZeroBundle {$N} ($ (Expr (:new , :B ))))
5054
5155# Sometimes we don't know whether or not we need to the ZeroBundle when doing
0 commit comments