-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance-method-node.py
More file actions
executable file
·86 lines (65 loc) · 1.91 KB
/
instance-method-node.py
File metadata and controls
executable file
·86 lines (65 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
An example of using a method of a class instance, as a node on the graph
class Foo():
def bar(self, v):
return v
g.add(Foo().bar, Foo().bar)
"""
from collections import defaultdict
import operator as op
from functools import partial
from pprint import pprint as pp
from hyperway.stepper import run_stepper, StepperC
from hyperway.graph import Graph
from hyperway.edges import Connection, as_connections, make_edge, get_connections
from hyperway.packer import argspack, test_argpack
from hyperway.graph import add, connect
from hyperway.nodes import Unit, as_unit
from hyperway.reader import read_linear_chain, read_tree_chain, flat_graph
# import smoke_tests
# A bunch of test functions such as add_4
import hyperway.tools as t
primary_graph = Graph(tuple)
g = primary_graph
f = t.factory
def main():
# smoke_tests.main()
return run()
class Printer:
"""In this example, we want to reference the print count.
We _could_ globalise the var - but instead we generate an instance
and supply a function to the graph.
printer = Printer()
g.add(f.add_4, printer.print_out)
"""
print_count = 0
def print_out(self, *a, **kw):
# global print_count
self.print_count += 1
print(' -- print_out', self.print_count, a, kw)
return (a, kw)
def run():
v = run_a()
# v = run_b()
return v
def run_a():
"""
+4
i +2 +3 print
+5
10
1 3 6 print
11
"""
printer = Printer()
g = Graph(tuple)
u_add_3 = as_unit(f.add_3)
u_print = as_unit(printer.print_out)
m = (u_print, f.add_3)
e = make_edge(u_add_3, m[0])
g.add(u_add_3, f.add_4)
g.add_edge(e)
g.stepper_prepare(u_add_3, 1)
return g
if __name__ == '__main__':
g= main()