python 2.7 - write into indexed array in pyopencl -


hi wrote code in pyopencl sparse random vector problem can not write value indexed array problem? output zero!!

here code

import pyopencl cl import numpy np pyopencl import array  pyopencl import clrandom  ctx = cl.create_some_context() queue = cl.commandqueue(ctx,         properties=cl.command_queue_properties.profiling_enable)  x=array.zeros(queue, 512, dtype=np.float32 )  indices = clrandom.rand(queue, 17 , dtype=np.int32 ,luxury=2, a=1 , b=512)  clrandom.ranluxgenerator(queue,luxury=0).fill_normal(x[indices], mu=0, sigma=1)  print x 

it seems x[indices] returning copy instead of view.

>>> import pyopencl cl >>> import numpy np >>> pyopencl import array  >>> pyopencl import clrandom >>>  >>> ctx = cl.create_some_context() >>> queue = cl.commandqueue(ctx, ...         properties=cl.command_queue_properties.profiling_enable) >>>  >>> x=array.zeros(queue, 512, dtype=np.float32 ) >>>  >>> indices = clrandom.rand(queue, 17 , dtype=np.int32 ,luxury=2, a=1 , b=512) >>> x_cp = x[indices] >>> x_cp array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,         0.,  0.,  0.,  0.], dtype=float32) >>> clrandom.ranluxgenerator(queue,luxury=0).fill_normal(x_cp, mu=0, sigma=1) >>> x_cp array([ 1.16633689,  0.65845662,  1.97530341, -0.53728914,  1.38982224,         1.47071588, -0.73042828,  1.29367638,  1.2390343 ,  2.89497447,        -0.75589401,  0.04600764, -4.28992653,  0.50232059,  0.4881362 ,         0.01112503, -0.46737072], dtype=float32) >>> x[indices] array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,         0.,  0.,  0.,  0.], dtype=float32) 

you try following:

  1. create float32 array has same dimensions indices array, lets call tmp_random.
  2. generate random numbers , store them in tmp_random
  3. write kernel takes indices, tmp_random, , x arguments. each thread reads 1 index out of indices , according random number tmp_random , stores @ correct place in x.

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -