@@ -239,9 +239,8 @@ function finite_difference_gradient!(
239
239
fx, c1, c2, c3 = cache. fx, cache. c1, cache. c2, cache. c3
240
240
if fdtype != Val (:complex ) && ArrayInterface. fast_scalar_indexing (c2)
241
241
@. c2 = compute_epsilon (fdtype, one (eltype (x)), relstep, absstep, dir)
242
- copyto! (c1, x)
243
242
end
244
- copyto! (c3 , x)
243
+ copyto! (c1 , x)
245
244
if fdtype == Val (:forward )
246
245
@inbounds for i ∈ eachindex (x)
247
246
if ArrayInterface. fast_scalar_indexing (c2)
@@ -273,6 +272,7 @@ function finite_difference_gradient!(
273
272
end
274
273
end
275
274
elseif fdtype == Val (:central )
275
+ copyto! (c3, x)
276
276
@inbounds for i ∈ eachindex (x)
277
277
if ArrayInterface. fast_scalar_indexing (c2)
278
278
epsilon = ArrayInterface. allowed_getindex (c2, i) * dir
@@ -296,9 +296,8 @@ function finite_difference_gradient!(
296
296
ArrayInterface. allowed_setindex! (c3, x_old, i)
297
297
end
298
298
elseif fdtype == Val (:complex ) && returntype <: Real
299
- copyto! (c1, x)
300
- epsilon_complex = eps (real (eltype (x)))
301
299
# we use c1 here to avoid typing issues with x
300
+ epsilon_complex = eps (real (eltype (x)))
302
301
@inbounds for i ∈ eachindex (x)
303
302
c1_old = ArrayInterface. allowed_getindex (c1, i)
304
303
ArrayInterface. allowed_setindex! (c1, c1_old + im * epsilon_complex, i)
0 commit comments