From d12d489682a09bc63034249f41761971f734c498 Mon Sep 17 00:00:00 2001 From: marko1olo Date: Mon, 8 Jun 2026 00:35:18 +0400 Subject: [PATCH] fix: infer transposed input length --- control/tests/timeresp_test.py | 11 +++++++++++ control/timeresp.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index 16ee01a3d..d5039f18b 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -1245,6 +1245,17 @@ def test_response_transpose( assert y.shape == ysh_no assert x.shape == (T.size, sys.nstates) + def test_forced_response_transpose_without_time_vector(self): + sys = ct.ss( + [[0.5]], [[1.0, -0.25]], [[1.0]], [[0.0, 0.0]], dt=True) + U = np.column_stack((np.arange(5.0), np.arange(5.0) + 10)) + + response = ct.forced_response(sys, inputs=U, transpose=True) + + np.testing.assert_allclose(response.time, np.arange(U.shape[0])) + np.testing.assert_allclose(response.inputs, U) + assert response.outputs.shape == (U.shape[0], sys.noutputs) + @pytest.mark.pandas def test_to_pandas(): diff --git a/control/timeresp.py b/control/timeresp.py index 3c49d213e..010d4aaca 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -1112,7 +1112,7 @@ def forced_response( raise ValueError('Parameters `T` and `U` can\'t both be ' 'zero for discrete-time simulation') # Set T to equally spaced samples with same length as U - if U.ndim == 1: + if U.ndim == 1 or transpose: n_steps = U.shape[0] else: n_steps = U.shape[1]