forked from FEniCS/fiat
-
Notifications
You must be signed in to change notification settings - Fork 7
GEM: Simplify Indexed tensors #131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
de501c1
GEM: simplify indexed
pbrubeck 592061e
Fixes for more complicated expressions
pbrubeck 03e9ae6
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck 158b0ec
small change
pbrubeck d2a4584
More simplification
pbrubeck b49eb5c
Do not replace free indices
pbrubeck 340ec40
Simplify IndexSum
pbrubeck a7fda02
Refactor IndexSum unrolling
pbrubeck eab0d90
Flatten nested ComponentTensors
pbrubeck 41981ec
use numpy.array_equal
pbrubeck 7f58028
Simplify ListTensor(ComponentTensor(Indexed(...)))
pbrubeck 7077cf9
Some indices fixed
pbrubeck 55bb313
style
pbrubeck 10a8604
Add tests
pbrubeck b738ec6
More simplify
pbrubeck 830a0e3
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck 5dfd17d
Fix up
pbrubeck 3fe803d
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck c0a6e02
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck f9c5d2b
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck 8d0dc41
expand_fixedindices DAG traverser
pbrubeck 40a7dc7
fix
pbrubeck 2fea3ff
restore Indexed.__new__
pbrubeck ca7f2f0
Remove fixed indices within remove_componenttensors
pbrubeck ff2c664
fix
pbrubeck aab3a94
fixes
pbrubeck f5d7959
Merge branch 'main' into pbrubeck/simplify-indexed
pbrubeck 04f0cf3
review comments
pbrubeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| import pytest | ||
| import gem | ||
| import numpy | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def A(): | ||
| a = gem.Variable("a", ()) | ||
| b = gem.Variable("b", ()) | ||
| c = gem.Variable("c", ()) | ||
| d = gem.Variable("d", ()) | ||
| array = [[a, b], [c, d]] | ||
| A = gem.ListTensor(array) | ||
| return A | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def X(): | ||
| return gem.Variable("X", (2, 2)) | ||
|
|
||
|
|
||
| def test_listtensor_from_indexed(X): | ||
| k = gem.Index() | ||
| elems = [gem.Indexed(X, (k, *i)) for i in numpy.ndindex(X.shape[1:])] | ||
| tensor = gem.ListTensor(numpy.reshape(elems, X.shape[1:])) | ||
|
|
||
| assert isinstance(tensor, gem.ComponentTensor) | ||
| j = tensor.multiindex | ||
| expected = gem.partial_indexed(X, (k,)) | ||
| expected = gem.ComponentTensor(gem.Indexed(expected, j), j) | ||
| assert tensor == expected | ||
|
|
||
|
|
||
| def test_listtensor_from_fixed_indexed(A): | ||
| elems = [gem.Indexed(A, i) for i in numpy.ndindex(A.shape)] | ||
| tensor = gem.ListTensor(numpy.reshape(elems, A.shape)) | ||
| assert tensor == A | ||
|
|
||
|
|
||
| def test_listtensor_from_partial_indexed(A): | ||
| elems = [gem.partial_indexed(A, i) for i in numpy.ndindex(A.shape[:1])] | ||
| tensor = gem.ListTensor(elems) | ||
| assert tensor == A | ||
|
|
||
|
|
||
| def test_nested_partial_indexed(A): | ||
| i, j = gem.indices(2) | ||
| B = gem.partial_indexed(gem.partial_indexed(A, (i,)), (j,)) | ||
| assert B == gem.Indexed(A, (i, j)) | ||
|
|
||
|
|
||
| def test_componenttensor_from_indexed(A): | ||
| i, j = gem.indices(2) | ||
| Aij = gem.Indexed(A, (i, j)) | ||
| assert A == gem.ComponentTensor(Aij, (i, j)) | ||
|
|
||
|
|
||
| def test_indexed_transpose(A): | ||
| i, j = gem.indices(2) | ||
| ATij = gem.Indexed(A.T, (i, j)) | ||
| Aji = gem.Indexed(A, (j, i)) | ||
| assert ATij == Aji | ||
|
|
||
| i, = gem.indices(1) | ||
| j = 1 | ||
| ATij = gem.Indexed(A.T, (i, j)) | ||
| Aji = gem.Indexed(A, (j, i)) | ||
| assert ATij == Aji | ||
|
|
||
| i, j = (0, 1) | ||
| ATij = gem.Indexed(A.T, (i, j)) | ||
| Aji = gem.Indexed(A, (j, i)) | ||
| assert ATij == Aji | ||
|
|
||
|
|
||
| def test_double_transpose(A): | ||
| assert A.T.T == A | ||
|
|
||
|
|
||
| def test_flatten_indexsum(A): | ||
| i, j = gem.indices(2) | ||
| Aij = gem.Indexed(A, (i, j)) | ||
|
|
||
| result = gem.IndexSum(gem.IndexSum(Aij, (i,)), (j,)) | ||
| expected = gem.IndexSum(Aij, (i, j)) | ||
| assert result == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.