def Slice(self, node): # Slice(start, stop, step){id(node), 'get'|'set'} array, start, stop, step = node.operands if start: start = self.visit(start) if stop: stop = self.visit(stop) if step: step = self.visit(step) return aappl( aterm("Slice"), [self.visit(array), start or aterm("None"), stop or aterm("None"), step or aterm("None")] )
def Literal(self, node): if node.vtype == int: return aint(node.val) if node.vtype == float: return areal(node.val) else: return aterm(node.val)
def annotate_dshape(ds): """ Convert a datashape instance into Aterm annotation >>> ds = dshape('2, 2, int32') >>> anno = dshape_anno(ds) dshape("2, 2, int32") >>> type(anno) <class 'AAppl'> """ assert isinstance(ds, DataShape) return aappl(aterm("dshape"), [astr(str(ds))])
def Assign(self, node): return aappl(aterm("Assign"), self.visit(node.operands))
def IndexNode(self, node): return aappl(aterm("Index"), self.visit(node.operands))
def Indexable(self, node): self.operands.append(node) return aappl(aterm("Array"), [])
def Op(self, node): opname = node.__class__.__name__ return aappl(aterm(opname), self.visit(node.children))