Skip to content

Commit

Permalink
Merge pull request #2361 from devitocodes/multi_conditional
Browse files Browse the repository at this point in the history
tests: Add test for combining multiple ConditionalDimensions
  • Loading branch information
mloubout authored Apr 29, 2024
2 parents d62e3a2 + 880366e commit 787b8eb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,38 @@ def test_implicit_dims(self):

assert np.all(f.data == F)

def test_implict_dims_multiple(self):
"""Test supplying multiple ConditionalDimensions as implicit dimensions"""
shape = (50,)
start_value = 5
stop_value = 20

time = Dimension(name='time')
f = TimeFunction(name='f', shape=shape, dimensions=[time])
# The condition to start incrementing
cond0 = ConditionalDimension(name='cond0',
parent=time, condition=time > start_value)
# The condition to stop incrementing
cond1 = ConditionalDimension(name='cond1',
parent=time, condition=time < stop_value)
# Factor of 2
cond2 = ConditionalDimension(name='cond2', parent=time, factor=2)

eqs = [Eq(f.forward, f), Eq(f.forward, f.forward + 1,
implicit_dims=[cond0, cond1, cond2])]
op = Operator(eqs)
op.apply(time_M=shape[0] - 2)

# Make the same calculation in python to assert the result
F = np.zeros(shape[0])
val = 0
for i in range(shape[0]):
F[i] = val
if i > start_value and i < stop_value and i % 2 == 0:
val += 1

assert np.all(f.data == F)

def test_grouping(self):
"""
Test that Clusters over the same set of ConditionalDimensions fall within
Expand Down

0 comments on commit 787b8eb

Please sign in to comment.