From 0954792e18e178a093c8e1688c54ea09eb3c42b4 Mon Sep 17 00:00:00 2001 From: Alexander-Makaryev Date: Mon, 14 Mar 2022 04:08:09 -0500 Subject: [PATCH 1/2] to_device array method impl --- dpnp/dpnp_array.py | 7 +++++++ tests/test_sycl_queue.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 5aaf3c6efbda..c0bd122aea18 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -97,6 +97,13 @@ def T(self): else: return dpnp.transpose(self) + def to_device(self, target_device): + """ + Transfer array to target device + """ + + return dpnp_array(shape=self.shape, buffer=self.get_array().to_device(target_device)) + def __abs__(self): return dpnp.abs(self) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 66fbfb786f89..33dcf1c15b81 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -83,3 +83,18 @@ def test_2in_1out(func, device): assert_sycl_queue_equal(result_queue, expected_queue) assert result_queue.sycl_device == expected_queue.sycl_device + + +@pytest.mark.parametrize("device_from", + valid_devices, + ids=[device.filter_string for device in valid_devices]) +@pytest.mark.parametrize("device_to", + valid_devices, + ids=[device.filter_string for device in valid_devices]) +def test_to_device(device_from, device_to): + data = [1., 1., 1., 1., 1.] + + x = dpnp.array(data, device=device_from) + y = x.to_device(device_to) + + assert y.get_array().sycl_device == device_to From 0467088cba652201cfd8625ef018f0387aa83ceb Mon Sep 17 00:00:00 2001 From: Alexander-Makaryev Date: Mon, 14 Mar 2022 14:12:23 +0300 Subject: [PATCH 2/2] Update tests/test_sycl_queue.py Co-authored-by: densmirn --- 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 33dcf1c15b81..d3cf85d88b74 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -95,6 +95,6 @@ def test_to_device(device_from, device_to): data = [1., 1., 1., 1., 1.] x = dpnp.array(data, device=device_from) - y = x.to_device(device_to) + y = x.to_device(device_to) assert y.get_array().sycl_device == device_to