def main(): """Run example.""" plan = Plan() pass_node_1 = WorkNode(Work(descr="Pass", worker=DoNothing())) pass_node_2 = WorkNode(Work(descr="Pass", worker=DoNothing())) select_node_m = SelectNode(index=0) select_node_s = SelectNode(index=0) plan.add_node(pass_node_1) plan.add_node(pass_node_2) plan.add_node(select_node_m, inputs=[pass_node_1, pass_node_2]) plan.add_node(select_node_s, inputs=[pass_node_1]) plan.inputs = [pass_node_1, pass_node_2] plan.outputs = [select_node_m, select_node_s] res = plan([[1, 2, 3], [2, 3, 4]]) print("Outputs: ", res)
def main(): """Entry point.""" print(__doc__) node = WorkNode(work=Work("Increment", worker=func)) node.set_start_hook(start_handler, node) node.set_stop_hook(stop_handler, node) plan = Plan() plan.add_node(node) plan.set_progress_hook(progress_handler) plan.inputs = [node] plan.outputs = [node] plan([5])
def main(): """Run example.""" print(__doc__) plan = Plan() node_1 = WorkNode(Work("Pass", worker=DoNothing())) node_2 = WorkNode(Work("Pass", worker=DoNothing())) node_3 = WorkNode(Work("Pass", worker=DoNothing())) pack_node_1 = PackNode() pack_node_2 = PackNode() plan.add_node(node_1) plan.add_node(node_2) plan.add_node(node_3) plan.add_node(pack_node_1, inputs=[node_1, node_2]) plan.add_node(pack_node_2, inputs=[node_2, node_3]) plan.inputs = [node_1, node_2, node_3] plan.outputs = [pack_node_1, pack_node_2] print(plan([1, 2, 3]))
def main(): """Run example.""" plan = Plan() node_a = WorkNode(work=Work("Linear transformation", worker=Linear(1, 1))) node_b = WorkNode(work=Work("Linear transformation", worker=Linear(2, 2))) node_c = WorkNode(work=Work("Linear transformation", worker=Linear(3, 3))) plan.add_node(node_a) plan.add_node(node_b, inputs=[node_a]) plan.add_node(node_c, inputs=[node_b]) plan.inputs = [node_a] plan.outputs = [node_c, node_b] print(plan([5]))
def main(): """Run example.""" p = Plan() g = WorkNode(Work("Generate random number", gen)) a = WorkNode(Work("Add 1", inc)) b = WorkNode(Work("Summation", plus)) p.add_node(g) p.add_node(a) p.add_node(b, inputs=[g, a]) p.inputs = [a] p.outputs = [b] x = [1] print(x) y = p(x) print(y)
def main(): """Run example.""" plan = Plan() pass_node_1 = WorkNode(Work("Pass", worker=DoNothing())) pass_node_2 = WorkNode(Work("Pass", worker=DoNothing())) map_node = MapNode(work=Work("Transformation", worker=Sum()), inputs=[pass_node_1, pass_node_2]) plan.add_node(pass_node_1) plan.add_node(pass_node_2) plan.add_node(map_node) plan.inputs = [pass_node_1, pass_node_2] plan.outputs = [map_node] res = plan([ [1, 1, 1], [2, 2, 2], ]) print("Outputs:", res)
def main(): """Run example.""" print(__doc__) p = Plan() a = WorkNode() b = WorkNode() c = WorkNode() d = WorkNode() p.add_node(a) p.add_node(b) p.add_node(c, inputs=[a]) p.add_node(d, inputs=[a, b]) print(d.inputs) p.remove_node(a) print(c.inputs) print(d.inputs) try: p.remove_node(a) # must raise an exception except RuntimeError as ex: print(ex)