Skip to content

Commit 6dd73e4

Browse files
committed
Use forwarddiff_color_jacobian when x is immutableby using the oop version instead of calling ForwardDiff.
1 parent f040740 commit 6dd73e4

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@ end
6868
jac_prototype = nothing,
6969
chunksize = nothing,
7070
dx = sparsity === nothing && jac_prototype === nothing ? nothing : copy(x)) #if dx is nothing, we will estimate dx at the cost of a function call
71-
@show typeof(x)
7271

73-
if sparsity === nothing && jac_prototype === nothing || !ArrayInterface.ismutable(x)
72+
if sparsity === nothing && jac_prototype === nothing
7473
cfg = chunksize === nothing ? ForwardDiff.JacobianConfig(f, x) : ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk(getsize(chunksize)))
7574
return ForwardDiff.jacobian(f, x, cfg)
7675
end
7776
if dx isa Nothing
7877
dx = f(x)
7978
end
80-
@show "Line 80"
8179
forwarddiff_color_jacobian(f,x,ForwardColorJacCache(f,x,chunksize,dx=dx,colorvec=colorvec,sparsity=sparsity),jac_prototype)
8280
end
8381

@@ -88,12 +86,11 @@ end
8886
jac_prototype = nothing,
8987
chunksize = nothing,
9088
dx = similar(x, size(J, 1))) #dx kwarg can be used to avoid re-allocating dx every time
91-
if sparsity === nothing && jac_prototype === nothing || !ArrayInterface.ismutable(x)
89+
if sparsity === nothing && jac_prototype === nothing
9290
cfg = chunksize === nothing ? ForwardDiff.JacobianConfig(f, x) : ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk(getsize(chunksize)))
9391
return ForwardDiff.jacobian(f, x, cfg)
9492
end
95-
@show "Line 95"
96-
forwarddiff_color_jacobian(J,f,x,ForwardColorJacCache(f,x,chunksize,dx=dx,colorvec=colorvec,sparsity=sparsity),jac_prototype)
93+
forwarddiff_color_jacobian(J,f,x,ForwardColorJacCache(f,x,chunksize,dx=dx,colorvec=colorvec,sparsity=sparsity))
9794
end
9895

9996
function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::ForwardColorJacCache,jac_prototype=nothing)
@@ -103,13 +100,10 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
103100

104101
J = jac_prototype isa Nothing ? (sparsity isa Nothing ? false .* vec(dx) .* vecx' : zeros(eltype(x),size(sparsity))) : zero(jac_prototype)
105102

106-
@show typeof(J)
107103
if ArrayInterface.ismutable(J) # Whenever J is mutable, we mutate it to avoid allocations
108-
@show "Line 108"
109-
forwarddiff_color_jacobian(J, f, x, jac_cache, jac_prototype)
104+
forwarddiff_color_jacobian(J, f, x, jac_cache)
110105
else
111-
@show "Line 111"
112-
forwarddiff_color_jacobian_immutable(J, f, x, jac_cache, jac_prototype)
106+
forwarddiff_color_jacobian_immutable(J, f, x, jac_cache)
113107
end
114108
end
115109

0 commit comments

Comments
 (0)