We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 310798e commit b96a039Copy full SHA for b96a039
2 files changed
control/modelsimp.py
@@ -146,6 +146,9 @@ def model_reduction(
146
other checking is done, so users to be careful not to render a system
147
unobservable or unreachable.
148
149
+ States, inputs, and outputs can be specified using integer offers.
150
+ Slices can also be specified, but must use the Python ``slice()`` function.
151
+
152
"""
153
if not isinstance(sys, StateSpace):
154
raise TypeError("system must be a a StateSpace system")
@@ -158,8 +161,16 @@ def model_reduction(
158
161
159
162
# Utility function to process keep/elim keywords
160
163
def _process_elim_or_keep(elim, keep, labels, allow_both=False):
- elim = [] if elim is None else np.atleast_1d(elim)
- keep = [] if keep is None else np.atleast_1d(keep)
164
+ def _expand_key(key):
165
+ if key is None:
166
+ return []
167
+ elif isinstance(key, slice):
168
+ return range(len(labels))[key]
169
+ else:
170
+ return np.atleast_1d(key)
171
172
+ elim = _expand_key(elim)
173
+ keep = _expand_key(keep)
174
175
if len(elim) > 0 and len(keep) > 0:
176
if not allow_both:
control/tests/modelsimp_test.py
@@ -480,6 +480,7 @@ def testBalredMatchDC(self):
480
({'elim_inputs': [1, 2], 'keep_states': [1, 3]}, 2, 3, 1),
481
({'elim_outputs': [1, 2], 'keep_inputs': [0, 1],}, 5, 1, 2),
482
({'keep_states': [2, 0], 'keep_outputs': [0, 1]}, 2, 2, 3),
483
+ ({'keep_states': slice(0, 4, 2), 'keep_outputs': slice(None, 2)}, 2, 2, 3),
484
({'elim_inputs': [0, 1, 2]}, 5, 3, 0), # no inputs
485
({'elim_outputs': [0, 1, 2]}, 5, 0, 3), # no outputs
486
({'elim_states': [0, 1, 2, 3, 4]}, 0, 3, 3), # no states
0 commit comments