Skip to content

Commit 0506a49

Browse files
authored
Merge pull request #1266 from IntelPython/full-large-integer-fix
Fix out of bounds integer behavior in dpctl.tensor.full
2 parents cc02941 + 3a814f6 commit 0506a49

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

dpctl/tensor/_ctors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ def full(
11011101
fill_value = int(fill_value.real)
11021102
elif fill_value_type is complex and np.issubdtype(dtype, np.floating):
11031103
fill_value = fill_value.real
1104+
elif fill_value_type is int and np.issubdtype(dtype, np.integer):
1105+
fill_value = _to_scalar(fill_value, dtype)
11041106

11051107
hev, _ = ti._full_usm_ndarray(fill_value, res, sycl_queue)
11061108
hev.wait()

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,19 @@ def test_full_strides():
14821482
assert np.array_equal(dpt.asnumpy(X), Xnp)
14831483

14841484

1485+
def test_full_gh_1230():
1486+
q = get_queue_or_skip()
1487+
dtype = "i4"
1488+
dt_maxint = dpt.iinfo(dtype).max
1489+
X = dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
1490+
X_np = dpt.asnumpy(X)
1491+
assert X.dtype == dpt.dtype(dtype)
1492+
assert np.array_equal(X_np, np.full_like(X_np, dt_maxint + 1))
1493+
1494+
with pytest.raises(OverflowError):
1495+
dpt.full(1, dpt.iinfo(dpt.uint64).max + 1, sycl_queue=q)
1496+
1497+
14851498
@pytest.mark.parametrize(
14861499
"dt",
14871500
_all_dtypes[1:],

0 commit comments

Comments
 (0)