mitsuba-renderer / enoki

Enoki: structured vectorization and differentiation on modern processor architectures
Other
1.26k stars 94 forks source link

Vectorized RNG repeats values with nested arrays #130

Open sweeneychris opened 1 year ago

sweeneychris commented 1 year ago

I am trying to initialize a non-square matrix (i.e. a nested array) using Enoki's RNG. When I run the following code, I notice that the values are repeated across the array.

  using FloatP = enoki::Packet<enoki::Array<float, 3>, 2>;
  using RNG_2x3 = enoki::PCG32<FloatP>;

  RNG_2x3 my_rng;
  FloatP value = my_rng.next_float32();
  std::cout << "RNG VALUE:\n" << value << std::endl;

This gives the output:

RNG VALUE:
[[0.108379, 0.158414],
 [0.108379, 0.158414],
 [0.108379, 0.158414]]

So it appears that the RNG is only working on the outer dimension and is copying values to the other dimensions. Is there a way to use a single RNG to initialize random values for each element of a nested loop? Of course it is possible to do this with an explicit for loop, but I was curious if there is a way in the API to do this in one call.