Skip to content

Commit 216d1ca

Browse files
Check that full(shape, fill_val, dtype=dt) handles out of bound integral fill values
It should raise OverflowError, like NumPy 2 does.
1 parent df88543 commit 216d1ca

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,29 +1791,14 @@ 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-
1803-
def test_full_gh_1230():
1794+
@pytest.mark.parametrize("dt", ["i1", "u1", "i2", "u2", "i4", "u4", "i8", "u8"])
1795+
def test_full_gh_1230(dt):
18041796
q = get_queue_or_skip()
18051797
dtype = "i4"
18061798
dt_maxint = dpt.iinfo(dtype).max
1807-
X = dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
1808-
X_np = dpt.asnumpy(X)
1809-
assert X.dtype == dpt.dtype(dtype)
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)
18141799

18151800
with pytest.raises(OverflowError):
1816-
dpt.full(1, dpt.iinfo(dpt.uint64).max + 1, sycl_queue=q)
1801+
dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
18171802

18181803

18191804
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)