Skip to content
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

tests: Add test for using a Constant as a condition in a ConditionalDimension #2512

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
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
14 changes: 14 additions & 0 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,20 @@ def test_no_index_symbolic(self):
op = Operator(eq)
op.cfunction

@pytest.mark.parametrize('value', [0, 1])
def test_constant_as_condition(self, value):
x = Dimension('x')

c = Constant(name="c", dtype=np.int8, value=value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a Bool if it's a condition by itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you can enhance the test with a bool as well? Behaviour should be the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But C doesn't have a core bool type? You have to import stdbool.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention is to use an int iirc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, int is OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int8 btw is converted into a char

cd = ConditionalDimension(name="cd", parent=x, condition=c)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably drop this empty line

f = Function(name='f', dimensions=(x,), shape=(11,), dtype=np.int32)

op = Operator(Eq(f, 1, implicit_dims=cd))
op.apply()

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

def test_symbolic_factor(self):
"""
Test ConditionalDimension with symbolic factor (provided as a Constant).
Expand Down
Loading