inducer / pyopencl

OpenCL integration for Python, plus shiny features
http://mathema.tician.de/software/pyopencl
Other
1.06k stars 242 forks source link

Fill struct with random values #334

Open zehanort opened 4 years ago

zehanort commented 4 years ago

Is it possible to fill a custom struct (or an array of custom structs) with random values after I have registered its type? For a "primitive" type, I can to it like this:

from pyopencl.clrandom import rand as clrand
import pyopencl.cltypes as cltypes

a = clrand(queue, (1024,), dtype=cltypes.float, a=-10.0, b=10.0)

It even works for vector types:

a = clrand(queue, (1024,), dtype=cltypes.float4, a=-10.0, b=10.0)

Is there a way to do it for structs? E.g. if I have a struct with an int16 and a float32, I would expect a similar syntax to create such random structs, where each struct in the array has been initialized recursively, using the respective RNG of the "primitive" types that constitute the struct type.

I am extremely sorry in advance in case I missed something from the documentation and/or the examples and tests.

inducer commented 4 years ago

Nope, sorry, there's nothing canned like that. If you'd like to work on that, I'd be open to considering a PR that implements filling structs.