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

Allow asarray to work on sequences of dpnp_array #1355

Merged
merged 5 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 23 additions & 11 deletions dpnp/dpnp_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,34 @@ def asarray(x1,
usm_type=None,
sycl_queue=None):
"""Converts `x1` to `dpnp_array`."""
if isinstance(x1, dpnp_array):
x1_obj = x1.get_array()
else:
x1_obj = x1
dpu.validate_usm_type(usm_type, allow_none=True)

sycl_queue_normalized = dpnp.get_normalized_queue_device(x1_obj, device=device, sycl_queue=sycl_queue)
npolina4 marked this conversation as resolved.
Show resolved Hide resolved
if order is None:
order = 'C'

"""Converts incoming 'x1' object to 'dpnp_array'."""
array_obj = dpt.asarray(x1_obj,
dtype=dtype,
copy=copy,
order=order,
usm_type=usm_type,
sycl_queue=sycl_queue_normalized)
if isinstance(x1, (list, tuple, range)):
array_obj = dpt.asarray(x1,
dtype=dtype,
copy=copy,
order=order,
device=device,
usm_type=usm_type,
sycl_queue=sycl_queue)
else:
if isinstance(x1, dpnp_array):
x1_obj = x1.get_array()
else:
x1_obj = x1

sycl_queue_normalized = dpnp.get_normalized_queue_device(x1_obj, device=device, sycl_queue=sycl_queue)

array_obj = dpt.asarray(x1_obj,
dtype=dtype,
copy=copy,
order=order,
usm_type=usm_type,
sycl_queue=sycl_queue_normalized)
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,3 +945,15 @@ def test_broadcast_to(device):
x = dpnp.arange(5, device=device)
y = dpnp.broadcast_to(x, (3, 5))
assert_sycl_queue_equal(x.sycl_queue, y.sycl_queue)


@pytest.mark.parametrize("device_x",
valid_devices,
ids=[device.filter_string for device in valid_devices])
@pytest.mark.parametrize("device_y",
valid_devices,
ids=[device.filter_string for device in valid_devices])
def test_asarray(device_x, device_y):
x = dpnp.array([1, 2, 3], device=device_x)
y = dpnp.asarray([x], device=device_y)
antonwolfy marked this conversation as resolved.
Show resolved Hide resolved
assert_sycl_queue_equal(y.sycl_queue, x.to_device(device_y).sycl_queue)