From 494ed7f4764d4f19663463f1687266e345eeffdf Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sat, 2 Jul 2011 22:35:53 -0400
Subject: [PATCH] Fix zeros() on vector array. (Reported by Sebastian Nowozin)

---
 pyopencl/array.py  | 6 ++++--
 test/test_array.py | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 2cd48b2c..3253c90d 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 e8996b8a..4269eb85 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)
+
 
 
 
-- 
GitLab