8000 handle t_eval for static systems in input_output_response (addresses … · python-control/python-control@04ef02d · GitHub
[go: up one dir, main page]

Skip to content

Commit 04ef02d

Browse files
committed
handle t_eval for static systems in input_output_response (addresses #742)
1 parent 3b5f199 commit 04ef02d

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

control/iosys.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,19 +1762,8 @@ def input_output_response(
17621762
warn("initial state too short; padding with zeros")
17631763
X0 = np.hstack([X0, np.zeros(sys.nstates - X0.size)])
17641764

1765-
# Check to make sure this is not a static function
1765+
# Compute the number of states
17661766
nstates = _find_size(sys.nstates, X0)
1767-
if nstates == 0:
1768-
# No states => map input to output
1769-
u = U[0] if len(U.shape) == 1 else U[:, 0]
1770-
y = np.zeros((np.shape(sys._out(T[0], X0, u))[0], len(T)))
1771-
for i in range(len(T)):
1772-
u = U[i] if len(U.shape) == 1 else U[:, i]
1773-
y[:, i] = sys._out(T[i], [], u)
1774-
return TimeResponseData(
1775-
T, y, None, U, issiso=sys.issiso(),
1776-
output_labels=sys.output_index, input_labels=sys.input_index,
1777-
transpose=transpose, return_x=return_x, squeeze=squeeze)
17781767

17791768
# create X0 if not given, test if X0 has correct shape
17801769
X0 = _check_convert_array(X0, [(nstates,), (nstates, 1)],

control/tests/iosys_test.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,27 +1763,40 @@ def test_input_output_broadcasting():
17631763
resp_bad = ct.input_output_response(
17641764
sys, T, (U[0, :], U[:2, :-1]), [X0, P0])
17651765

1766-
1767-
def test_nonuniform_timepts():
1766+
@pytest.mark.parametrize("nstates, ninputs, noutputs", [
1767+
[2, 1, 1],
1768+
[4, 2, 3],
1769+
[0, 1, 1], # static function
1770+
[0, 3, 2], # static function
1771+
])
1772+
def test_nonuniform_timepts(nstates, noutputs, ninputs):
17681773
"""Test non-uniform time points for simulations"""
1769-
sys = ct.LinearIOSystem(ct.rss(2, 1, 1))
1774+
if nstates:
1775+
sys = ct.rss(nstates, noutputs, ninputs)
1776+
else:
1777+
sys = ct.ss(
1778+
[], np.zeros((0, ninputs)), np.zeros((noutputs, 0)),
1779+
np.random.rand(noutputs, ninputs))
17701780

17711781
# Start with a uniform set of times
17721782
unifpts = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1773-
uniform = [1, 2, 3, 2, 1, -1, -3, -5, -7, -3, 1]
1774-
t_unif, y_unif = ct.input_output_response(sys, unifpts, uniform)
1783+
uniform = np.outer(
1784+
np.ones(ninputs), [1, 2, 3, 2, 1, -1, -3, -5, -7, -3, 1])
1785+
t_unif, y_unif = ct.input_output_response(
1786+
sys, unifpts, uniform, squeeze=False)
17751787

17761788
# Create a non-uniform set of inputs
17771789
noufpts = [0, 2, 4, 8, 10]
1778-
nonunif = [1, 3, 1, -7, 1]
1779-
t_nouf, y_nouf = ct.input_output_response(sys, noufpts, nonunif)
1790+
nonunif = np.outer(np.ones(ninputs), [1, 3, 1, -7, 1])
1791+
t_nouf, y_nouf = ct.input_output_response(
1792+
sys, noufpts, nonunif, squeeze=False)
17801793

17811794
# Make sure the outputs agree at common times
1782-
np.testing.assert_almost_equal(y_unif[noufpts], y_nouf, decimal=6)
1795+
np.testing.assert_almost_equal(y_unif[:, noufpts], y_nouf, decimal=6)
17831796

17841797
# Resimulate using a new set of evaluation points
17851798
t_even, y_even = ct.input_output_response(
1786-
sys, noufpts, nonunif, t_eval=unifpts)
1799+
sys, noufpts, nonunif, t_eval=unifpts, squeeze=False)
17871800
np.testing.assert_almost_equal(y_unif, y_even, decimal=6)
17881801

17891802

0 commit comments

Comments
 (0)
0