11from enum import Enum
2+ from functools import lru_cache
23
34from cellmlmanip .model import Variable
45from sympy import (
@@ -26,6 +27,7 @@ class KINDS(Enum):
2627 NONLINEAR = 3
2728
2829
30+ @lru_cache (maxsize = 128 )
2931def _check_expr (expr , state_var , membrane_voltage_var , state_vars ):
3032 """Check the kind of expression given (NONE, LINEAR or NONLINEAR)
3133
@@ -38,6 +40,7 @@ def _check_expr(expr, state_var, membrane_voltage_var, state_vars):
3840 :param state_vars: the state variables in the model the expression comes from
3941 :return: the kind of expr (NONE, LINEAR or NONLINEAR)
4042 """
43+ @lru_cache (maxsize = 128 )
4144 def max_kind (state_var , operands ):
4245 result = KINDS .NONE
4346 for op in operands :
@@ -126,7 +129,7 @@ def get_non_linear_state_vars(derivative_equations, membrane_voltage_var, state_
126129 return set ([eq .lhs .args [0 ] for eq in derivative_equations
127130 if isinstance (eq .lhs , Derivative ) and
128131 eq .lhs .args [0 ] != membrane_voltage_var and
129- _check_expr (eq .rhs , eq .lhs .args [0 ], membrane_voltage_var , state_vars ) != KINDS .LINEAR ])
132+ _check_expr (eq .rhs , eq .lhs .args [0 ], membrane_voltage_var , tuple ( state_vars ) ) != KINDS .LINEAR ])
130133
131134
132135def subst_deriv_eqs_non_linear_vars (y_derivatives , non_linear_state_vars , membrane_voltage_var , state_vars ,
0 commit comments