Skip to content

Commit d12d489

Browse files
committed
fix: infer transposed input length
1 parent 146ccee commit d12d489

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

control/tests/timeresp_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,17 @@ def test_response_transpose(
12451245
assert y.shape == ysh_no
12461246
assert x.shape == (T.size, sys.nstates)
12471247

1248+
def test_forced_response_transpose_without_time_vector(self):
1249+
sys = ct.ss(
1250+
[[0.5]], [[1.0, -0.25]], [[1.0]], [[0.0, 0.0]], dt=True)
1251+
U = np.column_stack((np.arange(5.0), np.arange(5.0) + 10))
1252+
1253+
response = ct.forced_response(sys, inputs=U, transpose=True)
1254+
1255+
np.testing.assert_allclose(response.time, np.arange(U.shape[0]))
1256+
np.testing.assert_allclose(response.inputs, U)
1257+
assert response.outputs.shape == (U.shape[0], sys.noutputs)
1258+
12481259

12491260
@pytest.mark.pandas
12501261
def test_to_pandas():

control/timeresp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ def forced_response(
11121112
raise ValueError('Parameters `T` and `U` can\'t both be '
11131113
'zero for discrete-time simulation')
11141114
# Set T to equally spaced samples with same length as U
1115-
if U.ndim == 1:
1115+
if U.ndim == 1 or transpose:
11161116
n_steps = U.shape[0]
11171117
else:
11181118
n_steps = U.shape[1]

0 commit comments

Comments
 (0)