From f6360a2d7fb33e0bd0f065c774112ba6b26246d5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:36:41 -0500 Subject: [PATCH 1/8] Array.copy(): Change to update the queue of returned array. --- pyopencl/array.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 08f7cc8b..adbb7aad 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -631,14 +631,24 @@ class Array(object): return ary - def copy(self, queue=None): - """.. versionadded:: 2013.1""" + def copy(self, queue=_copy_queue): + """ + :arg queue: The :class:`CommandQueue` for the returned array. - queue = queue or self.queue - result = self._new_like_me() + .. versionchanged:: 2017.1.2 + Updates the queue of returned array. + + .. versionadded:: 2013.1 + """ + + if queue is _copy_queue: + queue = self.queue + + result = self._new_like_me(queue=queue) if self.nbytes: - cl.enqueue_copy(queue, result.base_data, self.base_data, + cl.enqueue_copy(queue or self.queue, + result.base_data, self.base_data, src_offset=self.offset, byte_count=self.nbytes) return result -- GitLab From f3d09ecfabc4f88310d67f8208cc2fdef078cd7d Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:49:55 -0500 Subject: [PATCH 2/8] Fix Array.copy() behavior when the passed queue is None. --- pyopencl/array.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyopencl/array.py b/pyopencl/array.py index adbb7aad..416a41f3 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -646,6 +646,11 @@ class Array(object): result = self._new_like_me(queue=queue) + # result.queue won't be the same as queue if queue is None. + # We force them to be the same here. + if result.queue is not queue: + result = result.with_queue(queue) + if self.nbytes: cl.enqueue_copy(queue or self.queue, result.base_data, self.base_data, -- GitLab From 511e3ad5cb98967183ff2cd9584264c6cd7faaa2 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:50:38 -0500 Subject: [PATCH 3/8] Add a test for Array.copy(). --- test/test_array.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_array.py b/test/test_array.py index 4c418903..2f3def6f 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -762,6 +762,32 @@ def test_diff(ctx_factory): (cl.array.diff(a_dev).get() - np.diff(a))) assert err < 1e-4 + +def test_copy(ctx_factory): + context = ctx_factory() + queue1 = cl.CommandQueue(context) + queue2 = cl.CommandQueue(context) + + # Test copy + + arr = cl.array.zeros(queue1, 100, np.int32) + arr_copy = arr.copy() + + assert (arr == arr_copy).all().get() + assert arr.data != arr_copy.data + + # Test queue association + + arr_copy = arr.copy(queue=queue2) + assert arr_copy.queue == queue2 + + arr_copy = arr.copy(queue=None) + assert arr_copy.queue == None + + arr_copy = arr.with_queue(None).copy(queue=queue1) + assert arr_copy.queue == queue1 + + # }}} -- GitLab From 6a0f563310d7a6a82e05a9a19d14a492ddc83a14 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:51:05 -0500 Subject: [PATCH 4/8] Fix mismatched fold near as_strided(). --- pyopencl/array.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 416a41f3..3f65288a 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1797,6 +1797,8 @@ class Array(object): # }}} +# {{{ creation helpers + def as_strided(ary, shape=None, strides=None): """Make an :class:`Array` from the given array with the given shape and strides. @@ -1812,10 +1814,6 @@ def as_strided(ary, shape=None, strides=None): return Array(ary.queue, shape, ary.dtype, allocator=ary.allocator, data=ary.data, strides=strides) -# }}} - - -# {{{ creation helpers class _same_as_transfer(object): # noqa pass -- GitLab From e68b91ca885776d01729e25a6a13bae47055f220 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:51:45 -0500 Subject: [PATCH 5/8] Bump version for Array.copy() changes --- pyopencl/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyopencl/version.py b/pyopencl/version.py index cd1ab88f..751a8cfc 100644 --- a/pyopencl/version.py +++ b/pyopencl/version.py @@ -1,3 +1,3 @@ -VERSION = (2017, 1, 1) +VERSION = (2017, 1, 2) VERSION_STATUS = "" VERSION_TEXT = ".".join(str(x) for x in VERSION) + VERSION_STATUS -- GitLab From 373ac7b1d084618bcff5125d5930142baa9efae5 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:54:43 -0500 Subject: [PATCH 6/8] test_array(): Check for queue identity; also add a missing queue check. --- test/test_array.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_array.py b/test/test_array.py index 2f3def6f..b388575e 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -775,17 +775,18 @@ def test_copy(ctx_factory): assert (arr == arr_copy).all().get() assert arr.data != arr_copy.data + assert arr_copy.queue is queue1 # Test queue association arr_copy = arr.copy(queue=queue2) - assert arr_copy.queue == queue2 + assert arr_copy.queue is queue2 arr_copy = arr.copy(queue=None) - assert arr_copy.queue == None + assert arr_copy.queue is None arr_copy = arr.with_queue(None).copy(queue=queue1) - assert arr_copy.queue == queue1 + assert arr_copy.queue is queue1 # }}} -- GitLab From 1ca7e583745e3a87dac69174f9dd67627bc6571b Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 00:58:43 -0500 Subject: [PATCH 7/8] Whitespace fix. --- test/test_array.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_array.py b/test/test_array.py index b388575e..115488c3 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -788,7 +788,6 @@ def test_copy(ctx_factory): arr_copy = arr.with_queue(None).copy(queue=queue1) assert arr_copy.queue is queue1 - # }}} -- GitLab From 5ca953f8cb02d8f6571d0a57fc35b08987f4671f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Fri, 23 Jun 2017 01:00:49 -0500 Subject: [PATCH 8/8] Grammar fix. --- pyopencl/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 3f65288a..326eea7c 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -636,7 +636,7 @@ class Array(object): :arg queue: The :class:`CommandQueue` for the returned array. .. versionchanged:: 2017.1.2 - Updates the queue of returned array. + Updates the queue of the returned array. .. versionadded:: 2013.1 """ -- GitLab