@@ -6,17 +6,22 @@ function auto_jacvec!(
6
6
f,
7
7
x,
8
8
v,
9
- cache1 = Dual {DeivVecTag} .(x, 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 {DeivVecTag} .(x, 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
- dy .= partials .(cache2, 1 )
14
+ vecdy = _vec (dy)
15
+ vecdy .= partials .(_vec (cache2), 1 )
15
16
end
16
17
18
+ _vec (v) = vec (v)
19
+ _vec (v:: AbstractVector ) = v
20
+
17
21
function auto_jacvec (f, x, v)
18
22
vv = reshape (v, axes (x))
19
- vec (partials .(vec (f (ForwardDiff. Dual {DeivVecTag} .(x, 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 ))
20
25
end
21
26
22
27
function num_jacvec! (
@@ -122,12 +127,12 @@ function autonum_hesvec!(
122
127
f,
123
128
x,
124
129
v,
125
- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
126
- 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)))) ),
127
132
)
128
133
cache = FiniteDiff. GradientCache (v[1 ], cache1, Val{:central })
129
134
g = (dx, x) -> FiniteDiff. finite_difference_gradient! (dx, f, x, cache)
130
- 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)))) )
131
136
g (cache2, cache1)
132
137
dy .= partials .(cache2, 1 )
133
138
end
@@ -164,16 +169,17 @@ function auto_hesvecgrad!(
164
169
g,
165
170
x,
166
171
v,
167
- cache2 = ForwardDiff . Dual {DeivVecTag} .(x, v ),
168
- 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)))) ),
169
174
)
170
- 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)))) )
171
176
g (cache3, cache2)
172
177
dy .= partials .(cache3, 1 )
173
178
end
174
179
175
180
function auto_hesvecgrad (g, x, v)
176
- 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 )
177
183
end
178
184
179
185
# ## Operator Forms
@@ -188,15 +194,16 @@ end
188
194
189
195
function JacVec (f, x:: AbstractArray ; autodiff = true )
190
196
if autodiff
191
- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, x )
192
- 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)) )
193
199
else
194
200
cache1 = similar (x)
195
201
cache2 = similar (x)
196
202
end
197
203
JacVec (f, cache1, cache2, x, autodiff)
198
204
end
199
205
206
+ Base. eltype (L:: JacVec ) = eltype (L. x)
200
207
Base. size (L:: JacVec ) = (length (L. cache1), length (L. cache1))
201
208
Base. size (L:: JacVec , i:: Int ) = length (L. cache1)
202
209
Base.:* (L:: JacVec , v:: AbstractVector ) =
256
263
257
264
function HesVecGrad (g, x:: AbstractArray ; autodiff = false )
258
265
if autodiff
259
- cache1 = ForwardDiff . Dual {DeivVecTag} .(x, x )
260
- 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)) )
261
268
else
262
269
cache1 = similar (x)
263
270
cache2 = similar (x)
0 commit comments