From 0724c5b6c1fe2dfc57466d0b1552fdded54ba5b1 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sun, 7 Oct 2012 13:34:42 -0500
Subject: [PATCH] Fix numpy-scalar-as-shape (report/patch by Lawrence
 Mitchell).

---
 pyopencl/array.py  | 4 ++++
 test/test_array.py | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 88c37a2f..7304081d 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -285,6 +285,10 @@ class Array(object):
             s = shape
             shape = (shape,)
 
+        if isinstance(s, np.integer):
+            # bombs if s is a Python integer
+            s = np.asscalar(s)
+
         if strides is None:
             if order == "F":
                 strides = _f_contiguous_strides(
diff --git a/test/test_array.py b/test/test_array.py
index 47b2f76b..57ded681 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -1113,6 +1113,14 @@ def test_sort(ctx_factory):
 
 # {{{ misc
 
+@pytools.test.mark_test.opencl
+def test_numpy_integer_shape(ctx_factory):
+    context = ctx_factory()
+    queue = cl.CommandQueue(context)
+
+    cl_array.empty(queue, np.int32(17), np.float32)
+    cl_array.empty(queue, (np.int32(17), np.int32(17)), np.float32)
+
 @pytools.test.mark_test.opencl
 def test_len(ctx_factory):
     context = ctx_factory()
-- 
GitLab