pyopencl icon indicating copy to clipboard operation
pyopencl copied to clipboard

Fill struct with random values

Open zehanort opened this issue 4 years ago • 1 comments

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.

zehanort avatar Mar 22 '20 04:03 zehanort

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.

inducer avatar Mar 29 '20 20:03 inducer