Skip to content

Fixed missing copy for dpctl.tensor.full() function if fill_value is array #995

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 2 commits into from
Nov 19, 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
3 changes: 2 additions & 1 deletion dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,11 @@ def full(
X = dpt.asarray(
fill_value,
dtype=dtype,
order=order,
usm_type=usm_type,
sycl_queue=sycl_queue,
)
return dpt.broadcast_to(X, sh)
return dpt.copy(dpt.broadcast_to(X, sh), order=order)

sycl_queue = normalize_queue_device(sycl_queue=sycl_queue, device=device)
usm_type = usm_type if usm_type is not None else "device"
Expand Down
25 changes: 25 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,31 @@ def test_full_compute_follows_data():
assert np.array_equal(dpt.asnumpy(Y), np.full(10, 3, dtype="f4"))


@pytest.mark.parametrize("order1", ["F", "C"])
@pytest.mark.parametrize("order2", ["F", "C"])
def test_full_order(order1, order2):
q = get_queue_or_skip()
Xnp = np.array([1, 2, 3], order=order1)
Ynp = np.full((3, 3), Xnp, order=order2)
Y = dpt.full((3, 3), Xnp, order=order2, sycl_queue=q)
assert Y.flags.c_contiguous == Ynp.flags.c_contiguous
assert Y.flags.f_contiguous == Ynp.flags.f_contiguous
assert np.array_equal(dpt.asnumpy(Y), Ynp)


def test_full_strides():
q = get_queue_or_skip()
X = dpt.full((3, 3), dpt.arange(3, dtype="i4"), sycl_queue=q)
Xnp = np.full((3, 3), np.arange(3, dtype="i4"))
assert X.strides == tuple(el // Xnp.itemsize for el in Xnp.strides)
assert np.array_equal(dpt.asnumpy(X), Xnp)

X = dpt.full((3, 3), dpt.arange(6, dtype="i4")[::2], sycl_queue=q)
Xnp = np.full((3, 3), np.arange(6, dtype="i4")[::2])
assert X.strides == tuple(el // Xnp.itemsize for el in Xnp.strides)
assert np.array_equal(dpt.asnumpy(X), Xnp)


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