def test_SVar(): sv = SVar() assert not sv.matches(1) assert not sv.matches((1, 2)) assert sv.matches(Seq((1, ))) ssv = str(sv) assert ssv == f'*{sv.tag}' assert repr(sv) == f'SVar({sv.tag})' sv2 = SVar(var(filter=(True, False, 0, 1))) assert sv.matches(sv2) assert sv2.matches(Seq((True, False, 1))) assert not sv2.matches(Seq((1, 2)))
def graph_display(self, gprint, node, g, cl): """Display a node in cytoscape graph.""" if gprint.function_in_node and self.on_edge: lbl = gprint.label(node, '') gprint.cynode(id=node, label=lbl, parent=g, classes=cl) gprint.process_edges([(node, (self.label, 'fn-edge'), node.inputs[1])]) else: gprint.process_node_generic(node, g, cl) make_tuple = GraphCosmeticPrimitive('(...)') X = Var('X') Y = Var('Y') Xs = SVar(Var()) V = var(lambda x: x.is_constant()) V1 = var(lambda x: x.is_constant()) V2 = var(lambda x: x.is_constant()) L = var(lambda x: x.is_constant_graph()) @pattern_replacer(primops.make_tuple, Xs) def _opt_fancy_make_tuple(optimizer, node, equiv): xs = equiv[Xs] ct = Constant(GraphCosmeticPrimitive('(...)')) with About(node.debug, 'cosmetic'): return Apply([ct, *xs], node.graph) @pattern_replacer(primops.tuple_getitem, X, V)