How does Relay handle while loop

I only found IR ‘if’, but no other control flow related IR.

Please give me some hint, thanks

Curious too.

I guess when condition is not expressed with symbol, the body will be unrolled. Is there a solution to handle symbolic condition? @tqchen

Maybe using recursion? Functional languages don’t have for loop usually.

we will try to transform imperative loop into recursion (without reference) using something similar to lambda the ultimate imperative.

You can see an example which accumulates state in a tensor over some number of iterations.

Our previous front-end layer supported translating forms of loops directly into the IR, and I plan on adding some helpers to IR builder for building loops.

The only thing that we can’t support currently is typing changing updates to a variable i.e if you start with a variable of type x : Tensor<(10, 5, 5), f32> you can’t say assign y : Tesnor<(5), f32> to it.

EDIT:

I noticed that the cases are flipped in the example program (which is only used for testing type checking):

       def f(n: i32, data: f32) -> f32 {
          if (n == 0) {
              return data;
          } else {
              return f(n - 1, log(data));
          }
       }
       # Main
       f(2, 10000);
1 Like