Skip to content

Commit

Permalink
Do not modify dict with substitutions in substitute with eval
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Mar 15, 2018
1 parent 80bece3 commit 09f8128
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions qctoolkit/utils/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def sympify(expr: Union[str, Number, sympy.Expr, numpy.str_], **kwargs) -> sympy
def substitute_with_eval(expression: sympy.Expr,
substitutions: Dict[str, Union[sympy.Expr, numpy.ndarray, str]]) -> sympy.Expr:
"""Substitutes only sympy.Symbols. Workaround for numpy like array behaviour. ~Factor 3 slower compared to subs"""
for k, v in substitutions.items():
if not isinstance(v, sympy.Expr):
substitutions[k] = sympify(v)
substitutions = {k: v if isinstance(v, sympy.Expr) else sympify(v)
for k, v in substitutions.items()}

for symbol in expression.free_symbols:
symbol_name = str(symbol)
Expand Down

0 comments on commit 09f8128

Please sign in to comment.