Skip to content

Commit 6e81050

Browse files
Correct test_full_gh_1230 for NumPy 2.1.0
NumPy 2.1.0 now raises exception when fill_value is not in bounds for the array data type. Rework the logic of the test to accomodate that. The test continue to work with NumPy 2.0.1
1 parent 1e52918 commit 6e81050

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,14 +1791,26 @@ def test_full_strides():
17911791
assert np.array_equal(dpt.asnumpy(X), Xnp)
17921792

17931793

1794+
def _reduce_to_idtype_range(o, dtype):
1795+
assert isinstance(dtype, np.dtype)
1796+
assert dtype.kind in "ui"
1797+
_iinfo = np.iinfo(dtype)
1798+
_max = _iinfo.max
1799+
_min = _iinfo.min
1800+
return ((o - _min) % (1 + _max - _min)) + _min
1801+
1802+
17941803
def test_full_gh_1230():
17951804
q = get_queue_or_skip()
17961805
dtype = "i4"
17971806
dt_maxint = dpt.iinfo(dtype).max
17981807
X = dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
17991808
X_np = dpt.asnumpy(X)
18001809
assert X.dtype == dpt.dtype(dtype)
1801-
assert np.array_equal(X_np, np.full_like(X_np, dt_maxint + 1))
1810+
expected = np.full_like(
1811+
X_np, _reduce_to_idtype_range(dt_maxint + 1, X.dtype)
1812+
)
1813+
assert np.array_equal(X_np, expected)
18021814

18031815
with pytest.raises(OverflowError):
18041816
dpt.full(1, dpt.iinfo(dpt.uint64).max + 1, sycl_queue=q)

0 commit comments

Comments
 (0)