def test_Var(): v1 = var() assert isinstance(v1, Var) v2 = var() assert v1 is not v2 assert v1 != v2 assert v1.matches(v2) assert v1.matches(object()) assert str(v1) == v1.tag v3 = Var('name') assert repr(v3) == 'Var(name)' repr(v2) assert v1.tag != v2.tag
from myia.ir import Constant, GraphCloner, isomorphic, sexp_to_graph from myia.opt import ( LocalPassOptimizer, NodeMap, PatternSubstitutionOptimization as psub, cse, pattern_replacer, ) from myia.pipeline import scalar_pipeline from myia.prim import Primitive, ops as prim from myia.utils import InferenceError, Merge from myia.utils.unify import Var, var from ..common import f64, i64, to_abstract_test X = Var('X') Y = Var('Y') V = var(lambda n: n.is_constant()) parse = scalar_pipeline \ .configure({ 'resources.convert.object_map': Merge({ operations.getitem: prim.tuple_getitem, operations.user_switch: prim.switch }) }) \ .select('resources', 'parse', 'resolve') \ .make_transformer('input', 'graph')
self.on_edge = on_edge 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)
self.on_edge = on_edge 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)
from myia import operations from myia.ir import Constant, GraphCloner, isomorphic, sexp_to_graph from myia.operations import Primitive, primitives as prim from myia.opt import ( LocalPassOptimizer, PatternSubstitutionOptimization as psub, cse, pattern_replacer, ) from myia.pipeline import scalar_pipeline, steps from myia.testing.common import i64, to_abstract_test from myia.utils import InferenceError, Merge from myia.utils.unify import Var, var from myia.validate import ValidationError X = Var("X") Y = Var("Y") V = var(lambda n: n.is_constant()) parse = ( scalar_pipeline.configure( { "convert.object_map": Merge( { operations.getitem: prim.tuple_getitem, operations.user_switch: prim.switch, } ), } )