Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 1 addition & 9 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,6 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
if i.is_Derived and i.parent in nodes]
toposort = DAG(nodes, edges).topological_sort()

futures = {}
for d in reversed(toposort):
if set(d._arg_names).intersection(kwargs):
futures.update(d._arg_values(self._dspace[d], args={}, **kwargs))

# Prepare to process data-carriers
args = kwargs['args'] = ReducerMap()

Expand Down Expand Up @@ -637,15 +632,12 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs):
for k, v in p._arg_values(estimate_memory=estimate_memory, **kwargs).items():
if k not in args:
args[k] = v
elif k in futures:
# An explicit override is later going to set `args[k]`
pass
elif k in kwargs:
# User is in control
# E.g., given a ConditionalDimension `t_sub` with factor `fact`
# and a TimeFunction `usave(t_sub, x, y)`, an override for
# `fact` is supplied w/o overriding `usave`; that's legal
pass
args[k] = args.unique(k, candidate=v)
elif is_integer(args[k]) and not contains_val(args[k], v):
raise InvalidArgument(
f"Default `{p}` is incompatible with other args as "
Expand Down
4 changes: 2 additions & 2 deletions devito/tools/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def update(self, values):
else:
self.extend(values)

def unique(self, key):
def unique(self, key, candidate=None):
"""
Returns a unique value for a given key, if such a value
exists, and raises a ``ValueError`` if it does not.
Expand All @@ -150,7 +150,7 @@ def unique(self, key):
Key for which to retrieve a unique value.
"""
candidates = self.getall(key)
candidates = [c for c in candidates if c is not None]
candidates = [c for c in candidates + [candidate] if c is not None]
if not candidates:
return None

Expand Down
3 changes: 2 additions & 1 deletion devito/types/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,8 @@ def _arg_defaults(self, _min=None, size=None, alias=None):
raise ValueError(f"Incompatible size for ConditionalDimension "
f"{self.name}: {size} < {size0}")
else:
defaults[dim.parent.max_name] = range(d0, d0 + factor*size - 1)
# Given a factor the last time index is factor*(size - 1)
defaults[dim.parent.max_name] = range(d0, d0 + factor*(size - 1) + 1)

return defaults

Expand Down
28 changes: 28 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,34 @@ def test_loose_kwargs(self):
# But the following should work perfectly fine
op.arguments(x_size=2, y_size=2)

@pytest.mark.parametrize('vfact', [1, 3, 4])
def test_apply_args_consitency(self, vfact):
nt = 201
grid = Grid(shape=(11, 11, 11))
time = grid.time_dim

u = TimeFunction(name='u', grid=grid, time_order=2, space_order=4)
rec = SparseTimeFunction(name='rec', grid=grid, npoint=1, nt=nt)

factor = Constant(name='factor', value=vfact, dtype=np.int32)
time_sub = ConditionalDimension(name='t_sub', parent=time, factor=factor)
usave = TimeFunction(name='usave', grid=grid, space_order=4, time_order=0,
save=nt, time_dim=time_sub)

eqns = [
Eq(u.forward, u + 1),
Eq(usave, u),
] + rec.interpolate(expr=u)

op = Operator(eqns, opt='noop')
args0 = op.arguments(time_m=0, time_M=nt-2)
args1 = op.arguments(time_m=0, time_M=nt-2, rec=rec, usave=usave)

for k, v in args0.items():
assert k in args1
if isinstance(v, int):
assert args1[k] == v


@skipif('device')
class TestDeclarator:
Expand Down
Loading