Skip to content

Commit

Permalink
Split up TestMinMax::test_uint
Browse files Browse the repository at this point in the history
I split this test up to test uint64 separately, since
this is the case discussed in Issue pymc-devs#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.
  • Loading branch information
brendan-m-murphy committed Feb 4, 2025
1 parent 4011ea0 commit 708568b
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions tests/tensor/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 708568b

Please sign in to comment.