diff --git a/pyopencl/array.py b/pyopencl/array.py index b25ffc5766d8ec31a88e1e5a37fbbead0f0ad2e0..35c521b88665bdabd7d6415d22e2f1e80de64a5a 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1222,6 +1222,9 @@ class Array(object): def _zero_fill(self, queue=None, wait_for=None): queue = queue or self.queue + if not self.size: + return + if ( queue._get_cl_version() >= (1, 2) and cl.get_cl_header_version() >= (1, 2)): diff --git a/test/test_array.py b/test/test_array.py index 521f6719474f7a05a98a100bb9a6183018caa5df..cb0dbee8b8dae83c8ed5e0c4d32378ca506bf84c 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1316,6 +1316,19 @@ def test_outoforderqueue_reductions(ctx_factory): assert b1 == a.sum() and b2 == a.dot(3 - a) and b3 == 0 +@pytest.mark.parametrize("empty_shape", [0, (), (3, 0, 2)]) +def test_zero_size_array(ctx_factory, empty_shape): + context = ctx_factory() + queue = cl.CommandQueue(context) + + a = cl_array.zeros(queue, empty_shape, dtype=np.float32) + b = cl_array.zeros(queue, empty_shape, dtype=np.float32) + b.fill(1) + c = a + b + c_host = c.get() + cl_array.to_device(queue, c_host) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1])