Skip to content

Commit 41e12be

Browse files
committed
signal lti statespace at least 2d
move to test classes for easier merge with #438
1 parent a8aa41e commit 41e12be

File tree

3 files changed

+89
-84
lines changed

3 files changed

+89
-84
lines changed

control/statesp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,9 @@ def returnScipySignalLTI(self, strict=True):
827827
for i in range(self.outputs):
828828
for j in range(self.inputs):
829829
out[i][j] = signalStateSpace(asarray(self.A),
830-
asarray(self.B[:, j]),
831-
asarray(self.C[i, :]),
832-
self.D[i, j],
830+
asarray(self.B[:, j:j + 1]),
831+
asarray(self.C[i:i + 1, :]),
832+
asarray(self.D[i:i + 1, j:j + 1]),
833833
**kwdt)
834834

835835
return out

control/tests/statesp_test.py

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -674,51 +674,55 @@ def test_sample_system_prewarping(self):
674674
decimal=4)
675675

676676

677-
@pytest.fixture
678-
def mimoss(request):
679-
"""Test system with various dt values"""
680-
n = 5
681-
m = 3
682-
p = 2
683-
bx, bu = np.mgrid[1:n + 1, 1:m + 1]
684-
cy, cx = np.mgrid[1:p + 1, 1:n + 1]
685-
dy, du = np.mgrid[1:p + 1, 1:m + 1]
686-
return StateSpace(np.eye(5),
687-
bx * bu,
688-
cy * cx,
689-
dy * du,
690-
request.param)
691-
692-
693-
@pytest.mark.parametrize("mimoss",
694-
[None,
695-
0,
696-
0.1,
697-
1,
698-
True],
699-
indirect=True)
700-
def test_returnScipySignalLTI(mimoss):
701-
"""Test returnScipySignalLTI method with strict=False"""
702-
sslti = mimoss.returnScipySignalLTI(strict=False)
703-
for i in range(2):
704-
for j in range(3):
705-
np.testing.assert_allclose(sslti[i][j].A, mimoss.A)
706-
np.testing.assert_allclose(sslti[i][j].B, mimoss.B[:, j])
707-
np.testing.assert_allclose(sslti[i][j].C, mimoss.C[i, :])
708-
np.testing.assert_allclose(sslti[i][j].D, mimoss.D[i, j])
709-
if mimoss.dt == 0:
710-
assert sslti[i][j].dt is None
711-
else:
712-
assert sslti[i][j].dt == mimoss.dt
713-
714-
715-
@pytest.mark.parametrize("mimoss", [None], indirect=True)
716-
def test_returnScipySignalLTI_error(mimoss):
717-
"""Test returnScipySignalLTI method with dt=None and default strict=True"""
718-
with pytest.raises(ValueError):
719-
mimoss.returnScipySignalLTI()
720-
with pytest.raises(ValueError):
721-
mimoss.returnScipySignalLTI(strict=True)
677+
class TestLTIConverter:
678+
"""Test returnScipySignalLTI method"""
679+
680+
@pytest.fixture
681+
def mimoss(self, request):
682+
"""Test system with various dt values"""
683+
n = 5
684+
m = 3
685+
p = 2
686+
bx, bu = np.mgrid[1:n + 1, 1:m + 1]
687+
cy, cx = np.mgrid[1:p + 1, 1:n + 1]
688+
dy, du = np.mgrid[1:p + 1, 1:m + 1]
689+
return StateSpace(np.eye(5) + np.eye(5, 5, 1),
690+
bx * bu,
691+
cy * cx,
692+
dy * du,
693+
request.param)
694+
695+
@pytest.mark.parametrize("mimoss",
696+
[None,
697+
0,
698+
0.1,
699+
1,
700+
True],
701+
indirect=True)
702+
def test_returnScipySignalLTI(self, mimoss):
703+
"""Test returnScipySignalLTI method with strict=False"""
704+
sslti = mimoss.returnScipySignalLTI(strict=False)
705+
for i in range(mimoss.outputs):
706+
for j in range(mimoss.inputs):
707+
np.testing.assert_allclose(sslti[i][j].A, mimoss.A)
708+
np.testing.assert_allclose(sslti[i][j].B, mimoss.B[:,
709+
j:j + 1])
710+
np.testing.assert_allclose(sslti[i][j].C, mimoss.C[i:i + 1,
711+
:])
712+
np.testing.assert_allclose(sslti[i][j].D, mimoss.D[i:i + 1,
713+
j:j + 1])
714+
if mimoss.dt == 0:
715+
assert sslti[i][j].dt is None
716+
else:
717+
assert sslti[i][j].dt == mimoss.dt
718+
719+
@pytest.mark.parametrize("mimoss", [None], indirect=True)
720+
def test_returnScipySignalLTI_error(self, mimoss):
721+
"""Test returnScipySignalLTI method with dt=None and strict=True"""
722+
with pytest.raises(ValueError):
723+
mimoss.returnScipySignalLTI()
724+
with pytest.raises(ValueError):
725+
mimoss.returnScipySignalLTI(strict=True)
722726

