def alloc_array(self, array_t, shape_expr):
    if isinstance(shape_expr.type, ScalarT):
      dim = self.visit_expr(shape_expr)
      nelts = dim 
      shape_elts = [dim]
      ndims = 1 
    else:
      shape = self.visit_expr(shape_expr)
      ndims = array_t.rank
      shape_elts = ["%s.elt%d" % (shape, i) for i in xrange(ndims)]
      nelts = self.fresh_var("int64_t", "nelts", " * ".join(shape_elts))
    bytes_per_elt = array_t.elt_type.dtype.itemsize
    typename = self.to_ctype(array_t)
    result = self.fresh_var(typename, "new_array")
    raw_ptr_t = self.to_ctype(array_t.elt_type) + "*"
    self.setfield(result, "data.raw_ptr", "(%s) malloc(%s * %s)" % (raw_ptr_t, nelts, bytes_per_elt) )
    self.setfield(result, "data.base", "(PyObject*) NULL")
    self.setfield(result, "offset", "0")
    self.setfield(result, "size", nelts)
    # assume C-order layout
    strides_elts = [" * ".join(["1"] + shape_elts[(i+1):]) for i in xrange(ndims)]
    for i in xrange(ndims):
      self.setidx("%s.shape" % result, i, shape_elts[i])
      # assume c major layout for now
      self.setidx("%s.strides" % result, i, strides_elts[i])
    if config.debug:
      self.printf("[Debug] Done allocating array")
    return result
dataset/ETHPy150Open iskandr/parakeet/parakeet/c_backend/pymodule_compiler.py/PyModuleCompiler.alloc_array/original