From 39fa42af99bd227a23423720a42c0edebc19312c Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 11 Dec 2023 08:19:31 +0100 Subject: [PATCH] cache troot --- python/sdist/amici/de_model.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/sdist/amici/de_model.py b/python/sdist/amici/de_model.py index 46163c2074..72ce4a95ba 100644 --- a/python/sdist/amici/de_model.py +++ b/python/sdist/amici/de_model.py @@ -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. @@ -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. @@ -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]