Skip to content

Fix out of bounds integer behavior in dpctl.tensor.full #1266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,8 @@ def full(
fill_value = int(fill_value.real)
elif fill_value_type is complex and np.issubdtype(dtype, np.floating):
fill_value = fill_value.real
elif fill_value_type is int and np.issubdtype(dtype, np.integer):
fill_value = _to_scalar(fill_value, dtype)

hev, _ = ti._full_usm_ndarray(fill_value, res, sycl_queue)
hev.wait()
Expand Down
13 changes: 13 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,19 @@ def test_full_strides():
assert np.array_equal(dpt.asnumpy(X), Xnp)


def test_full_gh_1230():
q = get_queue_or_skip()
dtype = "i4"
dt_maxint = dpt.iinfo(dtype).max
X = dpt.full(1, dt_maxint + 1, dtype=dtype, sycl_queue=q)
X_np = dpt.asnumpy(X)
assert X.dtype == dpt.dtype(dtype)
assert np.array_equal(X_np, np.full_like(X_np, dt_maxint + 1))

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


@pytest.mark.parametrize(
"dt",
_all_dtypes[1:],
Expand Down