Skip to content
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

Fixed error in cast dtype for full() function. #1002

Merged
merged 1 commit into from
Nov 30, 2022
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
8 changes: 7 additions & 1 deletion dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,20 @@ def full(

sycl_queue = normalize_queue_device(sycl_queue=sycl_queue, device=device)
usm_type = usm_type if usm_type is not None else "device"
dtype = _get_dtype(dtype, sycl_queue, ref_type=type(fill_value))
fill_value_type = type(fill_value)
dtype = _get_dtype(dtype, sycl_queue, ref_type=fill_value_type)
res = dpt.usm_ndarray(
sh,
dtype=dtype,
buffer=usm_type,
order=order,
buffer_ctor_kwargs={"queue": sycl_queue},
)
if fill_value_type in [float, complex] and np.issubdtype(dtype, np.integer):
fill_value = int(fill_value.real)
elif fill_value_type is complex and np.issubdtype(dtype, np.floating):
fill_value = fill_value.real

hev, _ = ti._full_usm_ndarray(fill_value, res, sycl_queue)
hev.wait()
return res
Expand Down
4 changes: 4 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ def test_full_dtype_inference():
assert np.issubdtype(dpt.full(10, 12.3).dtype, np.floating)
assert np.issubdtype(dpt.full(10, 0.3 - 2j).dtype, np.complexfloating)

assert np.issubdtype(dpt.full(10, 12.3, dtype=int).dtype, np.integer)
assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=int).dtype, np.integer)
assert np.issubdtype(dpt.full(10, 0.3 - 2j, dtype=float).dtype, np.floating)


def test_full_fill_array():
q = get_queue_or_skip()
Expand Down