From 3c870f6a9d81e3b432a6a1d3721cdb056359e296 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Wed, 29 Mar 2023 17:00:20 -0500 Subject: [PATCH 1/4] Allow asarray to work on sequences of dpnp_array with support compute-follows-data. --- dpnp/dpnp_container.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_container.py b/dpnp/dpnp_container.py index 12d28074b8fb..3be26b3d9769 100644 --- a/dpnp/dpnp_container.py +++ b/dpnp/dpnp_container.py @@ -91,7 +91,6 @@ def asarray(x1, else: x1_obj = x1 - sycl_queue_normalized = dpnp.get_normalized_queue_device(x1_obj, device=device, sycl_queue=sycl_queue) if order is None: order = 'C' @@ -100,8 +99,9 @@ def asarray(x1, dtype=dtype, copy=copy, order=order, + device=device, usm_type=usm_type, - sycl_queue=sycl_queue_normalized) + sycl_queue=sycl_queue) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) From 05683972b41b0efdde280276e290131a812a20e2 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Wed, 29 Mar 2023 17:03:53 -0500 Subject: [PATCH 2/4] Added tests for asarray function. --- tests/test_sycl_queue.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index a523c46465bf..6994facf6ff9 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -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) + assert_sycl_queue_equal(y.sycl_queue, x.to_device(device_y).sycl_queue) From 01a11e42e65bbe34ee8a75e295c20ba5394b61d3 Mon Sep 17 00:00:00 2001 From: Natalia Polina Date: Fri, 31 Mar 2023 11:43:28 -0500 Subject: [PATCH 3/4] sycl_queue check returned for dpnp.asarray() function. --- dpnp/dpnp_container.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/dpnp/dpnp_container.py b/dpnp/dpnp_container.py index 3be26b3d9769..5bd6f460496f 100644 --- a/dpnp/dpnp_container.py +++ b/dpnp/dpnp_container.py @@ -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) 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, - device=device, - usm_type=usm_type, - sycl_queue=sycl_queue) + 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) From c7858afe140ed5e778e81de7875b7f3ec947146f Mon Sep 17 00:00:00 2001 From: Anton <100830759+antonwolfy@users.noreply.github.com> Date: Fri, 31 Mar 2023 20:03:33 +0200 Subject: [PATCH 4/4] Update tests/test_sycl_queue.py --- tests/test_sycl_queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 6994facf6ff9..ab974e426f93 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -955,5 +955,5 @@ def test_broadcast_to(device): 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) + y = dpnp.asarray([x, x, x], device=device_y) assert_sycl_queue_equal(y.sycl_queue, x.to_device(device_y).sycl_queue)