From d4705ccdcc2b152ec078f31796518e4035a3dd39 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 6 May 2013 22:39:03 -0400 Subject: [PATCH] Add Array.get_item(). --- pyopencl/array.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyopencl/array.py b/pyopencl/array.py index 1c8a0289..62e153c3 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -479,6 +479,19 @@ class Array(object): return ary + def get_item(self, index, queue=None, wait_for=None): + if not isinstance(index, tuple): + index = (index,) + if len(index) != len(self.shape): + raise ValueError("incorrect number of indices") + + tgt = np.empty((), self.dtype) + cl.enqueue_copy(queue or self.queue, tgt, self.data, + is_blocking=True, wait_for=wait_for, + device_offset=_builtin_sum(i*s for i, s in zip(index, self.strides))) + + return tgt[()] + def copy(self, queue=None): """.. versionadded:: 2013.1""" -- GitLab