Skip to content

Commit bc3ec49

Browse files
re-arrange to highlight allocations
1 parent b72cd2e commit bc3ec49

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/jacobians.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ function _finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f,
3434
if typeof(fx) == Void
3535
fx = similar(x,returntype)
3636
end
37-
f(fx,x)
3837
# TODO: Remove these allocations
3938
fx2 = similar(x,returntype)
4039
shifted_x = copy(x)
4140
epsilon_factor = compute_epsilon_factor(Val{:forward}, epsilon_elemtype)
41+
f(fx,x)
4242
@inbounds for i in 1:n
4343
epsilon = compute_epsilon(Val{:forward}, x[i], epsilon_factor)
4444
shifted_x[i] += epsilon
@@ -96,13 +96,12 @@ function _finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f,
9696
if typeof(fx) == Void
9797
fx = similar(x,returntype)
9898
end
99-
f(fx,x)
10099
# TODO: Remove these allocations
101100
fx2 = similar(x,returntype)
102101
shifted_x = copy(x)
103102

104103
epsilon_factor = compute_epsilon_factor(Val{:forward}, epsilon_elemtype)
105-
104+
f(fx,x)
106105
@inbounds for i in 1:n
107106
epsilon = compute_epsilon(Val{:forward}, real(x[i]), epsilon_factor)
108107
shifted_x[i] += epsilon
@@ -148,9 +147,7 @@ function _finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f,
148147
m, n = size(J)
149148
epsilon_elemtype = compute_epsilon_elemtype(epsilon, x)
150149
if fdtype == Val{:forward}
151-
if typeof(fx) == Void
152-
fx = f(x)
153-
end
150+
fx = f(x)
154151
epsilon_factor = compute_epsilon_factor(Val{:forward}, epsilon_elemtype)
155152
shifted_x = copy(x)
156153
@inbounds for i in 1:n

0 commit comments

Comments
 (0)