Skip to content

Commit a0fc6bc

Browse files
committed
Added more test cases for slicing of statespace model
1 parent c6ef9b4 commit a0fc6bc

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

control/tests/statesp_test.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,28 +477,39 @@ def test_array_access_ss_failure(self):
477477
[(0, 1),
478478
(slice(0, 1, 1), 1),
479479
(0, slice(1, 2, 1)),
480+
(slice(0, 1, 1), slice(1, 2, 1)),
481+
(slice(None, None, -1), 1),
482+
(0, slice(None, None, -1)),
483+
(slice(None, 2, None), 1),
484+
(slice(None, None, 1), slice(None, None, 2)),
485+
(0, slice(1, 2, 1)),
480486
(slice(0, 1, 1), slice(1, 2, 1))])
481487
def test_array_access_ss(self, outdx, inpdx):
482488
sys1 = StateSpace(
483489
[[1., 2.], [3., 4.]],
484-
[[5., 6.], [6., 8.]],
490+
[[5., 6.], [7., 8.]],
485491
[[9., 10.], [11., 12.]],
486492
[[13., 14.], [15., 16.]], 1,
487493
inputs=['u0', 'u1'], outputs=['y0', 'y1'])
488494

489495
sys1_01 = sys1[outdx, inpdx]
496+
497+
# Convert int to slice to ensure that numpy doesn't drop the dimension
498+
if isinstance(outdx, int): outdx = slice(outdx, outdx+1, 1)
499+
if isinstance(inpdx, int): inpdx = slice(inpdx, inpdx+1, 1)
500+
490501
np.testing.assert_array_almost_equal(sys1_01.A,
491502
sys1.A)
492503
np.testing.assert_array_almost_equal(sys1_01.B,
493-
sys1.B[:, 1:2])
504+
sys1.B[:, inpdx])
494505
np.testing.assert_array_almost_equal(sys1_01.C,
495-
sys1.C[0:1, :])
506+
sys1.C[outdx, :])
496507
np.testing.assert_array_almost_equal(sys1_01.D,
497-
sys1.D[0:1, 1:2])
508+
sys1.D[outdx, inpdx])
498509

499510
assert sys1.dt == sys1_01.dt
500-
assert sys1_01.input_labels == ['u1']
501-
assert sys1_01.output_labels == ['y0']
511+
assert sys1_01.input_labels == sys1.input_labels[inpdx]
512+
assert sys1_01.output_labels == sys1.output_labels[outdx]
502513
assert sys1_01.name == sys1.name + "$indexed"
503514

504515
def test_dc_gain_cont(self):

0 commit comments

Comments
 (0)