Skip to content

Commit

Permalink
symbolics: evaluate transpose on elements of tensors in case of deriv…
Browse files Browse the repository at this point in the history
…ative
  • Loading branch information
mloubout committed Feb 27, 2023
1 parent a737e6c commit 988aad6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ def __init_finalize__(self, *args, **kwargs):
def doit(self, **hint):
return self

@property
def T(self):
new = super().T
return new.applyfunc(lambda x: getattr(x, 'T', x))

def _eval_matrix_mul(self, other):
"""
Copy paste from sympy to avoid explicit call to sympy.Add
Expand Down
8 changes: 8 additions & 0 deletions tests/test_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def test_vector_transpose(func1):
assert np.all([f1[i] == f2[i] for i in range(3)])


@pytest.mark.parametrize('func1', [VectorFunction, VectorTimeFunction])
def test_vector_transpose_deriv(func1):
grid = Grid(tuple([5]*3))
f1 = func1(name="f1", grid=grid)
f2 = f1.dx.T
assert all([f2[i] == f1[i].dx.T for i in range(3)])


@pytest.mark.parametrize('func1', [TensorFunction, TensorTimeFunction,
VectorFunction, VectorTimeFunction])
def test_tensor_fd(func1):
Expand Down

0 comments on commit 988aad6

Please sign in to comment.