Skip to content

Commit

Permalink
handle input containing division by zero better
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Dec 4, 2024
1 parent 48a678b commit 7f6eacd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ode-toolbox-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
with_gsl: ["0", "1"]
sympy_version: ["==1.4", ""] # empty string for "latest"
sympy_version: [""] # empty string for "latest"

steps:
- name: Checkout ODE-toolbox code
Expand Down
2 changes: 1 addition & 1 deletion odetoolbox/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import sympy
import sympy.parsing.sympy_parser

from sympy.core.expr import Expr as SympyExpr # works for both sympy 1.4 and 1.8
from sympy.core.expr import Expr as SympyExpr

from .config import Config
from .sympy_helpers import _check_numerical_issue, _check_forbidden_name, _custom_simplify_expr, _is_constant_term, _is_sympy_type, _is_zero
Expand Down
9 changes: 3 additions & 6 deletions odetoolbox/system_of_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,14 @@ def get_sub_system(self, symbols):


def _generate_propagator_matrix(self, A):
r"""Generate the propagator matrix by matrix exponentiation.
XXX: the default custom simplification expression does not work well with sympy 1.4 here. Consider replacing sympy.simplify() with _custom_simplify_expr() if sympy 1.4 support is dropped.
"""
r"""Generate the propagator matrix by matrix exponentiation."""

# naive: calculate propagators in one step
# P_naive = sympy.simplify(sympy.exp(A * sympy.Symbol(Config().output_timestep_symbol)))
# P_naive = _custom_simplify_expr(sympy.exp(A * sympy.Symbol(Config().output_timestep_symbol)))

# optimized: be explicit about block diagonal elements; much faster!
blocks = get_block_diagonal_blocks(np.array(A))
propagators = [sympy.simplify(sympy.exp(sympy.Matrix(block) * sympy.Symbol(Config().output_timestep_symbol))) for block in blocks]
propagators = [_custom_simplify_expr(sympy.exp(sympy.Matrix(block) * sympy.Symbol(Config().output_timestep_symbol))) for block in blocks]
P = sympy.Matrix(scipy.linalg.block_diag(*propagators))

# check the result
Expand Down

0 comments on commit 7f6eacd

Please sign in to comment.