@@ -6,15 +6,20 @@ struct ForwardDiffJacobianCache{CO, CA, J, FX, X} <: AbstractMaybeSparseJacobian
66 x:: X
77end
88
9+ __getfield (c:: ForwardDiffJacobianCache , :: Val{:jac_prototype} ) = c. jac_prototype
10+
911struct SparseDiffToolsTag end
1012
13+ __standard_tag (:: Nothing , x) = ForwardDiff. Tag (SparseDiffToolsTag (), eltype (x))
14+ __standard_tag (tag, _) = tag
15+
1116function sparse_jacobian_cache (ad:: Union{AutoSparseForwardDiff, AutoForwardDiff} ,
1217 sd:: AbstractMaybeSparsityDetection , f:: F , x; fx = nothing ) where {F}
1318 coloring_result = sd (ad, f, x)
1419 fx = fx === nothing ? similar (f (x)) : fx
1520 if coloring_result isa NoMatrixColoring
1621 cache = ForwardDiff. JacobianConfig (f, x, __chunksize (ad, x),
17- ifelse (ad. tag === nothing , SparseDiffToolsTag (), ad . tag ))
22+ __standard_tag (ad. tag, x ))
1823 jac_prototype = nothing
1924 else
2025 cache = ForwardColorJacCache (f, x, __chunksize (ad); coloring_result. colorvec,
@@ -29,7 +34,7 @@ function sparse_jacobian_cache(ad::Union{AutoSparseForwardDiff, AutoForwardDiff}
2934 coloring_result = sd (ad, f!, fx, x)
3035 if coloring_result isa NoMatrixColoring
3136 cache = ForwardDiff. JacobianConfig (f!, fx, x, __chunksize (ad, x),
32- ifelse (ad. tag === nothing , SparseDiffToolsTag (), ad . tag ))
37+ __standard_tag (ad. tag, x ))
3338 jac_prototype = nothing
3439 else
3540 cache = ForwardColorJacCache (f!, x, __chunksize (ad); coloring_result. colorvec,
@@ -44,7 +49,8 @@ function sparse_jacobian!(J::AbstractMatrix, _, cache::ForwardDiffJacobianCache,
4449 if cache. cache isa ForwardColorJacCache
4550 forwarddiff_color_jacobian (J, f, x, cache. cache) # Use Sparse ForwardDiff
4651 else
47- ForwardDiff. jacobian! (J, f, x, cache. cache) # Don't try to exploit sparsity
52+ # Disable tag checking since we set the tag to our custom tag
53+ ForwardDiff. jacobian! (J, f, x, cache. cache, Val (false )) # Don't try to exploit sparsity
4854 end
4955 return J
5056end
@@ -54,7 +60,8 @@ function sparse_jacobian!(J::AbstractMatrix, _, cache::ForwardDiffJacobianCache,
5460 if cache. cache isa ForwardColorJacCache
5561 forwarddiff_color_jacobian! (J, f!, x, cache. cache) # Use Sparse ForwardDiff
5662 else
57- ForwardDiff. jacobian! (J, f!, fx, x, cache. cache) # Don't try to exploit sparsity
63+ # Disable tag checking since we set the tag to our custom tag
64+ ForwardDiff. jacobian! (J, f!, fx, x, cache. cache, Val (false )) # Don't try to exploit sparsity
5865 end
5966 return J
6067end
0 commit comments