Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slate: Transpose(Tensor(form)) -> Tensor(adjoint(form)) #2272

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firedrake/slate/slac/optimise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from itertools import repeat
from firedrake.slate.slate import *
from collections import namedtuple
from firedrake.ufl_expr import adjoint

""" ActionBag class
:arg coeff: what we contract with.
Expand Down Expand Up @@ -235,6 +236,8 @@ def _drop_double_transpose_transpose(expr, self):
if isinstance(child, Transpose):
grandchild, = child.children
return self(grandchild)
elif child.terminal and child.rank > 1:
return Tensor(adjoint(child.form))
wence- marked this conversation as resolved.
Show resolved Hide resolved
else:
return type(expr)(*map(self, expr.children))

Expand Down
7 changes: 7 additions & 0 deletions tests/slate/test_optimise.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ def test_drop_transposes(TC_non_symm):
compare_vector_expressions(expressions)
compare_slate_tensors(expressions, opt_expressions)

assert A != A.T
from firedrake.slate.slac.optimise import optimise
T_opt = optimise(A.T, {"optimise": True})
assert isinstance(T_opt, Tensor)
assert np.allclose(assemble(T_opt.T).M.values,
assemble(adjoint(T_opt.form)).M.values)


#######################################
# Test diagonal optimisation pass
Expand Down