|
18 | 18 | mad.send("cm1 = (MAD.cmatrix(10000, 1000) + 1i)") |
19 | 19 |
|
20 | 20 | # Create a string the manipulates the complex matrix in MAD and sends the result it to Python |
21 | | -cmatrixString = """ |
| 21 | +cmatrix_str = """ |
22 | 22 | {0} = cm1 {1} {2} |
23 | 23 | py:send({0})""" |
24 | 24 |
|
25 | | -mad.send( |
26 | | - cmatrixString.format("cm4", "*", 1) |
27 | | -) ## Set cm4 to cm1 * 1 and send it to Python |
28 | | -mad.send( |
29 | | - cmatrixString.format("cm1", "*", 2) |
30 | | -) ## Set cm1 to cm1 * 2 and send it to Python |
31 | | -mad.send( |
32 | | - cmatrixString.format("cm2", "*", 2) |
33 | | -) ## Set cm2 to cm1 * 2 and send it to Python |
34 | | -mad.send( |
35 | | - cmatrixString.format("cm3", "/", 3) |
36 | | -) ## Set cm3 to cm1 / 3 and send it to Python |
| 25 | +mad.send(cmatrix_str.format("cm4", "*", 1)) ## Set cm4 to cm1 * 1 and send it to Python |
| 26 | +mad.send(cmatrix_str.format("cm1", "*", 2)) ## Set cm1 to cm1 * 2 and send it to Python |
| 27 | +mad.send(cmatrix_str.format("cm2", "*", 2)) ## Set cm2 to cm1 * 2 and send it to Python |
| 28 | +mad.send(cmatrix_str.format("cm3", "/", 3)) ## Set cm3 to cm1 / 3 and send it to Python |
37 | 29 |
|
38 | 30 | ## Create a vector in MAD and send it to Python |
39 | 31 | mad.send(""" |
|
72 | 64 | mad_list = mad.recv("list") |
73 | 65 | for i, inner_list in enumerate(mad_list): |
74 | 66 | for j, val in enumerate(inner_list): |
75 | | - print( |
76 | | - f"List value at [{i}][{j}]: {val} == {my_list[i][j]}", val == my_list[i][j] |
77 | | - ) |
| 67 | + print(f"List value at [{i}][{j}]: {val} == {my_list[i][j]}", val == my_list[i][j]) |
78 | 68 |
|
79 | 69 | # Send an integer to MAD and receive a changed version back |
80 | | -myInt = 4 |
| 70 | +an_int = 4 |
81 | 71 | mad.send(""" |
82 | | -local myInt = py:recv() |
83 | | -py:send(myInt+2) |
| 72 | +local an_int = py:recv() |
| 73 | +py:send(an_int+2) |
84 | 74 | """) |
85 | | -mad.send(myInt) |
| 75 | +mad.send(an_int) |
86 | 76 | print("Integers", mad.recv() == 6) |
87 | 77 |
|
88 | 78 | # Send a float to MAD and receive a changed version back |
89 | | -myFloat = 6.612 |
| 79 | +a_float = 6.612 |
90 | 80 | mad.send(""" |
91 | | -local myFloat = py:recv() |
92 | | -py:send(myFloat + 0.56) |
| 81 | +local a_float = py:recv() |
| 82 | +py:send(a_float + 0.56) |
93 | 83 | """) |
94 | | -mad.send(myFloat) |
| 84 | +mad.send(a_float) |
95 | 85 | print("Floats", mad.recv() == 6.612 + 0.56) |
96 | 86 |
|
97 | 87 | # Send a complex number to MAD and receive a changed version back |
98 | | -myCpx = 6.612 + 4j |
| 88 | +a_cpx = 6.612 + 4j |
99 | 89 | mad.send(""" |
100 | | -local myCpx = py:recv() |
101 | | -py:send(myCpx + 0.5i) |
| 90 | +local a_cpx = py:recv() |
| 91 | +py:send(a_cpx + 0.5i) |
102 | 92 | """) |
103 | | -mad.send(myCpx) |
| 93 | +mad.send(a_cpx) |
104 | 94 | print("Complex", mad.recv() == 6.612 + 4.5j) |
105 | 95 |
|
106 | 96 | # Send None to MAD and it back |
107 | 97 | mad.send(""" |
108 | | -local myNil = py:recv() |
109 | | -py:send(myNil) |
| 98 | +local a_nil = py:recv() |
| 99 | +py:send(a_nil) |
110 | 100 | """) |
111 | 101 | mad.send(None) |
112 | 102 | print("Nil/None", mad.recv() is None) |
|
0 commit comments