Skip to content

Commit cc57b00

Browse files
Merge pull request #167 from JuliaDiff/inline
Remove inline and specialize the function evaluations
2 parents 09bc8b1 + 95a104f commit cc57b00

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ function generate_chunked_partials(x,colorvec,::Val{chunksize}) where chunksize
7979
chunked_partials
8080
end
8181

82-
@inline function forwarddiff_color_jacobian(f,
82+
function forwarddiff_color_jacobian(f::F,
8383
x::AbstractArray{<:Number};
8484
colorvec = 1:length(x),
8585
sparsity = nothing,
8686
jac_prototype = nothing,
8787
chunksize = nothing,
88-
dx = sparsity === nothing && jac_prototype === nothing ? nothing : copy(x)) #if dx is nothing, we will estimate dx at the cost of a function call
88+
dx = sparsity === nothing && jac_prototype === nothing ? nothing : copy(x)) where {F} #if dx is nothing, we will estimate dx at the cost of a function call
8989

9090
if sparsity === nothing && jac_prototype === nothing
9191
cfg = if chunksize === nothing
@@ -95,7 +95,7 @@ end
9595
ForwardDiff.JacobianConfig(f, x)
9696
end
9797
else
98-
ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk(getsize(chunksize)))
98+
ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk{getsize(chunksize)}())
9999
end
100100
return ForwardDiff.jacobian(f, x, cfg)
101101
end
@@ -105,21 +105,21 @@ end
105105
return forwarddiff_color_jacobian(f,x,ForwardColorJacCache(f,x,chunksize,dx=dx,colorvec=colorvec,sparsity=sparsity),jac_prototype)
106106
end
107107

108-
@inline function forwarddiff_color_jacobian(J::AbstractArray{<:Number}, f,
108+
function forwarddiff_color_jacobian(J::AbstractArray{<:Number}, f::F,
109109
x::AbstractArray{<:Number};
110110
colorvec = 1:length(x),
111111
sparsity = nothing,
112112
jac_prototype = nothing,
113113
chunksize = nothing,
114-
dx = similar(x, size(J, 1))) #dx kwarg can be used to avoid re-allocating dx every time
114+
dx = similar(x, size(J, 1))) where {F} #dx kwarg can be used to avoid re-allocating dx every time
115115
if sparsity === nothing && jac_prototype === nothing
116116
cfg = chunksize === nothing ? ForwardDiff.JacobianConfig(f, x) : ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk(getsize(chunksize)))
117117
return ForwardDiff.jacobian(f, x, cfg)
118118
end
119119
return forwarddiff_color_jacobian(J,f,x,ForwardColorJacCache(f,x,chunksize,dx=dx,colorvec=colorvec,sparsity=sparsity))
120120
end
121121

122-
function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::ForwardColorJacCache,jac_prototype=nothing)
122+
function forwarddiff_color_jacobian(f::F,x::AbstractArray{<:Number},jac_cache::ForwardColorJacCache,jac_prototype=nothing) where F
123123

124124
if jac_prototype isa Nothing ? ArrayInterface.ismutable(x) : ArrayInterface.ismutable(jac_prototype)
125125
# Whenever J is mutable, we mutate it to avoid allocations
@@ -136,7 +136,7 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
136136
end
137137

138138
# When J is mutable, this version of forwarddiff_color_jacobian will mutate J to avoid allocations
139-
function forwarddiff_color_jacobian(J::AbstractMatrix{<:Number},f,x::AbstractArray{<:Number},jac_cache::ForwardColorJacCache)
139+
function forwarddiff_color_jacobian(J::AbstractMatrix{<:Number},f::F,x::AbstractArray{<:Number},jac_cache::ForwardColorJacCache) where F
140140
t = jac_cache.t
141141
dx = jac_cache.dx
142142
p = jac_cache.p

test/test_acyclic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Graphs: SimpleGraph
44
using Test
55

66
using Random
7-
Random.seed!(100)
7+
Random.seed!(90)
88

99
# println("Starting acyclic coloring test...")
1010
#= Test data =#

0 commit comments

Comments
 (0)