-
Hi, I'm struggling to make a torus shape plugin for mitsuba 3 but while i'm trying to write loops such as for in my code, i keep failing compilation due to conditional expressions within loop statements. below is the example code:
My intention of the code is finding a nearest root from the roots obtained by SolveQuartic(). Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @g1r4ff3, If you have a small number of roots to iterate over, a standard C++ for loop is fine (it will lead be fully unrolled in the generated kernel, but that's okay for a small iteration count and loop body size). I would then write something like: FloatP t = dr::Largest<FloatP>;
for (size_t root_i = 0; root_i < n_roots; ++root_i) { // <-- only scalar quantities here
// Update entries of `t` for this this is the closest root
Mask is_closest_root = ...; // your logic
t = dr::select(is_closest_root, roots[i], t);
} |
Beta Was this translation helpful? Give feedback.
Hello @g1r4ff3,
If you have a small number of roots to iterate over, a standard C++ for loop is fine (it will lead be fully unrolled in the generated kernel, but that's okay for a small iteration count and loop body size).
I would then write something like: