8000 update LinearIOSystem.__rmul__ for Python2/Python3 consistency · python-control/python-control@08b1c2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 08b1c2a

Browse files
committed
update LinearIOSystem.__rmul__ for Python2/Python3 consistency
1 parent 5356388 commit 08b1c2a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

control/iosys.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,24 @@ def __mul__(sys2, sys1):
254254

255255
def __rmul__(sys1, sys2):
256256
"""Pre-multiply an input/output systems by a scalar/matrix"""
257-
if isinstance(sys2, (int, float, np.number)):
257+
if isinstance(sys2, InputOutputSystem):
258+
# Both systems are InputOutputSystems => use __mul__
259+
return InputOutputSystem.__mul__(sys2, sys1)
260+
261+
elif isinstance(sys2, (int, float, np.number)):
258262
# TODO: Scale the output
259263
raise NotImplemented("Scalar multiplication not yet implemented")
260264

261265
elif isinstance(sys2, np.ndarray):
262266
# TODO: Post-multiply by a matrix
263267
raise NotImplemented("Matrix multiplication not yet implemented")
264268

265-
elif not isinstance(sys2, InputOutputSystem):
266-
raise TypeError("Unknown I/O system object ", sys1)
269+
elif isinstance(sys2, StateSpace):
270+
# TODO: Should eventuall preserve LinearIOSystem structure
271+
return StateSpace.__mul__(sys2, sys1)
267272

268273
else:
269-
# Both systems are InputOutputSystems => use __mul__
270-
return InputOutputSystem.__mul__(sys2, sys1)
274+
raise TypeError("Unknown I/O system object ", sys1)
271275

272276
def __add__(sys1, sys2):
273277
"""Add two input/output systems (parallel interconnection)"""

control/tests/type_conversion_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def sys_dict():
7272
('sub', 'flt', ['ss', 'tf', 'xrd', 'xio', 'xos', 'arr', 'flt']),
7373

7474
# op left ss tf frd lio ios arr flt
75-
('mul', 'ss', ['ss', 'ss', 'xrd', 'xio', 'xos', 'ss', 'ss' ]),
75+
('mul', 'ss', ['ss', 'ss', 'xrd', 'ss', 'xos', 'ss', 'ss' ]),
7676
('mul', 'tf', ['tf', 'tf', 'xrd', 'tf', 'xos', 'tf', 'tf' ]),
7777
('mul', 'frd', ['xrd', 'xrd', 'frd', 'xrd', 'E', 'xrd', 'frd']),
7878
('mul', 'lio', ['xio', 'xio', 'xrd', 'lio', 'ios', 'xio', 'xio']),

0 commit comments

Comments
 (0)
0