diff --git a/pyopencl/array.py b/pyopencl/array.py index bda1449ce88bf9ecb2869449b2bf03a8fa8a6773..2562192c5dea1d254eb794c1a86f03cbb4750a3a 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1617,6 +1617,15 @@ class Array: if size != self.size: raise ValueError("total size of new array must be unchanged") + if self.size == 0: + return self._new_with_changes( + data=None, offset=0, shape=shape, + strides=( + _f_contiguous_strides(self.dtype.itemsize, shape) + if order == "F" else + _c_contiguous_strides(self.dtype.itemsize, shape) + )) + # {{{ determine reshaped strides # copied and translated from diff --git a/pyopencl/compyte b/pyopencl/compyte index d1f993daecc03947d9e6e3e60d2a5145ecbf3786..fbfe788a2dcb190fd241fd42ad047e33bafd85b8 160000 --- a/pyopencl/compyte +++ b/pyopencl/compyte @@ -1 +1 @@ -Subproject commit d1f993daecc03947d9e6e3e60d2a5145ecbf3786 +Subproject commit fbfe788a2dcb190fd241fd42ad047e33bafd85b8 diff --git a/test/test_array.py b/test/test_array.py index 162f52847e21a994152a409b4e1925ee2bb008a5..b4234a3777059cc44b2f37006c98239e4dbe2ec5 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1464,7 +1464,7 @@ def test_negative_dim_rejection(ctx_factory): cl_array.Array(queue, shape=(-1, right_dim), dtype=np.float) -@pytest.mark.parametrize("empty_shape", [0, (), (3, 0, 2)]) +@pytest.mark.parametrize("empty_shape", [0, (), (3, 0, 2), (0, 5), (5, 0)]) def test_zero_size_array(ctx_factory, empty_shape): context = ctx_factory() queue = cl.CommandQueue(context) @@ -1476,6 +1476,17 @@ def test_zero_size_array(ctx_factory, empty_shape): c_host = c.get() cl_array.to_device(queue, c_host) + assert c.flags.c_contiguous == c_host.flags.c_contiguous + assert c.flags.f_contiguous == c_host.flags.f_contiguous + + for order in "CF": + c_flat = c.reshape(-1, order=order) + c_host_flat = c_host.reshape(-1, order=order) + assert c_flat.shape == c_host_flat.shape + assert c_flat.strides == c_host_flat.strides + assert c_flat.flags.c_contiguous == c_host_flat.flags.c_contiguous + assert c_flat.flags.f_contiguous == c_host_flat.flags.f_contiguous + def test_str_without_queue(ctx_factory): context = ctx_factory()