Skip to content
Snippets Groups Projects
Commit 37b90035 authored by Daniel Bauer's avatar Daniel Bauer :speech_balloon:
Browse files

test conversion of non-integer values

parent fc844b77
No related merge requests found
Pipeline #72449 passed with stages
in 8 minutes and 28 seconds
......@@ -43,10 +43,14 @@ target_and_dtype = pytest.mark.parametrize(
@target_and_dtype
def test_type_cast(gen_config, xp, from_type, to_type):
inp = xp.array([-1, 0, 1, 3, -5, -312], dtype=from_type)
if np.issubdtype(from_type, np.floating):
inp = xp.array([-1.25, -0, 1.5, 3, -5, -312, 42, 6.625, -9], dtype=from_type)
else:
inp = xp.array([-1, 0, 1, 3, -5, -312, 42, 6, -9], dtype=from_type)
outp = xp.zeros_like(inp).astype(to_type)
reference = inp.astype(to_type)
truncated = inp.astype(to_type)
rounded = xp.round(inp).astype(to_type)
inp_field = Field.create_from_numpy_array("inp", inp)
outp_field = Field.create_from_numpy_array("outp", outp)
......@@ -57,4 +61,8 @@ def test_type_cast(gen_config, xp, from_type, to_type):
kfunc = kernel.compile()
kfunc(inp=inp, outp=outp)
xp.testing.assert_array_equal(outp, reference)
# rounding mode depends on platform
try:
xp.testing.assert_array_equal(outp, truncated)
except AssertionError:
xp.testing.assert_array_equal(outp, rounded)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment