Fix forced_response time inference for transposed inputs#1229
Open
marko1olo wants to merge 1 commit into
Open
Conversation
slivingston
reviewed
Jun 8, 2026
| # Set T to equally spaced samples with same length as U | ||
| if U.ndim == 1: | ||
| n_steps = U.shape[0] | ||
| elif transpose: |
Member
There was a problem hiding this comment.
Why add another branch here instead of or with the above? I.e.,
if U.ndim == 1 or transpose:
Contributor
Author
There was a problem hiding this comment.
Thanks, good point. I simplified this in d12d4896 to use if U.ndim == 1 or transpose: since both cases use U.shape[0].
Rechecked locally:
python -m pytest control\tests\timeresp_test.py::TestTimeresp::test_forced_response_transpose_without_time_vector -qpython -m pytest control\tests\timeresp_test.py -qpython -m ruff check control\timeresp.py control\tests\timeresp_test.pypython -m compileall -q control\timeresp.py control\tests\timeresp_test.pygit diff --check
bdd3e0d to
d12d489
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #931.
When
forced_response()is called for a discrete-time system withtimepts=None, it infers the generated time vector length frominputs. Withtranspose=True, 2D input data is supplied in(time, input)order, but the current code still readsU.shape[1], treating the input count as the number of time steps.This changes the inference to use
U.shape[0]for 2D inputs whentranspose=True, matching the later_check_convert_array(..., transpose=True)conversion.Validation
forced_response(sys, inputs=U, transpose=True)withU.shape == (5, 2)failed withValueError: Parameter U: Wrong shape ... Expected: (2, 2).python -m pytest control/tests/timeresp_test.py -k forced_response_transpose_without_time_vector -qpassed.python -m pytest control/tests/timeresp_test.py -q -p no:cacheproviderpassed: 253 passed, 46 skipped.python -m ruff check --no-cache control\timeresp.py control\tests\timeresp_test.pypassed.PYTHONPYCACHEPREFIX=C:\tmp\pycache-python-control-931 python -m compileall -q control\timeresp.py control\tests\timeresp_test.pypassed.git diff --checkpassed.