Skip to content

Commit 33df902

Browse files
authored
Fix redundant computation in deltasx (#2814)
In case of no state update, `deltaxdot * stau` was computed twice.
1 parent 71da562 commit 33df902

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

python/sdist/amici/de_model.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,11 +1727,8 @@ def _compute_equation(self, name: str) -> None:
17271727

17281728
# need to check if equations are zero since we are using
17291729
# symbols
1730-
1731-
if (
1732-
not smart_is_zero_matrix(self.eq("stau")[ie])
1733-
and not xdot_is_zero
1734-
):
1730+
stau_is_zero = smart_is_zero_matrix(self.eq("stau")[ie])
1731+
if not stau_is_zero and not xdot_is_zero:
17351732
tmp_eq += smart_multiply(
17361733
self.sym("xdot") - self.sym("xdot_old"),
17371734
self.sym("stau").T,
@@ -1747,7 +1744,7 @@ def _compute_equation(self, name: str) -> None:
17471744

17481745
# need to check if equations are zero since we are using
17491746
# symbols
1750-
if not smart_is_zero_matrix(self.eq("stau")[ie]):
1747+
if not stau_is_zero:
17511748
# chain rule for the time point
17521749
tmp_eq += smart_multiply(
17531750
self.eq("ddeltaxdt")[ie],
@@ -1766,12 +1763,6 @@ def _compute_equation(self, name: str) -> None:
17661763
+ self.eq("ddeltaxdx_old")[ie],
17671764
tmp_dxdp,
17681765
)
1769-
1770-
elif not xdot_is_zero:
1771-
tmp_eq = smart_multiply(
1772-
self.sym("xdot") - self.sym("xdot_old"),
1773-
self.eq("stau")[ie],
1774-
)
17751766
event_eqs.append(tmp_eq)
17761767

17771768
self._eqs[name] = event_eqs

0 commit comments

Comments
 (0)