def getidx(self, arr, idx, full_array = False):
    """
    Given either the compiled string representation or Parakeet IR
    for an array and index, construct a C indexing expression 
    """

    if isinstance(arr, Expr):
      if isinstance(arr.type, ArrayT):
        arr = self.visit_expr(arr)
        ptr = "%s.data.raw_ptr" % arr
      else:
        assert isinstance(arr.type, PtrT), \
          "Expected array or pointer but got %s : %s" % (arr, arr.type)
        arr = None
        ptr = self.visit_expr(arr)
    else:    
      assert isinstance(arr, str), "Expected string repr of array but got %s" % arr
      if full_array:
        ptr = "%s.data.raw_ptr" % arr 
      else:
        ptr = arr 
        arr = None  
        
    if isinstance(idx, Expr):
      if isinstance(idx.type, TupleT):
        nelts = len(idx.type.elt_types)
        tuple_value = self.visit_expr(idx)
        idx = ["%s.elt%d" % (tuple_value,i) for i in xrange(nelts)]
      else:
        assert isinstance(idx.type, ScalarT), "Expected index %s to be scalar or tuple" % idx
        offset = idx 
        
    if isinstance(idx, str):
      offset = idx 
    elif isinstance(idx, (int,long)):
      offset = "%s" % idx
    elif isinstance(idx, (list,tuple)):
      assert arr, "Expected full array but only pointer %s is available" % ptr 
      offset = "0"
      for i,idx_elt in enumerate(idx):
        if isinstance(idx_elt, Expr):
          idx_elt = self.visit_expr(idx_elt)
        offset = self.add(offset, self.mul("%s.strides[%d]" % (arr,i), idx_elt))
      
    return "%s[%s]" % (ptr, offset)
dataset/ETHPy150Open iskandr/parakeet/parakeet/c_backend/pymodule_compiler.py/PyModuleCompiler.getidx/original