Skip to content

Commit

Permalink
compiler: Fix unexpansion of tensor objects
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Sep 18, 2023
1 parent 37be2e5 commit 7ca7177
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion devito/types/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ def is_diagonal(self):
for i in range(self.rows) if i != j])

def _evaluate(self, **kwargs):
return self.applyfunc(lambda x: getattr(x, 'evaluate', x))
def _do_evaluate(x):
try:
expand = kwargs.get('expand', True)
return x._evaluate(expand=expand)
except AttributeError:
return x
return self.applyfunc(_do_evaluate)

def values(self):
if self.is_diagonal:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,16 @@ def test_transpose(self):
i0, = term.dimensions
assert term.base == f.subs(x, x + i0*h_x)

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

f = Function(name='f', grid=grid, space_order=4)

v = grad(f)._evaluate(expand=False)

assert all(isinstance(i, IndexDerivative) for i in v)
assert all(zip([Add(*i.args) for i in grad(f).evaluate], v.evaluate))


def bypass_uneval(expr):
unevals = expr.find(EvalDerivative)
Expand Down

0 comments on commit 7ca7177

Please sign in to comment.