@@ -74,48 +74,63 @@ function taylor_failure_values(r::TaylorBundle{<:Any, Tuple{Any,Any}}, fail_orde
74
74
return partial (r, i+ 1 )[1 ], partial (r, i)[2 ]
75
75
end
76
76
77
- function shuffle_up (r:: TaylorBundle{1, Tuple{B1,B2}} , :: Val{taylor_or_bust} ) where {B1,B2, taylor_or_bust}
78
- z₀ = primal (r)[1 ]
79
- z₁ = partial (r, 1 )[1 ]
80
- z₂ = primal (r)[2 ]
81
- z₁₂ = partial (r, 1 )[2 ]
82
-
83
- taylor_fail_order = find_taylor_incompatibility (r)
84
- if taylor_fail_order < 0
85
- return TaylorBundle {2} (z₀, (z₁, z₁₂))
86
- elseif taylor_or_bust
87
- @assert taylor_fail_order == 0 # can't be higher
88
- throw (TaylorRequired (taylor_fail_order, z₁, z₂))
89
- else
90
- return ExplicitTangentBundle {2} (z₀, (z₁, z₂, z₁₂))
77
+ for taylor_or_bust in (false , true )
78
+ @eval function shuffle_up (r:: TaylorBundle{1, Tuple{B1,B2}} , :: Val{$taylor_or_bust} ) where {B1,B2}
79
+ z₀ = primal (r)[1 ]
80
+ z₁ = partial (r, 1 )[1 ]
81
+ z₂ = primal (r)[2 ]
82
+ z₁₂ = partial (r, 1 )[2 ]
83
+
84
+ taylor_fail_order = find_taylor_incompatibility (r)
85
+ if taylor_fail_order < 0
86
+ return TaylorBundle {2} (z₀, (z₁, z₁₂))
87
+ else
88
+ $ (
89
+ if taylor_or_bust
90
+ quote
91
+ @assert taylor_fail_order == 0 # can't be higher
92
+ throw (TaylorRequired (taylor_fail_order, z₁, z₂))
93
+ end
94
+ else
95
+ :(return ExplicitTangentBundle {2} (z₀, (z₁, z₂, z₁₂)))
96
+ end
97
+ )
98
+ end
91
99
end
92
- end
93
100
94
- function shuffle_up (r:: TaylorBundle{N, Tuple{B1,B2}} , :: Val{taylor_or_bust} ) where {N, B1,B2, taylor_or_bust}
95
- the_primal = primal (r)[1 ]
96
- taylor_fail_order = find_taylor_incompatibility (r)
97
- if taylor_fail_order (r) < 0
98
- the_partials = ntuple (N+ 1 ) do i
99
- if i <= N
100
- partial (r, i)[1 ] # == `partial(r,i-1)[2]` (except first which is primal(r)[2])
101
- else # ii = N+1
102
- partial (r, i- 1 )[2 ]
101
+ @eval function shuffle_up (r:: TaylorBundle{N, Tuple{B1,B2}} , :: Val{$taylor_or_bust} ) where {N, B1,B2}
102
+ the_primal = primal (r)[1 ]
103
+ taylor_fail_order = find_taylor_incompatibility (r)
104
+ if taylor_fail_order (r) < 0
105
+ the_partials = ntuple (N+ 1 ) do i
106
+ if i <= N
107
+ partial (r, i)[1 ] # == `partial(r,i-1)[2]` (except first which is primal(r)[2])
108
+ else # ii = N+1
109
+ partial (r, i- 1 )[2 ]
110
+ end
103
111
end
112
+ return TaylorBundle {N+1} (the_primal, the_partials)
113
+ else
114
+ $ (
115
+ if taylor_or_bust
116
+ quote
117
+ @assert taylor_fail_order < N
118
+ throw (TaylorRequired (taylor_fail_order, taylor_failure_values (r, taylor_fail_order)... ))
119
+ end
120
+ else
121
+ quote
122
+ # XXX : am dubious of the correctness of this
123
+ a_partials = ntuple (i-> partial (r, i)[1 ], N)
124
+ b_partials = ntuple (i-> partial (r, i)[2 ], N)
125
+ the_partials = (a_partials... , primal_b, b_partials... )
126
+ return TangentBundle {N+1} (the_primal, the_partials)
127
+ end
128
+ end
129
+ )
104
130
end
105
- return TaylorBundle {N+1} (the_primal, the_partials)
106
- elseif taylor_or_bust
107
- @assert taylor_fail_order < N
108
- throw (TaylorRequired (taylor_fail_order, taylor_failure_values (r, taylor_fail_order)... ))
109
- else
110
- # XXX : am dubious of the correctness of this
111
- a_partials = ntuple (i-> partial (r, i)[1 ], N)
112
- b_partials = ntuple (i-> partial (r, i)[2 ], N)
113
- the_partials = (a_partials... , primal_b, b_partials... )
114
- return TangentBundle {N+1} (the_primal, the_partials)
115
131
end
116
132
end
117
133
118
-
119
134
function shuffle_up (r:: UniformBundle{N, B, U} , _:: Val ) where {N, B, U}
120
135
(a, b) = primal (r)
121
136
if r. tangent. val === b
0 commit comments