mitsuba-renderer / enoki

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

Is enoki support array index? #68

Closed andyyankai closed 4 years ago

andyyankai commented 4 years ago

for example A = [1, 2, 3, 4, 5] I = [0, 1, 1, 2] then A[I] = [A[0], A[1], A[1], A[2]] = [1, 2, 2, 3]

or

    FloatD some = {2.3f, 3.4f, 4.5f, 5.6f, 6.7f, 7.8f};
    IntC index = {1,1,3,3,5};

    FloatD check = some[index];

    value of check should be: [3.4f, 3.4f, 5.6f, 5.6f, 7.8f]
mp3guy commented 4 years ago

This is the gather operation. But, it probably isn't as fast as you might want it to be.

Speierers commented 4 years ago

Indeed, you will need a gather operator to do this (see this)

In your code this should translate to:

FloatD some = {2.3f, 3.4f, 4.5f, 5.6f, 6.7f, 7.8f};
IntC index = {1,1,3,3,5};
FloatD check = gather<FloatD>(some, index); // or something very similar to this
andyyankai commented 4 years ago

When I tried: FloatC some = {2.3f, 3.4f, 4.5f, 5.6f, 6.7f, 7.8f}; IntC index = {1,1,3,3,5}; FloatC check = gather<FloatC>(some, index); its working, but when I change FloatC into FloatD I have an error: image

Speierers commented 4 years ago

Could you try with IntD instead of IntC when working with FloatD?

andyyankai commented 4 years ago

Yes, seems working now.