Skip to content

Commit

Permalink
Fix num_vecjac
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Jan 16, 2024
1 parent 1156e34 commit 56bd10a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/differentiation/vecjac_products.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function num_vecjac!(du, f::F, x, v, cache1 = similar(v), cache2 = similar(v), cache3 = similar(v);
compute_f0 = true) where {F}
function num_vecjac!(du, f::F, x, v, cache1 = similar(v), cache2 = similar(v),
cache3 = similar(x); compute_f0 = true) where {F}
compute_f0 && (f(cache1, x))
T = eltype(x)
# Should it be min? max? mean?
Expand All @@ -22,10 +22,11 @@ function num_vecjac(f::F, x, v, f0 = nothing) where {F}
# Should it be min? max? mean?
ϵ = sqrt(eps(real(T))) * max(one(real(T)), abs(norm(x)))
du = similar(x)
cache = copy(x)
cache = similar(x)
copyto!(cache, x)
for i in 1:length(x)
cache[i] += ϵ
f0 = f(x)
f0 = f(cache)
cache[i] = x[i]
du[i] = (((f0 .- _f0) ./ ϵ)' * vv)[1]
end
Expand Down

0 comments on commit 56bd10a

Please sign in to comment.