From 20e7fff52fe36654f59c137551580f1f83a46298 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sun, 3 Jul 2011 01:10:59 -0400
Subject: [PATCH] Deprecate context arg on clrandom.rand.

---
 doc/source/array.rst |  2 +-
 pyopencl/clrandom.py | 24 +++++++++++++++++-------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/doc/source/array.rst b/doc/source/array.rst
index 56ab1995..7e70dd82 100644
--- a/doc/source/array.rst
+++ b/doc/source/array.rst
@@ -358,7 +358,7 @@ Generating Arrays of Random Numbers
 
 .. module:: pyopencl.clrandom
 
-.. function:: rand(context, queue, shape, dtype)
+.. function:: rand(queue, shape, dtype)
 
     Return an array of `shape` filled with random values of `dtype`
     in the range [0,1).
diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py
index c2cea99c..2b13047e 100644
--- a/pyopencl/clrandom.py
+++ b/pyopencl/clrandom.py
@@ -241,13 +241,23 @@ def _rand(output, seed):
 def fill_rand(result):
     _rand(result, np.random.randint(2**31-1))
 
-def rand(context, queue, shape, dtype):
-    from pyopencl.array import Array
-
-    result = Array(queue, shape, dtype)
-    _rand(result, np.random.randint(2**31-1))
-    return result
-
+def rand(*args, **kwargs):
+    def inner_rand(queue, shape, dtype):
+        from pyopencl.array import Array
+
+        result = Array(queue, shape, dtype)
+        _rand(result, np.random.randint(2**31-1))
+        return result
+
+    if isinstance(args[0], cl.Context):
+        from warnings import warn
+        warn("Passing a context as first argument is deprecated. "
+            "This will be continue to be accepted througout "
+            "versions 2011.x of PyOpenCL.",
+            DeprecationWarning, 2)
+        args = args[1:]
+
+    return inner_rand(*args, **kwargs)
 
 if __name__ == "__main__":
     import sys
-- 
GitLab