def nested_loops(self, 
                     upper_bounds, 
                     loop_body, 
                     lower_bounds = None, 
                     step_sizes = None, 
                     index_vars_as_list = False):
    upper_bounds = self._to_list(upper_bounds)
    
    n_loops = len(upper_bounds)
    assert lower_bounds is None or len(lower_bounds) == n_loops
    assert step_sizes is None or len(step_sizes) == n_loops 
    
    if lower_bounds is None:
      lower_bounds = [self.int(0) for _ in upper_bounds]
    else:
      lower_bounds = self._to_list(lower_bounds)
    
    if step_sizes is None:
      step_sizes = [self.int(1) for _ in upper_bounds]
    else:
      step_sizes = self._to_list(step_sizes)
    
    
    def build_loops(index_vars = ()):
      n_indices = len(index_vars)
      if n_indices == n_loops:
        if isinstance(loop_body, Expr):
          input_types = self.input_types(loop_body)
          if len(input_types) == len(index_vars):
            result = self.call(loop_body, index_vars)
          else:
            result = self.call(loop_body, [self.tuple(index_vars)])
        else:
          if index_vars_as_list:
            idx_tuple = list(index_vars)
          elif n_indices > 1:
            idx_tuple = self.tuple(index_vars)
          else:
            idx_tuple = index_vars[0]
          assert hasattr(loop_body, '__call__'), "Expected callable value, got %s" % (loop_body,)
          result = loop_body(idx_tuple)
        assert self.is_none(result), "Expected loop body to return None, not %s" % (result,)
      else:
        def inner_loop_body(idx):
          build_loops(index_vars + (idx,))
        lower = lower_bounds[n_indices]
        upper = upper_bounds[n_indices]  
        step = step_sizes[n_indices]
        # sanity check the bounds 
        if lower.__class__ is Const and upper.__class__ is Const and step.__class__ is Const:
          if 0 < step.value:
            assert lower.value > upper.value, \
              "Attempting to build invalid loop from %s to %s by %s" % (lower, upper, step)
          elif step.value > 0:
            assert upper.value > lower.value, \
              "Attempting to build invalid loop from %s to %s by %s" % (lower, upper, step) 
        self.loop(lower, upper, inner_loop_body, step=step)
    build_loops()
dataset/ETHPy150Open iskandr/parakeet/parakeet/builder/loop_builder.py/LoopBuilder.nested_loops/swapped operands of `<`