@@ -303,3 +303,49 @@ def test_squeeze_exceptions(self, fcn):
303303 sys ([[0.1j , 1j ], [1j , 10j ]])
304304 with pytest .raises (ValueError , match = "must be 1D" ):
305305 evalfr (sys , [[0.1j , 1j ], [1j , 10j ]])
306+
307+
308+ @pytest .mark .parametrize (
309+ "outdx, inpdx, key" ,
310+ [('y[0]' , 'u[1]' , (0 , 1 )),
311+ (['y[0]' ], ['u[1]' ], (0 , 1 )),
312+ (slice (0 , 1 , 1 ), slice (1 , 2 , 1 ), (0 , 1 )),
313+ (['y[0]' , 'y[1]' ], ['u[1]' , 'u[2]' ], ([0 , 1 ], [1 , 2 ])),
314+ ([0 , 'y[1]' ], ['u[1]' , 2 ], ([0 , 1 ], [1 , 2 ])),
315+ (slice (0 , 2 , 1 ), slice (1 , 3 , 1 ), ([0 , 1 ], [1 , 2 ])),
316+ (['y[2]' , 'y[1]' ], ['u[2]' , 'u[0]' ], ([2 , 1 ], [2 , 0 ])),
317+ ])
318+ @pytest .mark .parametrize ("fcn" , [ct .ss , ct .tf , ct .frd ])
319+ def test_subsys_indexing (fcn , outdx , inpdx , key ):
320+ # Construct the base system and subsystem
321+ sys = ct .rss (4 , 3 , 3 )
322+ subsys = sys [key ]
323+
324+ # Construct the system to be test
325+ match fcn :
326+ case ct .frd :
327+ omega = np .logspace (- 1 , 1 )
328+ sys = fcn (sys , omega )
329+ subsys_chk = fcn (subsys , omega )
330+ case _:
331+ sys = fcn (sys )
332+ subsys_chk = fcn (subsys )
333+
334+ # Construct the subsystem
335+ subsys_fcn = sys [outdx , inpdx ]
336+
337+ # Check to make sure everythng matches up
338+ match fcn :
339+ case ct .frd :
340+ np .testing .assert_almost_equal (
341+ subsys_fcn .response , subsys_chk .response )
342+ case ct .ss :
343+ np .testing .assert_almost_equal (subsys_fcn .A , subsys_chk .A )
344+ np .testing .assert_almost_equal (subsys_fcn .B , subsys_chk .B )
345+ np .testing .assert_almost_equal (subsys_fcn .C , subsys_chk .C )
346+ np .testing .assert_almost_equal (subsys_fcn .D , subsys_chk .D )
347+ case ct .tf :
348+ omega = np .logspace (- 1 , 1 )
349+ np .testing .assert_almost_equal (
350+ subsys_fcn .frequency_response (omega ).response ,
351+ subsys_chk .frequency_response (omega ).response )
0 commit comments