diff --git a/pyopencl/array.py b/pyopencl/array.py index 4592cc1e4fa11db6ed1b617616225a47edb2645d..0a8efe917ec5cd5b804073402468b85433c76b4b 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 ecfd3ba97a027278ffb4c317c5180d49cd25695e..485a46a62d03976711d6c4170efbc4f4022b63ef 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.