Skip to content

Commit

Permalink
Fix error for taking inplace Jacobian for AbstractArray
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Aug 20, 2017
1 parent d21022e commit 63c18df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/finitediff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,19 @@ function finite_difference_jacobian!(J::AbstractArray{T}, f, x::AbstractArray{T}
# This is an inefficient fallback that only makes sense if setindex/getindex are unavailable, e.g. GPUArrays etc.
m, n = size(J)
epsilon_factor = compute_epsilon_factor(fdtype, T)
if t == Val{:forward}
if fdtype == Val{:forward}
shifted_x = copy(x)
for i in 1:n
epsilon = compute_epsilon(t, x[i], epsilon_factor)
shifted_x[i] += epsilon
J[:, i] .= (f(shifted_x) - f_x) / epsilon
shifted_x[i] = x[i]
end
elseif t == Val{:central}
elseif fdtype == Val{:central}
shifted_x_plus = copy(x)
shifted_x_minus = copy(x)
for i in 1:n
epsilon = compute_epsilon(t, x[i], epsilon_factor)
epsilon = compute_epsilon(fdtype, x[i], epsilon_factor)
shifted_x_plus[i] += epsilon
shifted_x_minus[i] -= epsilon
J[:, i] .= (f(shifted_x_plus) - f(shifted_x_minus)) / (epsilon + epsilon)
Expand Down

0 comments on commit 63c18df

Please sign in to comment.