From 708568b6ae61e7e7c5216cb43c0a064901d04fa7 Mon Sep 17 00:00:00 2001 From: Brendan Murphy Date: Tue, 4 Feb 2025 13:56:51 +0000 Subject: [PATCH] Split up TestMinMax::test_uint I split this test up to test uint64 separately, since this is the case discussed in Issue #770. I also added a test for the exact example used in that issue. The uint dtypes with lower precision should pass. The uint64 case started passing for me locally on Mac OSX, but still fails on CI. I'm not sure why this is, but at least the test will be more specific now if it fails in the future. --- tests/tensor/test_math.py | 51 ++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/tests/tensor/test_math.py b/tests/tensor/test_math.py index 539950bbe1..ac8885001f 100644 --- a/tests/tensor/test_math.py +++ b/tests/tensor/test_math.py @@ -1402,18 +1402,47 @@ def _grad_list(self): # check_grad_max(data, eval_outputs(grad(max_and_argmax(n, # axis=1)[0], n)),axis=1) + @pytest.mark.parametrize("dtype", ("uint8", "uint16", "uint32")) + def test_uint(self, dtype): + itype = np.iinfo(dtype) + data = np.array([itype.min + 3, itype.min, itype.max - 5, itype.max], dtype) + n = as_tensor_variable(data) + + assert min(n).dtype == dtype + i_min = eval_outputs(min(n)) + assert i_min == itype.min + + assert max(n).dtype == dtype + i_max = eval_outputs(max(n)) + assert i_max == itype.max + @pytest.mark.xfail(reason="Fails due to #770") - def test_uint(self): - for dtype in ("uint8", "uint16", "uint32", "uint64"): - itype = np.iinfo(dtype) - data = np.array([itype.min + 3, itype.min, itype.max - 5, itype.max], dtype) - n = as_tensor_variable(data) - assert min(n).dtype == dtype - i = eval_outputs(min(n)) - assert i == itype.min - assert max(n).dtype == dtype - i = eval_outputs(max(n)) - assert i == itype.max + def test_uint64(self): + dtype = "uint64" + itype = np.iinfo(dtype) + + data = np.array([itype.min + 3, itype.min, itype.max - 5, itype.max], dtype) + n = as_tensor_variable(data) + + assert min(n).dtype == dtype + i_min = eval_outputs(min(n)) + assert i_min == itype.min + + assert max(n).dtype == dtype + i_max = eval_outputs(max(n)) + assert i_max == itype.max + + i_max = eval_outputs(max(n)) + assert i_max == data.max() + + @pytest.mark.xfail(reason="Fails due to #770") + def test_uint64_special_value(self): + dtype = "uint64" + data = np.array([0, 9223372036854775], dtype=dtype) + n = as_tensor_variable(data) + + i_max = eval_outputs(max(n)) + assert i_max == data.max() def test_bool(self): data = np.array([True, False], "bool")