Skip to content

Commit

Permalink
api: prevent derivative shortcut with incompatible fd order
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Oct 31, 2023
1 parent d4ebfa9 commit cf85b06
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ def is_TimeDependent(self):

@cached_property
def _fd(self):
return dict(ChainMap(*[getattr(i, '_fd', {}) for i in self._args_diff]))
# Filter out all args with fd order too high
fd_args = []
for f in self._args_diff:
try:
if f.space_order <= self.space_order and f.time_order <= self.time_order:
fd_args.append(f)
except AttributeError:
pass
return dict(ChainMap(*[getattr(i, '_fd', {}) for i in fd_args]))

@cached_property
def _symbolic_functions(self):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,21 @@ def test_all_shortcuts(self, so):
for fd in g._fd:
assert getattr(g, fd)

for d in grid.dimensions:
assert 'd%s' % d.name in f._fd
assert 'd%s' % d.name in g._fd
for o in range(2, min(7, so+1)):
assert 'd%s%s' % (d.name, o) in f._fd
assert 'd%s%s' % (d.name, o) in g._fd

def test_shortcuts_mixed(self):
grid = Grid(shape=(10,))
f = Function(name='f', grid=grid, space_order=2)
g = Function(name='g', grid=grid, space_order=4)
assert 'dx4' not in (f*g)._fd
assert 'dx4' not in (f+g)._fd
assert 'dx4' not in (g*f.dx)._fd

def test_transpose_simple(self):
grid = Grid(shape=(4, 4))

Expand Down

0 comments on commit cf85b06

Please sign in to comment.