Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit b4b816b

Browse files
Merge pull request #266 from avik-pal/ap/tstable
Pass Tag and Chunksize from the types
2 parents 11ce18a + ad2b150 commit b4b816b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseDiffTools"
22
uuid = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
33
authors = ["Pankaj Mishra <pankajmishra1511@gmail.com>", "Chris Rackauckas <contact@chrisrackauckas.com>"]
4-
version = "2.8.0"
4+
version = "2.9.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/highlevel/common.jl

+5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ function init_jacobian end
240240
const __init_𝒥 = init_jacobian
241241

242242
# Misc Functions
243+
function __chunksize(::AutoSparseForwardDiff{C}, x) where {C}
244+
return C === nothing ? ForwardDiff.Chunk(x) : C
245+
end
243246
__chunksize(::AutoSparseForwardDiff{C}) where {C} = C
247+
__chunksize(::AutoForwardDiff{C}, x) where {C} = C === nothing ? ForwardDiff.Chunk(x) : C
248+
__chunksize(::AutoForwardDiff{C}) where {C} = C
244249

245250
__f̂(f, x, idxs) = dot(vec(f(x)), idxs)
246251

src/highlevel/forward_mode.jl

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ struct ForwardDiffJacobianCache{CO, CA, J, FX, X} <: AbstractMaybeSparseJacobian
66
x::X
77
end
88

9+
struct SparseDiffToolsTag end
10+
911
function sparse_jacobian_cache(ad::Union{AutoSparseForwardDiff, AutoForwardDiff},
1012
sd::AbstractMaybeSparsityDetection, f, x; fx = nothing)
1113
coloring_result = sd(ad, f, x)
1214
fx = fx === nothing ? similar(f(x)) : fx
1315
if coloring_result isa NoMatrixColoring
14-
cache = ForwardDiff.JacobianConfig(f, x)
16+
cache = ForwardDiff.JacobianConfig(f, x, __chunksize(ad, x),
17+
ifelse(ad.tag === nothing, SparseDiffToolsTag(), ad.tag))
1518
jac_prototype = nothing
1619
else
1720
cache = ForwardColorJacCache(f, x, __chunksize(ad); coloring_result.colorvec,
18-
dx = fx,
19-
sparsity = coloring_result.jacobian_sparsity)
21+
dx = fx, sparsity = coloring_result.jacobian_sparsity, ad.tag)
2022
jac_prototype = coloring_result.jacobian_sparsity
2123
end
2224
return ForwardDiffJacobianCache(coloring_result, cache, jac_prototype, fx, x)
@@ -26,11 +28,12 @@ function sparse_jacobian_cache(ad::Union{AutoSparseForwardDiff, AutoForwardDiff}
2628
sd::AbstractMaybeSparsityDetection, f!, fx, x)
2729
coloring_result = sd(ad, f!, fx, x)
2830
if coloring_result isa NoMatrixColoring
29-
cache = ForwardDiff.JacobianConfig(f!, fx, x)
31+
cache = ForwardDiff.JacobianConfig(f!, fx, x, __chunksize(ad, x),
32+
ifelse(ad.tag === nothing, SparseDiffToolsTag(), ad.tag))
3033
jac_prototype = nothing
3134
else
3235
cache = ForwardColorJacCache(f!, x, __chunksize(ad); coloring_result.colorvec,
33-
dx = fx, sparsity = coloring_result.jacobian_sparsity)
36+
dx = fx, sparsity = coloring_result.jacobian_sparsity, ad.tag)
3437
jac_prototype = coloring_result.jacobian_sparsity
3538
end
3639
return ForwardDiffJacobianCache(coloring_result, cache, jac_prototype, fx, x)

0 commit comments

Comments
 (0)