Skip to content

Commit 7b856bc

Browse files
vec for broadcast
1 parent 6d55a63 commit 7b856bc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/diffeqwrappers.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f, x::AbstractAr
1616
epsilon_elemtype = compute_epsilon_elemtype(epsilon, x)
1717
x1, fx1 = f.x1, f.fx1
1818
copy!(x1, x)
19+
vfx, vfx1 = vec(fx1),vec(fx)
1920
if fdtype == Val{:forward}
2021
epsilon_factor = compute_epsilon_factor(Val{:forward}, epsilon_elemtype)
2122
@inbounds for i 1:n
2223
epsilon = compute_epsilon(Val{:forward}, x[i], epsilon_factor)
2324
x1[i] += epsilon
2425
f(fx1, x1)
2526
f(fx, x)
26-
@. J[:,i] = (fx1 - fx) / epsilon
27+
@. J[:,i] = (vfx1 - vfx) / epsilon
2728
x1[i] -= epsilon
2829
end
2930
elseif fdtype == Val{:central}
@@ -34,7 +35,7 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f, x::AbstractAr
3435
x[i] -= epsilon
3536
f(fx1, x1)
3637
f(fx, x)
37-
@. J[:,i] = (fx1 - fx) / (2*epsilon)
38+
@. J[:,i] = (vfx1 - vfx) / (2*epsilon)
3839
x1[i] -= epsilon
3940
x[i] += epsilon
4041
end
@@ -61,14 +62,15 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f, x::Abstract
6162
epsilon_elemtype = compute_epsilon_elemtype(epsilon, x)
6263
x1, fx1 = f.x1, f.fx1
6364
copy!(x1, x)
65+
vfx, vfx1 = vec(fx1),vec(fx)
6466
if fdtype == Val{:forward}
6567
epsilon_factor = compute_epsilon_factor(Val{:forward}, epsilon_elemtype)
6668
@inbounds for i 1:n
6769
epsilon = compute_epsilon(Val{:forward}, real(x[i]), epsilon_factor)
6870
x1[i] += epsilon
6971
f(fx1, x1)
7072
f(fx, x)
71-
@. J[:,i] = ( real( (fx1 - fx) ) + im*imag( (fx1 - fx) ) ) / epsilon
73+
@. J[:,i] = ( real( (vfx1 - vfx) ) + im*imag( (vfx1 - vfx) ) ) / epsilon
7274
x1[i] -= epsilon
7375
end
7476
elseif fdtype == Val{:central}
@@ -79,7 +81,7 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f, x::Abstract
7981
x[i] -= epsilon
8082
f(fx1, x1)
8183
f(fx, x)
82-
@. J[:,i] = ( real( (fx1 - fx) ) + im*imag( fx1 - fx ) ) / (2*epsilon)
84+
@. J[:,i] = ( real( (vfx1 - vfx) ) + im*imag( vfx1 - vfx ) ) / (2*epsilon)
8385
x1[i] -= epsilon
8486
x[i] += epsilon
8587
end

0 commit comments

Comments
 (0)