Skip to content

Commit ef5eeaf

Browse files
committed
Revert "semi-simultaneous, no reverse"
This reverts commit 3ccf621.
1 parent e23b656 commit ef5eeaf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

python/sdist/amici/importers/utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def smart_subs_dict(
399399
sym: sp.Expr,
400400
subs: SymbolDef,
401401
field: str | None = None,
402+
reverse: bool = True,
402403
) -> sp.Expr:
403404
"""
404405
Substitutes expressions completely flattening them out. Requires
@@ -413,16 +414,27 @@ def smart_subs_dict(
413414
:param field:
414415
Field of substitution expressions in subs.values(), if applicable
415416
417+
:param reverse:
418+
Whether ordering in subs should be reversed. Note that substitution
419+
requires the reverse order of what is required for evaluation.
420+
416421
:return:
417422
Substituted symbolic expression
418423
"""
419424
if field is None:
420-
s = {eid: expr for eid, expr in subs.items()}
425+
s = [(eid, expr) for eid, expr in subs.items()]
421426
else:
422-
s = {eid: expr[field] for eid, expr in subs.items()}
427+
s = [(eid, expr[field]) for eid, expr in subs.items()]
428+
429+
if reverse:
430+
s.reverse()
423431

424432
with sp.evaluate(False):
425-
sym = sym.subs(s, simultaneous=False)
433+
for old, new in s:
434+
# note that substitution may change free symbols, so we have to do
435+
# this recursively
436+
if sym.has(old):
437+
sym = sym.xreplace({old: new})
426438

427439
return sym
428440

0 commit comments

Comments
 (0)