Skip to content

Commit 2235c62

Browse files
Merge pull request #123 from andrewning/nonsquare
minor fix for nonsquare, sparse, inplace jacobians
2 parents f75429e + da00fa4 commit 2235c62

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/jacobians.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ function finite_difference_jacobian!(
373373
# Now return x1 back to its original value
374374
ArrayInterface.allowed_setindex!(x1, x1_save, color_i)
375375
else # Perturb along the colorvec vector
376-
@. fx1 = x1 * (_color == color_i)
377-
tmp = norm(fx1)
376+
idx = findfirst(isequal(color_i), _color)
377+
tmp = norm(x1[idx])
378378
epsilon = compute_epsilon(Val(:forward), sqrt(tmp), relstep, absstep, dir)
379379
@. x1 = x1 + epsilon * (_color == color_i)
380380
f(fx1, x1)
@@ -416,8 +416,8 @@ function finite_difference_jacobian!(
416416
@. J[:,color_i] = (vfx1 - vfx) / 2epsilon
417417
ArrayInterface.allowed_setindex!(x1, x_save, color_i)
418418
else # Perturb along the colorvec vector
419-
@. fx1 = x1 * (_color == color_i)
420-
tmp = norm(fx1)
419+
idx = findfirst(isequal(color_i), _color)
420+
tmp = norm(x1[idx])
421421
epsilon = compute_epsilon(Val(:central), sqrt(tmp), relstep, absstep, dir)
422422
@. x1 = x1 + epsilon * (_color == color_i)
423423
@. x = x - epsilon * (_color == color_i)

0 commit comments

Comments
 (0)