Skip to content

Commit

Permalink
cache troot
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Dec 11, 2023
1 parent be29447 commit 39fa42a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/sdist/amici/de_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ def __init__(
self._state_update = state_update
self._initial_value = initial_value

# expression(s) for the timepoint(s) at which the event triggers
self._t_root = sp.solve(self.get_val(), amici_time_symbol)

def get_initial_value(self) -> bool:
"""
Return the initial value for the root function.
Expand All @@ -717,10 +720,9 @@ def __eq__(self, other):

def triggers_at_fixed_timepoint(self) -> bool:
"""Check whether the event triggers at a (single) fixed time-point."""
t_root = sp.solve(self.get_val(), amici_time_symbol)
if len(t_root) != 1:
if len(self._t_root) != 1:
return False
return t_root[0].is_Number
return self._t_root[0].is_Number

def get_trigger_time(self) -> sp.Float:
"""Get the time at which the event triggers.
Expand All @@ -731,4 +733,4 @@ def get_trigger_time(self) -> sp.Float:
raise NotImplementedError(
"This event does not trigger at a fixed timepoint."
)
return sp.solve(self.get_val(), amici_time_symbol)[0]
return self._t_root[0]

0 comments on commit 39fa42a

Please sign in to comment.