def transform_IndexMap(self, expr, output = None):
    shape = expr.shape
    
    fn = expr.fn 
    dims = self.tuple_elts(shape)
    n_dims = len(dims)
    if n_dims == 1: shape = dims[0]
    if output is None: output = self.create_output_array(fn, [shape], shape)
    old_closure_args = self.closure_elts(fn)
    old_closure_arg_types = get_types(old_closure_args)
    fn = self.get_fn(fn)
    
    closure_arg_names = [self.fresh_input_name(clos_arg) for clos_arg in old_closure_args] 
    new_closure_vars = [Var(name, type=t) 
                        for name, t in 
                        zip(closure_arg_names, old_closure_arg_types)]
    
      
    old_input_types = fn.input_types
    last_input_type = old_input_types[-1]
    index_is_tuple = isinstance(last_input_type, TupleT)
    if index_is_tuple:
      index_types = last_input_type.elt_types
    else:
      index_types = old_input_types[-n_dims:]
    
    idx_names = self.fresh_index_names(n_dims)
    assert len(index_types) == n_dims, \
        "Mismatch between bounds of IndexMap %s and %d index formal arguments" % (dims, len(index_types))
    output_name = names.refresh("output")  
    
    new_input_names = [output_name] + closure_arg_names + idx_names            
    new_input_types =  [output.type]  + old_closure_arg_types + list(index_types)
    new_fn_name = names.fresh("idx_" + names.original(fn.name))
    new_fn, builder, input_vars = build_fn(new_input_types, NoneType,
                                           name = new_fn_name,  
                                           input_names = new_input_names)
    new_fn.created_by = self.fn.created_by 
    output_var = input_vars[0]
    
    idx_vars = input_vars[-n_dims:]
    
    if not self.is_none(expr.start_index):
      if isinstance(expr.start_index.type, ScalarT):
        idx_vars = [builder.add(idx, expr.start_index, "idx") for idx in idx_vars]
      else:
        start_indices = builder.tuple_elts(expr.start_index)
        assert len(start_indices) == len(idx_vars), \
          "Mismatch between number of indices %s and start offsets %s" % (idx_vars, start_indices)
        idx_vars = [builder.add(idx, offset, "idx%d" % i) 
                    for i, (idx,offset) 
                    in enumerate(zip(idx_vars, start_indices))]
           
    
    if index_is_tuple:
      elt_result = builder.call(fn, new_closure_vars + [builder.tuple(idx_vars)])
    else:
      elt_result = builder.call(fn, new_closure_vars + idx_vars)
    if len(idx_vars) == 1:
      builder.setidx(output_var, idx_vars[0], elt_result)
    else:
      builder.setidx(output_var, builder.tuple(idx_vars), elt_result)

      
    builder.return_(none)
    new_closure = self.closure(new_fn, (output,) + tuple(old_closure_args)  )
    self.insert_parfor(new_closure, shape, len(old_closure_args))
    return output
dataset/ETHPy150Open iskandr/parakeet/parakeet/transforms/indexify_adverbs.py/IndexifyAdverbs.transform_IndexMap/original