@@ -6,13 +6,13 @@ get_tag(::Dual{T, V, N}) where {T, V, N} = T
6
6
# J(f(x))*v
7
7
function auto_jacvec! (dy, f, x, v,
8
8
cache1 = Dual{typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
9
- eltype (x), 1 ,
9
+ eltype (x), 1
10
10
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
11
11
cache2 = similar (cache1))
12
12
cache1 .= Dual{
13
13
get_tag (cache1),
14
14
eltype (x),
15
- 1 ,
15
+ 1
16
16
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
17
17
f (cache2, cache1)
18
18
vecdy = _vec (dy)
@@ -27,7 +27,7 @@ function auto_jacvec(f, x, v)
27
27
y = ForwardDiff. Dual{
28
28
typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
29
29
eltype (x),
30
- 1 ,
30
+ 1
31
31
}. (x, ForwardDiff. Partials .(tuple .(vv)))
32
32
vec (partials .(vec (f (y)), 1 ))
33
33
end
@@ -113,17 +113,17 @@ end
113
113
114
114
function autonum_hesvec! (dy, f, x, v,
115
115
cache1 = Dual{typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
116
- eltype (x), 1 ,
116
+ eltype (x), 1
117
117
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
118
118
cache2 = Dual{typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
119
- eltype (x), 1 ,
119
+ eltype (x), 1
120
120
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))))
121
121
cache = FiniteDiff. GradientCache (v[1 ], cache1, Val{:central })
122
122
g = (dx, x) -> FiniteDiff. finite_difference_gradient! (dx, f, x, cache)
123
123
cache1 .= Dual{
124
124
get_tag (cache1),
125
125
eltype (x),
126
- 1 ,
126
+ 1
127
127
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
128
128
g (cache2, cache1)
129
129
dy .= partials .(cache2, 1 )
@@ -159,15 +159,15 @@ end
159
159
160
160
function auto_hesvecgrad! (dy, g, x, v,
161
161
cache2 = Dual{typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
162
- eltype (x), 1 ,
162
+ eltype (x), 1
163
163
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))),
164
164
cache3 = Dual{typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
165
- eltype (x), 1 ,
165
+ eltype (x), 1
166
166
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x))))))
167
167
cache2 .= Dual{
168
168
get_tag (cache2),
169
169
eltype (x),
170
- 1 ,
170
+ 1
171
171
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
172
172
g (cache3, cache2)
173
173
dy .= partials .(cache3, 1 )
@@ -177,7 +177,7 @@ function auto_hesvecgrad(g, x, v)
177
177
y = Dual{
178
178
typeof (ForwardDiff. Tag (DeivVecTag (), eltype (x))),
179
179
eltype (x),
180
- 1 ,
180
+ 1
181
181
}. (x, ForwardDiff. Partials .(tuple .(reshape (v, size (x)))))
182
182
partials .(g (y), 1 )
183
183
end
@@ -272,10 +272,10 @@ function JacVec(f, u::AbstractArray, p = nothing, t = nothing; fu = nothing,
272
272
(cache1, cache2), num_jacvec, num_jacvec!
273
273
elseif autodiff isa AutoForwardDiff
274
274
cache1 = Dual{
275
- typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1 ,
275
+ typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1
276
276
}. (u, ForwardDiff. Partials .(tuple .(u)))
277
277
cache2 = Dual{
278
- typeof (ForwardDiff. Tag (tag, eltype (fu))), eltype (fu), 1 ,
278
+ typeof (ForwardDiff. Tag (tag, eltype (fu))), eltype (fu), 1
279
279
}. (fu, ForwardDiff. Partials .(tuple .(fu)))
280
280
281
281
(cache1, cache2), auto_jacvec, auto_jacvec!
@@ -307,7 +307,7 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing;
307
307
@assert static_hasmethod (autoback_hesvec, typeof ((f, u, u))) " To use AutoZygote() AD, first load Zygote with `using Zygote`, or `import Zygote`"
308
308
309
309
cache1 = Dual{
310
- typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1 ,
310
+ typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1
311
311
}. (u, ForwardDiff. Partials .(tuple .(u)))
312
312
cache2 = copy (cache1)
313
313
@@ -338,7 +338,7 @@ function HesVecGrad(f, u::AbstractArray, p = nothing, t = nothing;
338
338
(cache1, cache2), num_hesvecgrad, num_hesvecgrad!
339
339
elseif autodiff isa AutoForwardDiff
340
340
cache1 = Dual{
341
- typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1 ,
341
+ typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1
342
342
}. (u, ForwardDiff. Partials .(tuple .(u)))
343
343
cache2 = copy (cache1)
344
344
0 commit comments