From 21f5d8ebe24e3d0d33535c98e3aceb30fe0d9c9e Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 17 Dec 2012 23:37:21 -0500
Subject: [PATCH] Allow passing an explicit size to the scan.

---
 doc/source/algorithm.rst | 6 ++++--
 pyopencl/scan.py         | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/doc/source/algorithm.rst b/doc/source/algorithm.rst
index 94758f71..781cbcb6 100644
--- a/doc/source/algorithm.rst
+++ b/doc/source/algorithm.rst
@@ -193,10 +193,12 @@ Making Custom Scan Kernels
 
 .. autoclass:: GenericScanKernel
 
-    .. method:: __call__(*args, allocator=None, queue=None)
+    .. method:: __call__(*args, allocator=None, queue=None, size=None)
 
         *queue* and *allocator* default to the ones provided on the first
-        :class:`pyopencl.array.Array` in *args*.
+        :class:`pyopencl.array.Array` in *args*. *size* may specify the
+        length of the scan to be carried out. If not given, this length
+        is inferred from the first array argument passed.
 
 Debugging aids
 ~~~~~~~~~~~~~~
diff --git a/pyopencl/scan.py b/pyopencl/scan.py
index 61cf90a9..9e2487fe 100644
--- a/pyopencl/scan.py
+++ b/pyopencl/scan.py
@@ -1258,6 +1258,7 @@ class GenericScanKernel(_GenericScanKernelBase):
 
         allocator = kwargs.get("allocator")
         queue = kwargs.get("queue")
+        n = kwargs.get("size")
 
         if len(args) != len(self.parsed_args):
             raise TypeError("expected %d arguments, got %d" %
@@ -1267,7 +1268,8 @@ class GenericScanKernel(_GenericScanKernelBase):
         allocator = allocator or first_array.allocator
         queue = queue or first_array.queue
 
-        n, = first_array.shape
+        if n is None:
+            n, = first_array.shape
 
         data_args = []
         from pyopencl.tools import VectorArg
-- 
GitLab