723727

724728
if __name__ == "__main__":

control/tests/xferfcn_test.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -936,42 +936,43 @@ def test_sample_system_prewarping(self):
936936
decimal=4)
937937

938938

939-
@pytest.fixture
940-
def mimotf(request):
941-
"""Test system with various dt values"""
942-
return TransferFunction([[[11], [12], [13]],
943-
[[21], [22], [23]]],
944-
[[[1, -1]] * 3] * 2,
945-
request.param)
946-
947-
948-
@pytest.mark.parametrize("mimotf",
949-
[None,
950-
0,
951-
0.1,
952-
1,
953-
True],
954-
indirect=True)
955-
def test_returnScipySignalLTI(mimotf):
956-
"""Test returnScipySignalLTI method with strict=False"""
957-
sslti = mimotf.returnScipySignalLTI(strict=False)
958-
for i in range(2):
959-
for j in range(3):
960-
np.testing.assert_allclose(sslti[i][j].num, mimotf.num[i][j])
961-
np.testing.assert_allclose(sslti[i][j].den, mimotf.den[i][j])
962-
if mimotf.dt == 0:
963-
assert sslti[i][j].dt is None
964-
else:
965-
assert sslti[i][j].dt == mimotf.dt
966-
967-
968-
@pytest.mark.parametrize("mimotf", [None], indirect=True)
969-
def test_returnScipySignalLTI_error(mimotf):
970-
"""Test returnScipySignalLTI method with dt=None and default strict=True"""
971-
with pytest.raises(ValueError):
972-
mimotf.returnScipySignalLTI()
973-
with pytest.raises(ValueError):
974-
mimotf.returnScipySignalLTI(strict=True)
939+
class TestLTIConverter:
940+
"""Test returnScipySignalLTI method"""
941+
942+
@pytest.fixture
943+
def mimotf(self, request):
944+
"""Test system with various dt values"""
945+
return TransferFunction([[[11], [12], [13]],
946+
[[21], [22], [23]]],
947+
[[[1, -1]] * 3] * 2,
948+
request.param)
949+
950+
@pytest.mark.parametrize("mimotf",
951+
[None,
952+
0,
953+
0.1,
954+
1,
955+
True],
956+
indirect=True)
957+
def test_returnScipySignalLTI(self, mimotf):
958+
"""Test returnScipySignalLTI method with strict=False"""
959+
sslti = mimotf.returnScipySignalLTI(strict=False)
960+
for i in range(2):
961+
for j in range(3):
962+
np.testing.assert_allclose(sslti[i][j].num, mimotf.num[i][j])
963+
np.testing.assert_allclose(sslti[i][j].den, mimotf.den[i][j])
964+
if mimotf.dt == 0:
965+
assert sslti[i][j].dt is None
966+
else:
967+
assert sslti[i][j].dt == mimotf.dt
968+
969+
@pytest.mark.parametrize("mimotf", [None], indirect=True)
970+
def test_returnScipySignalLTI_error(self, mimotf):
971+
"""Test returnScipySignalLTI method with dt=None and strict=True"""
972+
with pytest.raises(ValueError):
973+
mimotf.returnScipySignalLTI()
974+
with pytest.raises(ValueError):
975+
mimotf.returnScipySignalLTI(strict=True)
975976

976977

977978
if __name__ == "__main__":

0 commit comments

Comments
 (0)