Skip to content

Commit af8d4ee

Browse files
authored
Merge pull request python-control#186 from roryyorke/rory/series-fix
FIX: bdalg.series should reverse order of arguments in product
2 parents 10e8f47 + 6ec4e81 commit af8d4ee

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

control/bdalg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def series(sys1, *sysn):
6767
Parameters
6868
----------
6969
sys1: scalar, StateSpace, TransferFunction, or FRD
70-
*sysn: other scalers, StateSpaces, TransferFunctions, or FRDs
70+
*sysn: other scalars, StateSpaces, TransferFunctions, or FRDs
7171
7272
Returns
7373
-------
@@ -103,7 +103,7 @@ def series(sys1, *sysn):
103103
104104
"""
105105
from functools import reduce
106-
return reduce(lambda x, y:x*y, sysn, sys1)
106+
return reduce(lambda x, y:y*x, sysn, sys1)
107107

108108
def parallel(sys1, *sysn):
109109
"""
@@ -112,7 +112,7 @@ def parallel(sys1, *sysn):
112112
Parameters
113113
----------
114114
sys1: scalar, StateSpace, TransferFunction, or FRD
115-
*sysn: other scalers, StateSpaces, TransferFunctions, or FRDs
115+
*sysn: other scalars, StateSpaces, TransferFunctions, or FRDs
116116
117117
Returns
118118
-------

control/tests/bdalg_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ def testLists(self):
237237
np.testing.assert_array_almost_equal(sort(zero(sys1_5)),
238238
sort(zero(sys1 + sys2 +
239239
sys3 + sys4 + sys5)))
240+
def testMimoSeries(self):
241+
"""regression: bdalg.series reverses order of arguments"""
242+
g1 = ctrl.ss([],[],[],[[1,2],[0,3]])
243+
g2 = ctrl.ss([],[],[],[[1,0],[2,3]])
244+
ref = g2*g1
245+
tst = ctrl.series(g1,g2)
246+
# assert_array_equal on mismatched matrices gives
247+
# "repr failed for <matrix>: ..."
248+
def assert_equal(x,y):
249+
np.testing.assert_array_equal(np.asarray(x),
250+
np.asarray(y))
251+
assert_equal(ref.A, tst.A)
252+
assert_equal(ref.B, tst.B)
253+
assert_equal(ref.C, tst.C)
254+
assert_equal(ref.D, tst.D)
255+
256+
240257
def suite():
241258
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)
242259

0 commit comments

Comments
 (0)