def visit_ArrayView(self, expr): strides_tuple = self.visit_expr(expr.strides) if strides_tuple.__class__ is Const: strides_tuple = abstract_tuple([strides_tuple]) shape_tuple = self.visit_expr(expr.shape) if shape_tuple.__class__ is Const: shape_tuple = abstract_tuple([shape_tuple]) offset = self.visit_expr(expr.offset) if strides_tuple.__class__ is Tuple or shape_tuple.__class__ is Tuple or offset.__class__ is Const: return Array(strides_tuple, shape_tuple, offset) else: return unknown
def visit_AllocArray(self, expr): if expr.order == "C": elts = (unknown,) * (expr.type.rank-1) + (one,) strides = abstract_tuple(elts) elif expr.order == "F": elts = (one, ) + (unknown,) * (expr.type.rank-1) strides = abstract_tuple(elts) else: strides = unknown shape = self.visit_expr(expr.shape) offset = Const(0) return Array(strides, shape, offset)
def visit_AllocArray(self, expr): if expr.order == "C": elts = (unknown, ) * (expr.type.rank - 1) + (one, ) strides = abstract_tuple(elts) elif expr.order == "F": elts = (one, ) + (unknown, ) * (expr.type.rank - 1) strides = abstract_tuple(elts) else: strides = unknown shape = self.visit_expr(expr.shape) offset = Const(0) return Array(strides, shape, offset)
def from_python(python_value): t = type(python_value) if t is ndarray: elt_size = python_value.dtype.itemsize strides = [] for s in python_value.strides: strides.append(specialization_const(s/elt_size)) strides = abstract_tuple(strides) shape = abstract_tuple([specialization_const(dim) for dim in python_value.shape]) return Array(strides, shape) elif t is tuple: return abstract_tuple(from_python_list(python_value)) elif python_value == 0: return zero elif python_value == 1: return one else: return unknown
def from_python(python_value): t = type(python_value) if t is ndarray: elt_size = python_value.dtype.itemsize strides = [] for s in python_value.strides: strides.append(specialization_const(s / elt_size)) strides = abstract_tuple(strides) shape = abstract_tuple( [specialization_const(dim) for dim in python_value.shape]) return Array(strides, shape) elif t is tuple: return abstract_tuple(from_python_list(python_value)) elif python_value == 0: return zero elif python_value == 1: return one else: return unknown
def visit_Struct(self, expr): if expr.type.__class__ is TupleT: return abstract_tuple(self.visit_expr_list(expr.args)) elif expr.type.__class__ is ArrayT: stride_pos = expr.type.field_pos("strides") stride_arg = expr.args[stride_pos] stride_val = self.visit_expr(stride_arg) return Array(stride_val) else: return unknown
def visit_Tuple(self, expr): return abstract_tuple(self.visit_expr_list(expr.elts))