Skip to content

Commit b065395

Browse files
author
jgray-19
committed
Remove all lambda functions
1 parent f3ccf10 commit b065395

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

src/pymadng/madp_pymad.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,26 @@ def recv_dat(self: mad_process, dat_sz: int, dat_typ: np.dtype):
193193

194194
# None ----------------------------------------------------------------------- #
195195

196-
send_nil = lambda self, input: None
197-
recv_nil = lambda self: None
196+
def send_nil(self: mad_process, input):
197+
return None
198+
199+
def recv_nil(self: mad_process):
200+
return None
198201

199202
# Boolean -------------------------------------------------------------------- #
203+
def send_bool(self: mad_process, input: bool):
204+
return self.fto_mad.write(struct.pack("?", input))
200205

201-
send_bool = lambda self, input: self.fto_mad.write(struct.pack("?", input))
202-
recv_bool = lambda self: recv_dat(self, 1, np.bool_)[0]
206+
def recv_bool(self: mad_process) -> bool:
207+
return recv_dat(self, 1, np.bool_)[0]
203208

204209
# int32 ---------------------------------------------------------------------- #
205210

206-
send_int = lambda self, input: send_dat(self, "i", input)
207-
recv_int = lambda self: recv_dat(self, 4, np.int32)[
208-
0
209-
] # Should it be a python int or a numpy int32?
211+
def send_int(self: mad_process, input: int):
212+
return send_dat(self, "i", input)
213+
214+
def recv_int(self: mad_process) -> int:
215+
return recv_dat(self, 4, np.int32)[0]
210216

211217
# String --------------------------------------------------------------------- #
212218

@@ -217,23 +223,30 @@ def send_str(self: mad_process, input: str):
217223

218224

219225
def recv_str(self: mad_process) -> str:
220-
return self.ffrom_mad.read(recv_int(self)).decode("utf-8")
226+
res = self.ffrom_mad.read(recv_int(self)).decode("utf-8")
227+
return res
221228

222229

223230
# number (float64) ----------------------------------------------------------- #
224231

225-
send_num = lambda self, input: send_dat(self, "d", input)
226-
recv_num = lambda self: recv_dat(self, 8, np.float64)[0]
232+
def send_num(self: mad_process, input: float):
233+
return send_dat(self, "d", input)
234+
235+
def recv_num(self: mad_process) -> float:
236+
return recv_dat(self, 8, np.float64)[0]
227237

228238
# Complex (complex128) ------------------------------------------------------- #
229239

230-
send_cpx = lambda self, input: send_dat(self, "dd", input.real, input.imag)
231-
recv_cpx = lambda self: recv_dat(self, 16, np.complex128)[0]
240+
def send_cpx(self: mad_process, input: complex):
241+
return send_dat(self, "dd", input.real, input.imag)
232242

233-
# Range ---------------------------------------------------------------------- #
243+
def recv_cpx(self: mad_process) -> complex:
244+
return recv_dat(self, 16, np.complex128)[0]
234245

235-
send_grng = lambda self, start, stop, size: send_dat(self, "ddi", start, stop, size)
246+
# Range ---------------------------------------------------------------------- #
236247

248+
def send_grng(self, start: float, stop: float, size: int):
249+
send_dat(self, "ddi", start, stop, size)
237250

238251
def recv_rng(self: mad_process) -> np.ndarray:
239252
return np.linspace(*struct.unpack("ddi", self.ffrom_mad.read(20)))
@@ -245,7 +258,8 @@ def recv_lrng(self: mad_process) -> np.ndarray:
245258

246259
# irange --------------------------------------------------------------------- #
247260

248-
send_irng = lambda self, rng: send_dat(self, "iii", rng.start, rng.stop, rng.step)
261+
def send_irng(self: mad_process, rng: range):
262+
return send_dat(self, "iii", rng.start, rng.stop, rng.step)
249263

250264
def recv_irng(self: mad_process) -> range:
251265
start, stop, step = recv_dat(self, 12, np.int32)
@@ -266,9 +280,14 @@ def recv_gmat(self: mad_process, dtype: np.dtype) -> str:
266280
return recv_dat(self, shape[0] * shape[1] * dtype.itemsize, dtype).reshape(shape)
267281

268282

269-
recv_mat = lambda self: recv_gmat(self, np.dtype("float64"))
270-
recv_cmat = lambda self: recv_gmat(self, np.dtype("complex128"))
271-
recv_imat = lambda self: recv_gmat(self, np.dtype("int32"))
283+
def recv_mat(self: mad_process) -> np.ndarray:
284+
return recv_gmat(self, np.dtype("float64"))
285+
286+
def recv_cmat(self: mad_process) -> np.ndarray:
287+
return recv_gmat(self, np.dtype("complex128"))
288+
289+
def recv_imat(self: mad_process) -> np.ndarray:
290+
return recv_gmat(self, np.dtype("int32"))
272291

273292
# monomial ------------------------------------------------------------------- #
274293

@@ -277,7 +296,8 @@ def send_mono(self: mad_process, mono: np.ndarray):
277296
send_int(self, mono.size)
278297
self.fto_mad.write(mono.tobytes())
279298

280-
recv_mono = lambda self: recv_dat(self, recv_int(self), np.ubyte)
299+
def recv_mono(self: mad_process) -> np.ndarray:
300+
return recv_dat(self, recv_int(self), np.ubyte)
281301

282302
# TPSA ----------------------------------------------------------------------- #
283303

@@ -308,6 +328,12 @@ def recv_gtpsa(self: mad_process, dtype: np.dtype) -> np.ndarray:
308328
return mono_list, coefficients
309329

310330

331+
def recv_ctpa(self: mad_process):
332+
return recv_gtpsa(self, np.dtype("complex128"))
333+
334+
def recv_tpsa(self: mad_process):
335+
return recv_gtpsa(self, np.dtype("float64"))
336+
311337
recv_ctpa = lambda self: recv_gtpsa(self, np.dtype("complex128"))
312338
recv_tpsa = lambda self: recv_gtpsa(self, np.dtype("float64"))
313339

@@ -334,8 +360,11 @@ def recv_list(self: mad_process) -> list:
334360

335361
# object (table with metatable are treated as pure reference) ---------------- #
336362

337-
recv_ref = lambda self: mad_ref(self.varname, self)
338-
send_ref = lambda self, obj: send_str(self, f"return {obj._name}")
363+
def recv_ref(self: mad_process):
364+
return mad_ref(self.varname, self)
365+
366+
def send_ref(self, obj: mad_ref):
367+
return send_str(self, f"return {obj._name}")
339368

340369
# error ---------------------------------------------------------------------- #
341370

0 commit comments

Comments
 (0)