-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3904 from firedrakeproject/connorjward/add-tsfc
Absorb TSFC into Firedrake
- Loading branch information
Showing
49 changed files
with
6,255 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
|
||
from gem import impero_utils | ||
from gem.gem import Index, Indexed, IndexSum, Product, Variable | ||
|
||
|
||
def test_loop_fusion(): | ||
i = Index() | ||
j = Index() | ||
Ri = Indexed(Variable('R', (6,)), (i,)) | ||
|
||
def make_expression(i, j): | ||
A = Variable('A', (6,)) | ||
s = IndexSum(Indexed(A, (j,)), (j,)) | ||
return Product(Indexed(A, (i,)), s) | ||
|
||
e1 = make_expression(i, j) | ||
e2 = make_expression(i, i) | ||
|
||
def gencode(expr): | ||
impero_c = impero_utils.compile_gem([(Ri, expr)], (i, j)) | ||
return impero_c.tree | ||
|
||
assert len(gencode(e1).children) == len(gencode(e2).children) | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
import sys | ||
pytest.main(args=[os.path.abspath(__file__)] + sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pytest | ||
|
||
from gem.gem import Index, Indexed, Product, Variable, Division, Literal, Sum | ||
from gem.optimise import replace_division | ||
from tsfc.coffee_mode import optimise_expressions | ||
|
||
|
||
def test_replace_div(): | ||
i = Index() | ||
A = Variable('A', ()) | ||
B = Variable('B', (6,)) | ||
Bi = Indexed(B, (i,)) | ||
d = Division(Bi, A) | ||
result, = replace_division([d]) | ||
expected = Product(Bi, Division(Literal(1.0), A)) | ||
|
||
assert result == expected | ||
|
||
|
||
def test_loop_optimise(): | ||
I = 20 | ||
J = K = 10 | ||
i = Index('i', I) | ||
j = Index('j', J) | ||
k = Index('k', K) | ||
|
||
A1 = Variable('a1', (I,)) | ||
A2 = Variable('a2', (I,)) | ||
A3 = Variable('a3', (I,)) | ||
A1i = Indexed(A1, (i,)) | ||
A2i = Indexed(A2, (i,)) | ||
A3i = Indexed(A3, (i,)) | ||
|
||
B = Variable('b', (J,)) | ||
C = Variable('c', (J,)) | ||
Bj = Indexed(B, (j,)) | ||
Cj = Indexed(C, (j,)) | ||
|
||
E = Variable('e', (K,)) | ||
F = Variable('f', (K,)) | ||
G = Variable('g', (K,)) | ||
Ek = Indexed(E, (k,)) | ||
Fk = Indexed(F, (k,)) | ||
Gk = Indexed(G, (k,)) | ||
|
||
Z = Variable('z', ()) | ||
|
||
# Bj*Ek + Bj*Fk => (Ek + Fk)*Bj | ||
expr = Sum(Product(Bj, Ek), Product(Bj, Fk)) | ||
result, = optimise_expressions([expr], (j, k)) | ||
expected = Product(Sum(Ek, Fk), Bj) | ||
assert result == expected | ||
|
||
# Bj*Ek + Bj*Fk + Bj*Gk + Cj*Ek + Cj*Fk => | ||
# (Ek + Fk + Gk)*Bj + (Ek+Fk)*Cj | ||
expr = Sum(Sum(Sum(Sum(Product(Bj, Ek), Product(Bj, Fk)), Product(Bj, Gk)), | ||
Product(Cj, Ek)), Product(Cj, Fk)) | ||
result, = optimise_expressions([expr], (j, k)) | ||
expected = Sum(Product(Sum(Sum(Ek, Fk), Gk), Bj), Product(Sum(Ek, Fk), Cj)) | ||
assert result == expected | ||
|
||
# Z*A1i*Bj*Ek + Z*A2i*Bj*Ek + A3i*Bj*Ek + Z*A1i*Bj*Fk => | ||
# Bj*(Ek*(Z*A1i + Z*A2i) + A3i) + Z*A1i*Fk) | ||
|
||
expr = Sum(Sum(Sum(Product(Z, Product(A1i, Product(Bj, Ek))), | ||
Product(Z, Product(A2i, Product(Bj, Ek)))), | ||
Product(A3i, Product(Bj, Ek))), | ||
Product(Z, Product(A1i, Product(Bj, Fk)))) | ||
result, = optimise_expressions([expr], (j, k)) | ||
expected = Product(Sum(Product(Ek, Sum(Sum(Product(Z, A1i), Product(Z, A2i)), A3i)), | ||
Product(Fk, Product(Z, A1i))), Bj) | ||
assert result == expected | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
import sys | ||
pytest.main(args=[os.path.abspath(__file__)] + sys.argv[1:]) |
Oops, something went wrong.