-
Notifications
You must be signed in to change notification settings - Fork 231
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
compiler: Fix placement of ConditionalDimension in subdomain #2050
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
from conftest import opts_tiling, assert_structure | ||
from devito import (ConditionalDimension, Constant, Grid, Function, TimeFunction, | ||
Eq, solve, Operator, SubDomain, SubDomainSet) | ||
Eq, solve, Operator, SubDomain, SubDomainSet, Lt) | ||
from devito.ir import FindNodes, Expression, Iteration | ||
from devito.tools import timed_region | ||
|
||
|
@@ -693,3 +693,101 @@ class Dummy(SubDomainSet): | |
# Switch the thickness symbols between MultiSubDimensions with the rebuild | ||
remixed = [d._rebuild(thickness=t) for d, t in zip(sdims, tkns[::-1])] | ||
assert [d.thickness for d in remixed] == tkns[::-1] | ||
|
||
|
||
class TestSubDomain_w_condition(object): | ||
|
||
def test_condition_w_subdomain_v0(self): | ||
|
||
shape = (10, ) | ||
grid = Grid(shape=shape) | ||
x, = grid.dimensions | ||
|
||
class Middle(SubDomain): | ||
name = 'middle' | ||
|
||
def define(self, dimensions): | ||
return {x: ('middle', 2, 4)} | ||
|
||
mid = Middle() | ||
my_grid = Grid(shape=shape, subdomains=(mid, )) | ||
|
||
f = Function(name='f', grid=my_grid) | ||
|
||
sdf = Function(name='sdf', grid=my_grid) | ||
sdf.data[5:] = 1 | ||
|
||
condition = Lt(sdf[mid.dimensions[0]], 1) | ||
|
||
ci = ConditionalDimension(name='ci', condition=condition, | ||
parent=mid.dimensions[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mid.dimensions[0] is a root dimension already, do we actually need this test? IOW, would this test actually fail in current master? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
op = Operator(Eq(f, f + 10, implicit_dims=ci, | ||
subdomain=my_grid.subdomains['middle'])) | ||
op.apply() | ||
|
||
assert_structure(op, ['x'], 'x') | ||
|
||
def test_condition_w_subdomain_v1(self): | ||
|
||
shape = (10, 10) | ||
grid = Grid(shape=shape) | ||
x, y = grid.dimensions | ||
|
||
class Middle(SubDomain): | ||
name = 'middle' | ||
|
||
def define(self, dimensions): | ||
return {x: x, y: ('middle', 2, 4)} | ||
|
||
mid = Middle() | ||
my_grid = Grid(shape=shape, subdomains=(mid, )) | ||
|
||
sdf = Function(name='sdf', grid=grid) | ||
sdf.data[:, 5:] = 1 | ||
sdf.data[2:6, 3:5] = 1 | ||
|
||
x1, y1 = mid.dimensions | ||
|
||
condition = Lt(sdf[x1, y1], 1) | ||
ci = ConditionalDimension(name='ci', condition=condition, parent=y1) | ||
|
||
f = Function(name='f', grid=my_grid) | ||
op = Operator(Eq(f, f + 10, implicit_dims=ci, | ||
subdomain=my_grid.subdomains['middle'])) | ||
|
||
op.apply() | ||
|
||
assert_structure(op, ['xy'], 'xy') | ||
|
||
def test_condition_w_subdomain_v2(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mloubout could you help sketching a test about what you mention as the conditional being the indexing dimension? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok sorry after bit of digging, forgot this algorithm section is only for non indirect (see line 223 in algorithms.py) GTG There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah right, this is what happens if I have long time to see a PR |
||
|
||
shape = (10, 10) | ||
grid = Grid(shape=shape) | ||
x, y = grid.dimensions | ||
|
||
class Middle(SubDomain): | ||
name = 'middle' | ||
|
||
def define(self, dimensions): | ||
return {x: ('middle', 2, 4), y: ('middle', 2, 4)} | ||
|
||
mid = Middle() | ||
my_grid = Grid(shape=shape, subdomains=(mid, )) | ||
|
||
sdf = Function(name='sdf', grid=my_grid) | ||
sdf.data[2:4, 5:] = 1 | ||
sdf.data[2:6, 3:5] = 1 | ||
|
||
x1, y1 = mid.dimensions | ||
|
||
condition = Lt(sdf[x1, y1], 1) | ||
ci = ConditionalDimension(name='ci', condition=condition, parent=y1) | ||
|
||
f = Function(name='f', grid=my_grid) | ||
op = Operator(Eq(f, f + 10, implicit_dims=ci, | ||
subdomain=my_grid.subdomains['middle'])) | ||
|
||
op.apply() | ||
|
||
assert_structure(op, ['xy'], 'xy') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
flag=cd.indirect
for the case where the conditional is used as the indexing dimension