From 23d7336407c83b16d23e12192497ed244b74deaa Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 16 Oct 2011 12:08:07 -0400 Subject: [PATCH] Fix, document fill_rand. --- doc/source/array.rst | 4 ++++ pyopencl/clrandom.py | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/source/array.rst b/doc/source/array.rst index bd9ce90c..e49f8305 100644 --- a/doc/source/array.rst +++ b/doc/source/array.rst @@ -418,6 +418,10 @@ Generating Arrays of Random Numbers Return an array of `shape` filled with random values of `dtype` in the range [0,1). +.. function:: fill_rand(result, queue=None) + + Fill *result* with random values of `dtype` in the range [0,1). + PyOpenCL now includes and uses the `RANLUXCL random number generator `_ by Ivar Ursin Nikolaisen. In addition to being usable through the convenience functions above, it is diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index 7710bc60..efa39f2e 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -27,7 +27,7 @@ class RanluxGenerator(object): self.use_legacy_init = use_legacy_init self.max_work_items = max_work_items - prg = cl.Program(queue.context, """ + src = """ %s #include @@ -36,7 +36,8 @@ class RanluxGenerator(object): { ranluxcl_initialization(seeds, ranluxcltab); } - """ % self.generate_settings_defines()).build() + """ % self.generate_settings_defines() + prg = cl.Program(queue.context, src).build() self.state = cl_array.empty(queue, (num_work_items, 112), dtype=np.uint8) prg.init_ranlux(queue, (num_work_items,), None, np.uint32(seed), @@ -218,12 +219,14 @@ def _get_generator(queue): -@cl_array.elwise_kernel_runner -def _rand(output, seed): - return get_rand_kernel(output.context, output.dtype) +def fill_rand(result, queue=None): + if queue is None: + queue = result.queue + gen = _get_generator(queue) + gen.fill_uniform(result) + + -def fill_rand(result): - _rand(result, np.random.randint(2**31-1)) def rand(*args, **kwargs): def inner_rand(queue, shape, dtype): -- GitLab