From 2944dad6f0bc94bc7eec9b4aca972974d80f0f5f Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Wed, 13 Dec 2023 13:09:55 -0500 Subject: [PATCH] Threshold for Numerical Errors --- src/highlevel/coloring.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/highlevel/coloring.jl b/src/highlevel/coloring.jl index cad29e81..d0c1b0da 100644 --- a/src/highlevel/coloring.jl +++ b/src/highlevel/coloring.jl @@ -78,10 +78,11 @@ function (alg::ApproximateJacobianSparsity)(ad::AutoSparseFiniteDiff, f::F, x; f cache = FiniteDiff.JacobianCache(x, fx) J = fill!(similar(fx, length(fx), length(x)), 0) x_ = similar(x) + ε = eps(eltype(x))^(1 / 3) for _ in 1:ntrials randn!(rng, x_) J_cache = FiniteDiff.finite_difference_jacobian(f, x, cache) - @. J += abs(J_cache) + @. J += (abs(J_cache) .≥ ε) # hedge against numerical issues end return (JacPrototypeSparsityDetection(; jac_prototype = sparse(J), alg.alg))(ad, f, x; fx, kwargs...) @@ -94,10 +95,11 @@ function (alg::ApproximateJacobianSparsity)(ad::AutoSparseFiniteDiff, f!::F, fx, J = fill!(similar(fx, length(fx), length(x)), 0) J_cache = similar(J) x_ = similar(x) + ε = eps(eltype(x))^(1 / 3) for _ in 1:ntrials randn!(rng, x_) FiniteDiff.finite_difference_jacobian!(J_cache, f!, x_, cache) - @. J += abs(J_cache) + @. J += (abs(J_cache) .≥ ε) # hedge against numerical issues end return (JacPrototypeSparsityDetection(; jac_prototype = sparse(J), alg.alg))(ad, f!, fx, x; kwargs...)