@@ -6,15 +6,20 @@ struct ForwardDiffJacobianCache{CO, CA, J, FX, X} <: AbstractMaybeSparseJacobian
6
6
x:: X
7
7
end
8
8
9
+ __getfield (c:: ForwardDiffJacobianCache , :: Val{:jac_prototype} ) = c. jac_prototype
10
+
9
11
struct SparseDiffToolsTag end
10
12
13
+ __standard_tag (:: Nothing , x) = ForwardDiff. Tag (SparseDiffToolsTag (), eltype (x))
14
+ __standard_tag (tag, _) = tag
15
+
11
16
function sparse_jacobian_cache (ad:: Union{AutoSparseForwardDiff, AutoForwardDiff} ,
12
17
sd:: AbstractMaybeSparsityDetection , f:: F , x; fx = nothing ) where {F}
13
18
coloring_result = sd (ad, f, x)
14
19
fx = fx === nothing ? similar (f (x)) : fx
15
20
if coloring_result isa NoMatrixColoring
16
21
cache = ForwardDiff. JacobianConfig (f, x, __chunksize (ad, x),
17
- ifelse (ad. tag === nothing , SparseDiffToolsTag (), ad . tag ))
22
+ __standard_tag (ad. tag, x ))
18
23
jac_prototype = nothing
19
24
else
20
25
cache = ForwardColorJacCache (f, x, __chunksize (ad); coloring_result. colorvec,
@@ -29,7 +34,7 @@ function sparse_jacobian_cache(ad::Union{AutoSparseForwardDiff, AutoForwardDiff}
29
34
coloring_result = sd (ad, f!, fx, x)
30
35
if coloring_result isa NoMatrixColoring
31
36
cache = ForwardDiff. JacobianConfig (f!, fx, x, __chunksize (ad, x),
32
- ifelse (ad. tag === nothing , SparseDiffToolsTag (), ad . tag ))
37
+ __standard_tag (ad. tag, x ))
33
38
jac_prototype = nothing
34
39
else
35
40
cache = ForwardColorJacCache (f!, x, __chunksize (ad); coloring_result. colorvec,
@@ -44,7 +49,8 @@ function sparse_jacobian!(J::AbstractMatrix, _, cache::ForwardDiffJacobianCache,
44
49
if cache. cache isa ForwardColorJacCache
45
50
forwarddiff_color_jacobian (J, f, x, cache. cache) # Use Sparse ForwardDiff
46
51
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
48
54
end
49
55
return J
50
56
end
@@ -54,7 +60,8 @@ function sparse_jacobian!(J::AbstractMatrix, _, cache::ForwardDiffJacobianCache,
54
60
if cache. cache isa ForwardColorJacCache
55
61
forwarddiff_color_jacobian! (J, f!, x, cache. cache) # Use Sparse ForwardDiff
56
62
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
58
65
end
59
66
return J
60
67
end
0 commit comments