diff --git a/devito/tools/data_structures.py b/devito/tools/data_structures.py index 01a9a3f4bd..61bb7f5257 100644 --- a/devito/tools/data_structures.py +++ b/devito/tools/data_structures.py @@ -111,6 +111,8 @@ def unique(self, key): """ candidates = self.getall(key) candidates = [c for c in candidates if c is not None] + if not candidates: + return None def compare_to_first(v): first = candidates[0] diff --git a/tests/test_dimension.py b/tests/test_dimension.py index a54e160b38..7532602190 100644 --- a/tests/test_dimension.py +++ b/tests/test_dimension.py @@ -9,7 +9,7 @@ SparseFunction, SparseTimeFunction, Eq, Operator, Constant, Dimension, DefaultDimension, SubDimension, switchconfig, SubDomain, Lt, Le, Gt, Ge, Ne, Buffer, sin, SpaceDimension, - CustomDimension, dimensions, configuration) + CustomDimension, dimensions, configuration, norm, Inc, sum) from devito.ir.iet import (Conditional, Expression, Iteration, FindNodes, FindSymbols, retrieve_iteration_tree) from devito.symbolics import indexify, retrieve_functions, IntDiv, INT @@ -1636,6 +1636,25 @@ def test_array_shared_w_topofuse(self): assert_structure(op, ['i,x,y', 'i', 'i,x,y', 'i,x,y'], 'i,x,y,x,y,x,y') + def test_cond_notime(self): + grid = Grid(shape=(10, 10)) + time = grid.time_dim + + time_under = ConditionalDimension(name='timeu', parent=time, factor=5) + nt = 10 + + u = TimeFunction(name='u', grid=grid, space_order=2) + usaved = TimeFunction(name='usaved', grid=grid, space_order=2, + time_dim=time_under, save=nt//5+1) + g = Function(name='g', grid=grid) + + op = Operator([Eq(usaved, u)]) + op(time_m=1, time_M=nt-1, dt=1) + + op = Operator([Inc(g, usaved)]) + op(time_m=1, time_M=nt-1, dt=1) + assert norm(g, order=1) == norm(sum(usaved, dims=time_under), order=1) + class TestCustomDimension(object):