1515import scipy as sp
1616from control .matlab import *
1717from control .frdata import FRD
18+ from control .exception import slycot_check
1819import warnings
1920
2021# for running these through Matlab or Octave
@@ -165,12 +166,13 @@ def testStep(self):
165166 np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
166167 np .testing .assert_array_almost_equal (tout , t )
167168
168- #Test MIMO system, which contains ``siso_ss1`` twice
169- sys = self .mimo_ss1
170- y_00 , _t = step (sys , T = t , input = 0 , output = 0 )
171- y_11 , _t = step (sys , T = t , input = 1 , output = 1 )
172- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
173- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
169+ if slycot_check ():
170+ # Test MIMO system, which contains ``siso_ss1`` twice
171+ sys = self .mimo_ss1
172+ y_00 , _t = step (sys , T = t , input = 0 , output = 0 )
173+ y_11 , _t = step (sys , T = t , input = 1 , output = 1 )
174+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
175+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
174176
175177 def testImpulse (self ):
176178 t = np .linspace (0 , 1 , 10 )
@@ -206,12 +208,13 @@ def testImpulse(self):
206208 np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
207209 np .testing .assert_array_almost_equal (tout , t )
208210
209- #Test MIMO system, which contains ``siso_ss1`` twice
210- sys = self .mimo_ss1
211- y_00 , _t = impulse (sys , T = t , input = 0 , output = 0 )
212- y_11 , _t = impulse (sys , T = t , input = 1 , output = 1 )
213- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
214- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
211+ if slycot_check ():
212+ #Test MIMO system, which contains ``siso_ss1`` twice
213+ sys = self .mimo_ss1
214+ y_00 , _t = impulse (sys , T = t , input = 0 , output = 0 )
215+ y_11 , _t = impulse (sys , T = t , input = 1 , output = 1 )
216+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
217+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
215218
216219 def testInitial (self ):
217220 #Test SISO system
@@ -229,13 +232,14 @@ def testInitial(self):
229232 np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
230233 np .testing .assert_array_almost_equal (tout , t )
231234
232- #Test MIMO system, which contains ``siso_ss1`` twice
233- sys = self .mimo_ss1
234- x0 = np .matrix (".5; 1.; .5; 1." )
235- y_00 , _t = initial (sys , T = t , X0 = x0 , input = 0 , output = 0 )
236- y_11 , _t = initial (sys , T = t , X0 = x0 , input = 1 , output = 1 )
237- np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
238- np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
235+ if slycot_check ():
236+ #Test MIMO system, which contains ``siso_ss1`` twice
237+ sys = self .mimo_ss1
238+ x0 = np .matrix (".5; 1.; .5; 1." )
239+ y_00 , _t = initial (sys , T = t , X0 = x0 , input = 0 , output = 0 )
240+ y_11 , _t = initial (sys , T = t , X0 = x0 , input = 1 , output = 1 )
241+ np .testing .assert_array_almost_equal (y_00 , youttrue , decimal = 4 )
242+ np .testing .assert_array_almost_equal (y_11 , youttrue , decimal = 4 )
239243
240244 def testLsim (self ):
241245 t = np .linspace (0 , 1 , 10 )
@@ -259,18 +263,19 @@ def testLsim(self):
259263 yout , _t , _xout = lsim (self .siso_ss1 , u , t , x0 )
260264 np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
261265
262- #Test MIMO system, which contains ``siso_ss1`` twice
263- #first system: initial value, second system: step response
264- u = np .array ([[0. , 1. ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ],
265- [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ]])
266- x0 = np .matrix (".5; 1; 0; 0" )
267- youttrue = np .array ([[11. , 9. ], [8.1494 , 17.6457 ], [5.9361 , 24.7072 ],
268- [4.2258 , 30.4855 ], [2.9118 , 35.2234 ],
269- [1.9092 , 39.1165 ], [1.1508 , 42.3227 ],
270- [0.5833 , 44.9694 ], [0.1645 , 47.1599 ],
271- [- 0.1391 , 48.9776 ]])
272- yout , _t , _xout = lsim (self .mimo_ss1 , u , t , x0 )
273- np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
266+ if slycot_check ():
267+ #Test MIMO system, which contains ``siso_ss1`` twice
268+ #first system: initial value, second system: step response
269+ u = np .array ([[0. , 1. ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ],
270+ [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ], [0 , 1 ]])
271+ x0 = np .matrix (".5; 1; 0; 0" )
272+ youttrue = np .array ([[11. , 9. ], [8.1494 , 17.6457 ],
273+ [5.9361 , 24.7072 ], [4.2258 , 30.4855 ],
274+ [2.9118 , 35.2234 ], [1.9092 , 39.1165 ],
275+ [1.1508 , 42.3227 ], [0.5833 , 44.9694 ],
276+ [0.1645 , 47.1599 ], [- 0.1391 , 48.9776 ]])
277+ yout , _t , _xout = lsim (self .mimo_ss1 , u , t , x0 )
278+ np .testing .assert_array_almost_equal (yout , youttrue , decimal = 4 )
274279
275280 def testMargin (self ):
276281 #! TODO: check results to make sure they are OK
@@ -310,11 +315,12 @@ def testDcgain(self):
310315 gain_sim ],
311316 [59 , 59 , 59 , 59 , 59 ])
312317
313- # Test with MIMO system, which contains ``siso_ss1`` twice
314- gain_mimo = dcgain (self .mimo_ss1 )
315- # print('gain_mimo: \n', gain_mimo)
316- np .testing .assert_array_almost_equal (gain_mimo , [[59. , 0 ],
317- [0 , 59. ]])
318+ if slycot_check ():
319+ # Test with MIMO system, which contains ``siso_ss1`` twice
320+ gain_mimo = dcgain (self .mimo_ss1 )
321+ # print('gain_mimo: \n', gain_mimo)
322+ np .testing .assert_array_almost_equal (gain_mimo , [[59. , 0 ],
323+ [0 , 59. ]])
318324
319325 def testBode (self ):
320326 bode (self .siso_ss1 )
@@ -370,29 +376,35 @@ def testEvalfr(self):
370376 evalfr (self .siso_tf1 , w )
371377 evalfr (self .siso_tf2 , w )
372378 evalfr (self .siso_tf3 , w )
373- np .testing .assert_array_almost_equal (
374- evalfr (self .mimo_ss1 , w ),
375- np .array ( [[44.8 - 21.4j , 0. ], [0. , 44.8 - 21.4j ]]))
379+ if slycot_check ():
380+ np .testing .assert_array_almost_equal (
381+ evalfr (self .mimo_ss1 , w ),
382+ np .array ( [[44.8 - 21.4j , 0. ], [0. , 44.8 - 21.4j ]]))
376383
384+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
377385 def testHsvd (self ):
378386 hsvd (self .siso_ss1 )
379387 hsvd (self .siso_ss2 )
380388 hsvd (self .siso_ss3 )
381389
390+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
382391 def testBalred (self ):
383392 balred (self .siso_ss1 , 1 )
384393 balred (self .siso_ss2 , 2 )
385394 balred (self .siso_ss3 , [2 , 2 ])
386395
396+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
387397 def testModred (self ):
388398 modred (self .siso_ss1 , [1 ])
389399 modred (self .siso_ss2 * self .siso_ss3 , [1 , 2 ])
390400 modred (self .siso_ss3 , [1 ], 'matchdc' )
391401 modred (self .siso_ss3 , [1 ], 'truncate' )
392402
403+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
393404 def testPlace (self ):
394405 place (self .siso_ss1 .A , self .siso_ss1 .B , [- 2 , - 2 ])
395406
407+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
396408 def testLQR (self ):
397409 (K , S , E ) = lqr (self .siso_ss1 .A , self .siso_ss1 .B , np .eye (2 ), np .eye (1 ))
398410 (K , S , E ) = lqr (self .siso_ss2 .A , self .siso_ss2 .B , np .eye (3 ), \
@@ -416,6 +428,7 @@ def testObsv(self):
416428 obsv (self .siso_ss1 .A , self .siso_ss1 .C )
417429 obsv (self .siso_ss2 .A , self .siso_ss2 .C )
418430
431+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
419432 def testGram (self ):
420433 gram (self .siso_ss1 , 'c' )
421434 gram (self .siso_ss2 , 'c' )
@@ -452,6 +465,7 @@ def testSISOssdata(self):
452465 for i in range (len (ssdata_1 )):
453466 np .testing .assert_array_almost_equal (ssdata_1 [i ], ssdata_2 [i ])
454467
468+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
455469 def testMIMOssdata (self ):
456470 m = (self .mimo_ss1 .A , self .mimo_ss1 .B , self .mimo_ss1 .C , self .mimo_ss1 .D )
457471 ssdata_1 = ssdata (self .mimo_ss1 );
@@ -532,6 +546,7 @@ def testFRD(self):
532546 frd2 = frd (frd1 .fresp [0 ,0 ,:], omega )
533547 assert isinstance (frd2 , FRD )
534548
549+ @unittest .skipIf (not slycot_check (), "slycot not installed" )
535550 def testMinreal (self , verbose = False ):
536551 """Test a minreal model reduction"""
537552 #A = [-2, 0.5, 0; 0.5, -0.3, 0; 0, 0, -0.1]
0 commit comments