Skip to content

Commit c232484

Browse files
committed
Fix jacobian caching
1 parent 1275c9d commit c232484

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ end
1919

2020
function calculate_jacobian(sys::AbstractODESystem;
2121
sparse=false, simplify=false)
22-
isempty(get_jac(sys)[]) || return get_jac(sys)[] # use cached Jacobian, if possible
22+
cache = get_jac(sys)[]
23+
if cache isa Tuple && cache[2] == (sparse, simplify)
24+
return cache[1]
25+
end
2326
rhs = [eq.rhs for eq equations(sys)]
2427

2528
iv = get_iv(sys)
@@ -31,7 +34,7 @@ function calculate_jacobian(sys::AbstractODESystem;
3134
jac = jacobian(rhs, dvs, simplify=simplify)
3235
end
3336

34-
get_jac(sys)[] = jac # cache Jacobian
37+
get_jac(sys)[] = jac, (sparse, simplify) # cache Jacobian
3538
return jac
3639
end
3740

0 commit comments

Comments
 (0)