Skip to content

Commit b6553b8

Browse files
committed
Make it an option
1 parent 5727eed commit b6553b8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/highlevel/coloring.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ 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)) * 100
81+
ε = ifelse(alg.epsilon === nothing, eps(eltype(x)) * 100, alg.epsilon)
8282
for _ in 1:ntrials
8383
randn!(rng, x_)
8484
J_cache = FiniteDiff.finite_difference_jacobian(f, x, cache)
@@ -95,7 +95,7 @@ function (alg::ApproximateJacobianSparsity)(ad::AutoSparseFiniteDiff, f!::F, fx,
9595
J = fill!(similar(fx, length(fx), length(x)), 0)
9696
J_cache = similar(J)
9797
x_ = similar(x)
98-
ε = eps(eltype(x)) * 100
98+
ε = ifelse(alg.epsilon === nothing, eps(eltype(x)) * 100, alg.epsilon)
9999
for _ in 1:ntrials
100100
randn!(rng, x_)
101101
FiniteDiff.finite_difference_jacobian!(J_cache, f!, x_, cache)

src/highlevel/common.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ end
114114

115115
"""
116116
ApproximateJacobianSparsity(; ntrials = 5, rng = Random.default_rng(),
117-
alg = GreedyD1Color())
117+
epsilon = nothing, alg = GreedyD1Color())
118118
119119
Use `ntrials` random vectors to compute the sparsity pattern of the Jacobian. This is an
120120
approximate method and the sparsity pattern may not be exact.
@@ -124,17 +124,21 @@ approximate method and the sparsity pattern may not be exact.
124124
- `ntrials`: The number of random vectors to use for computing the sparsity pattern
125125
- `rng`: The random number generator used for generating the random vectors
126126
- `alg`: The algorithm used for computing the matrix colors
127+
- `epsilon`: For Finite Differencing based Jacobian Approximations, any number smaller
128+
than `epsilon` is considered to be zero. If `nothing` is specified, then this value
129+
is calculated as `100 * eps(eltype(x))`
127130
"""
128-
struct ApproximateJacobianSparsity{R <: AbstractRNG,
129-
A <: ArrayInterface.ColoringAlgorithm} <: AbstractSparsityDetection
131+
struct ApproximateJacobianSparsity{R <: AbstractRNG, A <: ArrayInterface.ColoringAlgorithm,
132+
E} <: AbstractSparsityDetection
130133
ntrials::Int
131134
rng::R
132135
alg::A
136+
epsilon::E
133137
end
134138

135-
function ApproximateJacobianSparsity(; ntrials::Int = 3,
139+
function ApproximateJacobianSparsity(; ntrials::Int = 3, epsilon = nothing,
136140
rng::AbstractRNG = Random.default_rng(), alg = GreedyD1Color())
137-
return ApproximateJacobianSparsity(ntrials, rng, alg)
141+
return ApproximateJacobianSparsity(ntrials, rng, alg, epsilon)
138142
end
139143

140144
# No one should be using this currently

0 commit comments

Comments
 (0)