From 299612cfe93de63a23bd89b640cf6830e86e5ffb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 15 Jun 2020 17:59:53 -0500 Subject: [PATCH] Test, fix zero-size arrays --- pyopencl/array.py | 3 +++ test/test_array.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pyopencl/array.py b/pyopencl/array.py index b25ffc57..35c521b8 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 521f6719..cb0dbee8 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]) -- GitLab