@@ -6,21 +6,22 @@ function auto_jacvec!(
66 f,
77 x,
88 v,
9- cache1 = Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(reshape (v, size (x)))),
9+ cache1 = Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(Tuple .( reshape (v, size (x) )))),
1010 cache2 = similar (cache1),
1111)
12- cache1 .= Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(reshape (v, size (x))))
12+ cache1 .= Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(Tuple .( reshape (v, size (x) ))))
1313 f (cache2, cache1)
1414 vecdy = _vec (dy)
15- vecdy .= partials .(vec (cache2), 1 )
15+ vecdy .= partials .(_vec (cache2), 1 )
1616end
1717
1818_vec (v) = vec (v)
1919_vec (v:: AbstractVector ) = v
2020
2121function auto_jacvec (f, x, v)
2222 vv = reshape (v, axes (x))
23- vec (partials .(vec (f (ForwardDiff. Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(vv)))), 1 ))
23+ y = ForwardDiff. Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(Tuple .(vv)))
24+ vec (partials .(vec (f (y)), 1 ))
2425end
2526
2627function num_jacvec! (
@@ -126,12 +127,12 @@ function autonum_hesvec!(
126127 f,
127128 x,
128129 v,
129- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
130- cache2 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
130+ cache1 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) ),
131+ cache2 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) ),
131132)
132133 cache = FiniteDiff. GradientCache (v[1 ], cache1, Val{:central })
133134 g = (dx, x) -> FiniteDiff. finite_difference_gradient! (dx, f, x, cache)
134- cache1 .= Dual {DeivVecTag} .(x, v )
135+ cache1 .= Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) )
135136 g (cache2, cache1)
136137 dy .= partials .(cache2, 1 )
137138end
@@ -168,16 +169,17 @@ function auto_hesvecgrad!(
168169 g,
169170 x,
170171 v,
171- cache2 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
172- cache3 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
172+ cache2 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) ),
173+ cache3 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) ),
173174)
174- cache2 .= Dual {DeivVecTag} .(x, v )
175+ cache2 .= Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .( reshape (v, size (x)))) )
175176 g (cache3, cache2)
176177 dy .= partials .(cache3, 1 )
177178end
178179
179180function auto_hesvecgrad (g, x, v)
180- partials .(g (Dual {DeivVecTag} .(x, v)), 1 )
181+ y = Dual {typeof(ForwardDiff.Tag(DeivVecTag,eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(Tuple .(reshape (v, size (x)))))
182+ partials .(g (y), 1 )
181183end
182184
183185# ## Operator Forms
192194
193195function JacVec (f, x:: AbstractArray ; autodiff = true )
194196 if autodiff
195- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, x )
196- cache2 = ForwardDiff . Dual {DeivVecTag} .(x, x )
197+ cache1 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .(x)) )
198+ cache2 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .(x)) )
197199 else
198200 cache1 = similar (x)
199201 cache2 = similar (x)
261263
262264function HesVecGrad (g, x:: AbstractArray ; autodiff = false )
263265 if autodiff
264- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, x )
265- cache2 = ForwardDiff . Dual {DeivVecTag} .(x, x )
266+ cache1 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .(x)) )
267+ cache2 = Dual {typeof(ForwardDiff.Tag( DeivVecTag,eltype(x))),eltype(x),1 } .(x, ForwardDiff . Partials .( Tuple .(x)) )
266268 else
267269 cache1 = similar (x)
268270 cache2 = similar (x)
0 commit comments