Skip to content

Commit 2944dad

Browse files
committed
Threshold for Numerical Errors
1 parent b2c1a07 commit 2944dad

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/highlevel/coloring.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ function (alg::ApproximateJacobianSparsity)(ad::AutoSparseFiniteDiff, f::F, x; f
7878
cache = FiniteDiff.JacobianCache(x, fx)
7979
J = fill!(similar(fx, length(fx), length(x)), 0)
8080
x_ = similar(x)
81+
ε = eps(eltype(x))^(1 / 3)
8182
for _ in 1:ntrials
8283
randn!(rng, x_)
8384
J_cache = FiniteDiff.finite_difference_jacobian(f, x, cache)
84-
@. J += abs(J_cache)
85+
@. J += (abs(J_cache) .≥ ε) # hedge against numerical issues
8586
end
8687
return (JacPrototypeSparsityDetection(; jac_prototype = sparse(J), alg.alg))(ad, f, x;
8788
fx, kwargs...)
@@ -94,10 +95,11 @@ function (alg::ApproximateJacobianSparsity)(ad::AutoSparseFiniteDiff, f!::F, fx,
9495
J = fill!(similar(fx, length(fx), length(x)), 0)
9596
J_cache = similar(J)
9697
x_ = similar(x)
98+
ε = eps(eltype(x))^(1 / 3)
9799
for _ in 1:ntrials
98100
randn!(rng, x_)
99101
FiniteDiff.finite_difference_jacobian!(J_cache, f!, x_, cache)
100-
@. J += abs(J_cache)
102+
@. J += (abs(J_cache) .≥ ε) # hedge against numerical issues
101103
end
102104
return (JacPrototypeSparsityDetection(; jac_prototype = sparse(J), alg.alg))(ad, f!, fx,
103105
x; kwargs...)

0 commit comments

Comments
 (0)