1
1
struct DeivVecTag end
2
2
3
+ get_tag (:: Array{Dual{T,V,N}} ) where {T,V,N} = T
4
+ get_tag (:: Dual{T,V,N} ) where {T,V,N} = T
5
+
3
6
# J(f(x))*v
4
7
function auto_jacvec! (
5
8
dy,
@@ -9,7 +12,7 @@ function auto_jacvec!(
9
12
cache1 = Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
10
13
cache2 = similar (cache1),
11
14
)
12
- cache1 .= Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x)) ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
15
+ cache1 .= Dual {get_tag(cache1 ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
13
16
f (cache2, cache1)
14
17
vecdy = _vec (dy)
15
18
vecdy .= partials .(_vec (cache2), 1 )
@@ -135,7 +138,7 @@ function autonum_hesvec!(
135
138
)
136
139
cache = FiniteDiff. GradientCache (v[1 ], cache1, Val{:central })
137
140
g = (dx, x) -> FiniteDiff. finite_difference_gradient! (dx, f, x, cache)
138
- cache1 .= Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x)) ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
141
+ cache1 .= Dual {get_tag(cache1 ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
139
142
g (cache2, cache1)
140
143
dy .= partials .(cache2, 1 )
141
144
end
@@ -175,7 +178,7 @@ function auto_hesvecgrad!(
175
178
cache2 = Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
176
179
cache3 = Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x))),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
177
180
)
178
- cache2 .= Dual {typeof(ForwardDiff.Tag(DeivVecTag(),eltype(x)) ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
181
+ cache2 .= Dual {get_tag(cache2 ),eltype(x),1} .(x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
179
182
g (cache3, cache2)
180
183
dy .= partials .(cache3, 1 )
181
184
end
0 commit comments