diff --git a/pyopencl/array.py b/pyopencl/array.py index 2cd48b2c3211edde0422466f60e27ba799b7f422..3253c90db4bd2b56c5f01cce1395c0431b4ebef3 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -680,7 +680,8 @@ def zeros(*args, **kwargs): def _zeros(queue, shape, dtype, order="C", allocator=None): result = Array(queue, shape, dtype, order=order, allocator=allocator) - result.fill(0) + zero = np.zeros((), dtype) + result.fill(zero) return result if isinstance(args[0], cl.Context): @@ -703,7 +704,8 @@ def empty_like(ary): def zeros_like(ary): result = empty_like(ary) - result.fill(0) + zero = np.zeros((), ary.dtype) + result.fill(zero) return result diff --git a/test/test_array.py b/test/test_array.py index e8996b8a6704c36440bbc009b4fffadfc34973ab..4269eb855e38d92ca86fc6c37d8ab11be904e591 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -615,6 +615,8 @@ def test_vector_fill(ctx_getter): a = a_gpu.get() assert a.dtype is cl_array.vec.float4 + a_gpu = cl_array.zeros(queue, 100, dtype=cl_array.vec.float4) +