Skip to content

Commit 669b37d

Browse files
committed
compiler: Fixup AbstractSymbol._subs
1 parent 08cfd37 commit 669b37d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

devito/types/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def _subs(self, old, new, **hints):
497497
devito subclasses of sympy types are quite strict.
498498
"""
499499
try:
500-
if old.name == self.name:
500+
if old.is_Symbol and old.name == self.name:
501501
return new
502502
except AttributeError:
503503
pass

tests/test_symbolics.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ def test_safeinv():
375375
assert 'SAFEINV' in str(op1)
376376
assert 'SAFEINV' in str(op2)
377377

378+
# Ensure .subs leaves the caller unchanged if no substitutions occur.
379+
# We used to have a bug where passing SafeInv to .subs would result
380+
# in the construction of weird, nonsensical objects due to the _subs
381+
# stub in types.AbstractSymbol
382+
f = Function(name='f', grid=grid)
383+
ui = u1.indexify()
384+
safeinv = SafeInv(ui, ui)
385+
v = ui._subs(safeinv, f.indexify())
386+
assert str(v) == 'u[x, y]'
387+
378388

379389
def test_def_function():
380390
foo0 = DefFunction('foo', arguments=['a', 'b'], template=['int'])

0 commit comments

Comments
 (0)