From b93e79732bef2a632bcc302f6fec29ef87e14969 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 5 Jul 2015 09:46:22 -0500 Subject: [PATCH] Fix rounding in slicing (David Wei Chang) --- pyopencl/array.py | 2 +- test/test_array.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 4592cc1e..0a8efe91 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1517,7 +1517,7 @@ class Array(object): array_stride = self.strides[array_axis] - new_shape.append((stop-start)//idx_stride) + new_shape.append((stop-start-1)//idx_stride+1) new_strides.append(idx_stride*array_stride) new_offset += array_stride*start diff --git a/test/test_array.py b/test/test_array.py index ecfd3ba9..485a46a6 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -817,6 +817,19 @@ def test_reshape(ctx_factory): a_dev.reshape(-1, -1, 4) +def test_skip_slicing(ctx_factory): + context = ctx_factory() + queue = cl.CommandQueue(context) + + a_host = np.arange(16).reshape((4, 4)) + b_host = a_host[::3] + + a = cl_array.to_device(queue, a_host) + b = a[::3] + assert b.shape == b_host.shape + assert np.array_equal(b[1].get(), b_host[1]) + + if __name__ == "__main__": # make sure that import failures get reported, instead of skipping the # tests. -- GitLab