diff --git a/pyopencl/array.py b/pyopencl/array.py index c05ab2f0039c6868284fa73520fa4fec7da4982d..402426a8241029f824df7d3aea50ebdee58da080 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 3bfd0d04bb463174e40fefa59304ca1b1e9b4f8f..289052eef2320e647d569bee4556822734b31c7a 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])