Skip to content

Commit

Permalink
replace misleading uses of ConstInitializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Häuselmann committed Nov 17, 2023
1 parent f7d83da commit c4bf2cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 48 deletions.
7 changes: 0 additions & 7 deletions tests/next_tests/integration_tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ def field(
sizes: dict[gtx.Dimension, int],
dtype: np.typing.DTypeLike,
) -> FieldValue:
if hasattr(self.value, "__array__"):
return constructors.as_field(
common.domain(sizes),
np.full(tuple(sizes.values()), self.value),
dtype=dtype,
allocator=backend,
)
return constructors.full(
domain=common.domain(sizes),
fill_value=self.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ def conditional_nested_tuple(
return where(mask, ((a, b), (b, a)), ((5.0, 7.0), (7.0, 5.0)))

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
mask = cases.allocate(cartesian_case, conditional_nested_tuple, "mask").strategy(
cases.ConstInitializer(bool_field)
)()
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=size))
a = cases.allocate(cartesian_case, conditional_nested_tuple, "a")()
b = cases.allocate(cartesian_case, conditional_nested_tuple, "b")()

Expand Down Expand Up @@ -211,10 +208,7 @@ def conditional(
return where(mask, a, b)

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
mask = cases.allocate(cartesian_case, conditional, "mask").strategy(
cases.ConstInitializer(bool_field)
)()
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
a = cases.allocate(cartesian_case, conditional, "a")()
b = cases.allocate(cartesian_case, conditional, "b")()
out = cases.allocate(cartesian_case, conditional, cases.RETURN)()
Expand All @@ -228,10 +222,7 @@ def conditional_promotion(mask: cases.IBoolField, a: cases.IFloatField) -> cases
return where(mask, a, 10.0)

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
mask = cases.allocate(cartesian_case, conditional_promotion, "mask").strategy(
cases.ConstInitializer(bool_field)
)()
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
a = cases.allocate(cartesian_case, conditional_promotion, "a")()
out = cases.allocate(cartesian_case, conditional_promotion, cases.RETURN)()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,8 @@ def binary_xor(inp1: cases.IBoolField, inp2: cases.IBoolField) -> cases.IBoolFie
return inp1 ^ inp2

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
inp1 = cases.allocate(cartesian_case, binary_xor, "inp1").strategy(
cases.ConstInitializer(bool_field)
)()
inp2 = cases.allocate(cartesian_case, binary_xor, "inp2").strategy(
cases.ConstInitializer(bool_field)
)()
inp1 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
inp2 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
out = cases.allocate(cartesian_case, binary_xor, cases.RETURN)()
cases.verify(cartesian_case, binary_xor, inp1, inp2, out=out, ref=inp1 ^ inp2)

Expand All @@ -120,13 +115,8 @@ def bit_and(inp1: cases.IBoolField, inp2: cases.IBoolField) -> cases.IBoolField:
return inp1 & inp2

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
inp1 = cases.allocate(cartesian_case, bit_and, "inp1").strategy(
cases.ConstInitializer(bool_field)
)()
inp2 = cases.allocate(cartesian_case, bit_and, "inp2").strategy(
cases.ConstInitializer(bool_field)
)()
inp1 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
inp2 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
out = cases.allocate(cartesian_case, bit_and, cases.RETURN)()
cases.verify(cartesian_case, bit_and, inp1, inp2, out=out, ref=inp1 & inp2)

Expand All @@ -137,13 +127,8 @@ def bit_or(inp1: cases.IBoolField, inp2: cases.IBoolField) -> cases.IBoolField:
return inp1 | inp2

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
inp1 = cases.allocate(cartesian_case, bit_or, "inp1").strategy(
cases.ConstInitializer(bool_field)
)()
inp2 = cases.allocate(cartesian_case, bit_or, "inp2").strategy(
cases.ConstInitializer(bool_field)
)()
inp1 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
inp2 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
out = cases.allocate(cartesian_case, bit_or, cases.RETURN)()
cases.verify(cartesian_case, bit_or, inp1, inp2, out=out, ref=inp1 | inp2)

Expand All @@ -165,10 +150,7 @@ def tilde_fieldop(inp1: cases.IBoolField) -> cases.IBoolField:
return ~inp1

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
inp1 = cases.allocate(cartesian_case, tilde_fieldop, "inp1").strategy(
cases.ConstInitializer(bool_field)
)()
inp1 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
out = cases.allocate(cartesian_case, tilde_fieldop, cases.RETURN)()
cases.verify(cartesian_case, tilde_fieldop, inp1, out=out, ref=~inp1)

Expand All @@ -179,10 +161,7 @@ def not_fieldop(inp1: cases.IBoolField) -> cases.IBoolField:
return not inp1

size = cartesian_case.default_sizes[IDim]
bool_field = np.random.choice(a=[False, True], size=(size))
inp1 = cases.allocate(cartesian_case, not_fieldop, "inp1").strategy(
cases.ConstInitializer(bool_field)
)()
inp1 = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size)))
out = cases.allocate(cartesian_case, not_fieldop, cases.RETURN)()
cases.verify(cartesian_case, not_fieldop, inp1, out=out, ref=~inp1)

Expand Down

0 comments on commit c4bf2cd

Please sign in to comment.