From 88a1cddebc6b6c9985afbf3700e365cb7edc9d07 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 27 May 2021 19:15:52 -0500 Subject: [PATCH] Prohibit non-contiguous copy --- pyopencl/array.py | 3 +++ test/test_array.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index c05ab2f0..402426a8 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -823,6 +823,9 @@ class Array: if result.queue is not queue: result = result.with_queue(queue) + if not self.flags.forc: + raise RuntimeError("cannot copy non-contiguous array") + if self.nbytes: event1 = cl.enqueue_copy(queue or self.queue, result.base_data, self.base_data, diff --git a/test/test_array.py b/test/test_array.py index 3bfd0d04..289052ee 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1560,7 +1560,7 @@ def test_assign_different_strides(ctx_factory): b[:] = a -def test_branch_operations_on_pure_scalars(ctx_factory): +def test_branch_operations_on_pure_scalars(): x = np.random.rand() y = np.random.rand() cond = np.random.choice([False, True]) @@ -1573,6 +1573,16 @@ def test_branch_operations_on_pure_scalars(ctx_factory): cl_array.if_positive(cond, x, y)) +def test_slice_copy(ctx_factory): + cl_ctx = ctx_factory() + queue = cl.CommandQueue(cl_ctx) + + x = cl.array.to_device(queue, np.random.rand(96, 27)) + y = x[::8, ::3] + with pytest.raises(RuntimeError): + y.copy() + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) -- GitLab