Skip to content

Commit 2fcc287

Browse files
committed
sampling a LinearIOSystem returns a LinearIOSystem
1 parent 867b353 commit 2fcc287

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

control/iosys.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ def __init__(self, linsys, **kwargs):
676676
StateSpace.__init__(
677677
self, linsys, remove_useless_states=False, init_namedio=False)
678678

679+
# When sampling a LinearIO system, return a LinearIOSystem
680+
def sample(self, *args, **kwargs):
681+
return LinearIOSystem(StateSpace.sample(self, *args, **kwargs))
682+
683+
sample.__doc__ = StateSpace.sample.__doc__
684+
679685
# The following text needs to be replicated from StateSpace in order for
680686
# this entry to show up properly in sphinx doccumentation (not sure why,
681687
# but it was the only way to get it to work).

control/tests/iosys_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,3 +2036,14 @@ def test_find_eqpt(x0, ix, u0, iu, y0, iy, dx0, idx, dt, x_expect, u_expect):
20362036
# Check that we got the expected result as well
20372037
np.testing.assert_allclose(np.array(xeq), x_expect, atol=1e-6)
20382038
np.testing.assert_allclose(np.array(ueq), u_expect, atol=1e-6)
2039+
2040+
def test_iosys_sample():
2041+
csys = ct.rss(2, 1, 1)
2042+
dsys = csys.sample(0.1)
2043+
assert isinstance(dsys, ct.LinearIOSystem)
2044+
assert dsys.dt == 0.1
2045+
2046+
csys = ct.rss(2, 1, 1)
2047+
dsys = ct.sample_system(csys, 0.1)
2048+
assert isinstance(dsys, ct.LinearIOSystem)
2049+
assert dsys.dt == 0.1

control/tests/kwargs_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def test_kwarg_search(module, prefix):
8686
(control.lqr, 1, 0, ([[1, 0], [0, 1]], [[1]]), {}),
8787
(control.linearize, 1, 0, (0, 0), {}),
8888
(control.pzmap, 1, 0, (), {}),
89-
(control.rlocus, 0, 1, ( ), {}),
90-
(control.root_locus, 0, 1, ( ), {}),
89+
(control.rlocus, 0, 1, (), {}),
90+
(control.root_locus, 0, 1, (), {}),
9191
(control.rss, 0, 0, (2, 1, 1), {}),
9292
(control.set_defaults, 0, 0, ('control',), {'default_dt': True}),
9393
(control.ss, 0, 0, (0, 0, 0, 0), {'dt': 1}),
@@ -101,7 +101,9 @@ def test_kwarg_search(module, prefix):
101101
(control.InputOutputSystem, 0, 0, (),
102102
{'inputs': 1, 'outputs': 1, 'states': 1}),
103103
(control.InputOutputSystem.linearize, 1, 0, (0, 0), {}),
104-
(control.StateSpace, 0, 0, ([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}),
104+
(control.LinearIOSystem.sample, 1, 0, (0.1,), {}),
105+
(control.StateSpace, 0, 0,
106+
([[-1, 0], [0, -1]], [[1], [1]], [[1, 1]], 0), {}),
105107
(control.TransferFunction, 0, 0, ([1], [1, 1]), {})]
106108
)
107109
def test_unrecognized_kwargs(function, nsssys, ntfsys, moreargs, kwargs,
@@ -202,6 +204,7 @@ def test_matplotlib_kwargs(function, nsysargs, moreargs, kwargs, mplcleanup):
202204
interconnect_test.test_interconnect_exceptions,
203205
'LinearIOSystem.__init__':
204206
interconnect_test.test_interconnect_exceptions,
207+
'LinearIOSystem.sample': test_unrecognized_kwargs,
205208
'NonlinearIOSystem.__init__':
206209
interconnect_test.test_interconnect_exceptions,
207210
'StateSpace.__init__': test_unrecognized_kwargs,

0 commit comments

Comments
 (0)