@@ -6,21 +6,22 @@ function auto_jacvec!(
6
6
f,
7
7
x,
8
8
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) )))),
10
10
cache2 = similar (cache1),
11
11
)
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) ))))
13
13
f (cache2, cache1)
14
14
vecdy = _vec (dy)
15
- vecdy .= partials .(vec (cache2), 1 )
15
+ vecdy .= partials .(_vec (cache2), 1 )
16
16
end
17
17
18
18
_vec (v) = vec (v)
19
19
_vec (v:: AbstractVector ) = v
20
20
21
21
function auto_jacvec (f, x, v)
22
22
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 ))
24
25
end
25
26
26
27
function num_jacvec! (
@@ -126,12 +127,12 @@ function autonum_hesvec!(
126
127
f,
127
128
x,
128
129
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)))) ),
131
132
)
132
133
cache = FiniteDiff. GradientCache (v[1 ], cache1, Val{:central })
133
134
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)))) )
135
136
g (cache2, cache1)
136
137
dy .= partials .(cache2, 1 )
137
138
end
@@ -168,16 +169,17 @@ function auto_hesvecgrad!(
168
169
g,
169
170
x,
170
171
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)))) ),
173
174
)
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)))) )
175
176
g (cache3, cache2)
176
177
dy .= partials .(cache3, 1 )
177
178
end
178
179
179
180
function 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 )
181
183
end
182
184
183
185
# ## Operator Forms
192
194
193
195
function JacVec (f, x:: AbstractArray ; autodiff = true )
194
196
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)) )
197
199
else
198
200
cache1 = similar (x)
199
201
cache2 = similar (x)
261
263
262
264
function HesVecGrad (g, x:: AbstractArray ; autodiff = false )
263
265
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)) )
266
268
else
267
269
cache1 = similar (x)
268
270
cache2 = similar (x)
0 commit comments