def __hrepr__(self, H, hrepr): """Return HTML representation (uses buche-cytoscape).""" if hrepr.config.depth > 1 and not hrepr.config.graph_expand_all: label = short_labeler.label(self, True) return H.span['node', f'node-Graph'](label) dc = hrepr.config.duplicate_constants dfv = hrepr.config.duplicate_free_variables fin = hrepr.config.function_in_node fr = hrepr.config.follow_references tgen = hrepr.config.node_tooltip cgen = hrepr.config.node_class xsty = hrepr.config.graph_style beau = hrepr.config.graph_beautify gpr = MyiaGraphPrinter( {self}, duplicate_constants=True if dc is None else dc, duplicate_free_variables=True if dfv is None else dfv, function_in_node=True if fin is None else fin, follow_references=True if fr is None else fr, tooltip_gen=tgen, class_gen=cgen, extra_style=xsty, beautify=True if beau is None else beau) gpr.process() return gpr.__hrepr__(H, hrepr)
def run_test(args): pip = pipeline.make() argspec = tuple({'value': arg} for arg in args) pip.resources.inferrer.fill_in(argspec) print(argspec) for arg in argspec: del arg['value'] result_py = fn(*args) try: res = pip(input=fn, argspec=argspec) except InferenceError as ierr: print_inference_error(ierr) raise ierr except ValidationError as verr: print('Collected the following errors:') for err in verr.errors: n = err.node nlbl = lbl.label(n) print(f' {nlbl} ({type(n).__name__}) :: {n.type}') print(f' {err.args[0]}') raise verr result_final = res['output'](*args) if isinstance(result_py, numpy.ndarray): assert (result_py == result_final).all() else: assert result_py == result_final
def _opt_fancy_array_map(optimizer, node, equiv): xs = equiv[Xs] v = equiv[V] if v.is_constant_graph(): return node name = short_labeler.label(v) ct = Constant(GraphCosmeticPrimitive(f'[{name}]')) with About(node.debug, 'cosmetic'): return Apply([ct, *xs], node.graph)
def mkdict(info): d = {k: v for k, v in info.__dict__.items() if not k.startswith('_') and k not in exclude} tr = d.get('trace', None) if tr: fr = tr[-3] d['trace'] = parser.Location( fr.filename, fr.lineno, 0, fr.lineno, 0, None ) d['name'] = short_labeler.label(info) return d
def run_test(args): if isinstance(args, Exception): exc = type(args) args = args.args else: exc = None pdef = pipeline if not validate: pdef = pdef.configure(validate=False) pip = pdef.make() if abstract is None: argspec = tuple( from_value(arg, broaden=True) for arg in args) else: argspec = tuple(to_abstract_test(a) for a in abstract) if exc is not None: try: mfn = pip(input=fn, argspec=argspec) mfn['output'](*args) except exc: pass return result_py = fn(*args) try: res = pip(input=fn, argspec=argspec) except InferenceError as ierr: print_inference_error(ierr) raise ierr except ValidationError as verr: print('Collected the following errors:') for err in verr.errors: n = err.node nlbl = lbl.label(n) tname = type(n).__name__ print(f' {nlbl} ({tname}) :: {n.abstract}') print(f' {err.args[0]}') raise verr result_final = res['output'](*args) assert _eq(result_py, result_final)
def run_test(args): pip = pipeline.make() argspec = tuple(from_value(arg, broaden=True) for arg in args) result_py = fn(*args) try: res = pip(input=fn, argspec=argspec) except InferenceError as ierr: print_inference_error(ierr) raise ierr except ValidationError as verr: print('Collected the following errors:') for err in verr.errors: n = err.node nlbl = lbl.label(n) print(f' {nlbl} ({type(n).__name__}) :: {n.type}') print(f' {err.args[0]}') raise verr result_final = res['output'](*args) assert _eq(result_py, result_final)
def lbl(x): if isinstance(x, ParentProxy): return f"{short_labeler.label(x.graph)}'" else: return short_labeler.label(x)
def __hrepr__(self, H, hrepr): class_name = 'constant' label = 'Prox:' + short_labeler.label(self.graph, True) return H.span['node', f'node-{class_name}'](label)
def __hrepr__(self, H, hrepr): class_name = self.__class__.__name__.lower() label = short_labeler.label(self, True) return H.span['node', f'node-{class_name}'](label)
def __hrepr__(self, H, hrepr): class_name = "constant" label = "Prox:" + short_labeler.label(self.graph, True) return H.span["node", f"node-{class_name}"](label)
def name(node): return short_labeler.label(node, fn_label=False)