From 56bd10a42c7607754f31a8a4543401b48e9adf8e Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Tue, 16 Jan 2024 10:50:04 -0500 Subject: [PATCH] Fix num_vecjac --- src/differentiation/vecjac_products.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/differentiation/vecjac_products.jl b/src/differentiation/vecjac_products.jl index 7f827583..c48b34ca 100644 --- a/src/differentiation/vecjac_products.jl +++ b/src/differentiation/vecjac_products.jl @@ -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? @@ -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