This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
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 #95 from firedrakeproject/conditional-simplification
* conditional-simplification: Add test of simplification in Conditional gem: Simplification in Conditional
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import absolute_import, print_function, division | ||
|
||
import pytest | ||
|
||
from gem.gem import Variable, Zero, Conditional, \ | ||
LogicalAnd, Index, Indexed, Product | ||
|
||
|
||
def test_conditional_simplification(): | ||
a = Variable("A", ()) | ||
b = Variable("B", ()) | ||
|
||
expr = Conditional(LogicalAnd(b, a), a, a) | ||
|
||
assert expr == a | ||
|
||
|
||
def test_conditional_zero_folding(): | ||
b = Variable("B", ()) | ||
a = Variable("A", (3, )) | ||
i = Index() | ||
expr = Conditional(LogicalAnd(b, b), | ||
Product(Indexed(a, (i, )), | ||
Zero()), | ||
Zero()) | ||
|
||
assert expr == Zero() | ||
|
||
|
||
if __name__ == "__main__": | ||
import os | ||
import sys | ||
pytest.main(args=[os.path.abspath(__file__)] + sys.argv[1:]) |