|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# test_mb03rd.py - test suite for Shur form reduction |
| 4 | +# RvP, 31 Jul 2019 |
| 5 | +import unittest |
| 6 | +from slycot import transform |
| 7 | +import numpy as np |
| 8 | +from numpy.testing import assert_raises, assert_almost_equal, assert_equal |
| 9 | +from scipy.linalg import schur |
| 10 | + |
| 11 | +test1_A = np.array([ |
| 12 | + [ 1., -1., 1., 2., 3., 1., 2., 3.], |
| 13 | + [ 1., 1., 3., 4., 2., 3., 4., 2.], |
| 14 | + [ 0., 0., 1., -1., 1., 5., 4., 1.], |
| 15 | + [ 0., 0., 0., 1., -1., 3., 1., 2.], |
| 16 | + [ 0., 0., 0., 1., 1., 2., 3., -1.], |
| 17 | + [ 0., 0., 0., 0., 0., 1., 5., 1.], |
| 18 | + [ 0., 0., 0., 0., 0., 0., 0.99999999, -0.99999999 ], |
| 19 | + [ 0., 0., 0., 0., 0., 0., 0.99999999, 0.99999999 ] |
| 20 | + ]) |
| 21 | +test1_n = test1_A.shape[0] |
| 22 | + |
| 23 | +test1_Ar = np.array([ |
| 24 | + [ 1.0000, -1.0000, -1.2247, -0.7071, -3.4186, 1.4577, 0.0000, 0.0000 ], |
| 25 | + [ 1.0000, 1.0000, 0.0000, 1.4142, -5.1390, 3.1637, 0.0000, 0.0000 ], |
| 26 | + [ 0.0000, 0.0000, 1.0000, -1.7321, -0.0016, 2.0701, 0.0000, 0.0000 ], |
| 27 | + [ 0.0000, 0.0000, 0.5774, 1.0000, 0.7516, 1.1379, 0.0000, 0.0000 ], |
| 28 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, -5.8606, 0.0000, 0.0000 ], |
| 29 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 0.1706, 1.0000, 0.0000, 0.0000 ], |
| 30 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, -0.8850 ], |
| 31 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000 ], |
| 32 | + ]) |
| 33 | + |
| 34 | +test1_Xr = np.array([ |
| 35 | + [ 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.9045, 0.1957 ], |
| 36 | + [ 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, -0.3015, 0.9755 ], |
| 37 | + [ 0.0000, 0.0000, 0.8165, 0.0000, -0.5768, -0.0156, -0.3015, 0.0148 ], |
| 38 | + [ 0.0000, 0.0000, -0.4082, 0.7071, -0.5768, -0.0156, 0.0000, -0.0534 ], |
| 39 | + [ 0.0000, 0.0000, -0.4082, -0.7071, -0.5768, -0.0156, 0.0000, 0.0801 ], |
| 40 | + [ 0.0000, 0.0000, 0.0000, 0.0000, -0.0276, 0.9805, 0.0000, 0.0267 ], |
| 41 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 0.0332, -0.0066, 0.0000, 0.0000 ], |
| 42 | + [ 0.0000, 0.0000, 0.0000, 0.0000, 0.0011, 0.1948, 0.0000, 0.0000 ] |
| 43 | + ]) |
| 44 | + |
| 45 | +test1_pmax = 1e3 |
| 46 | +test1_tol = 0.01 |
| 47 | +class test_mb03rd(unittest.TestCase): |
| 48 | + def test1(self): |
| 49 | + # create schur form with scipy |
| 50 | + A, X = schur(test1_A) |
| 51 | + Ah, Xh = np.copy(A), np.copy(X) |
| 52 | + # on this basis, get the transform |
| 53 | + Ar, Xr, blks, eig = transform.mb03rd( |
| 54 | + test1_n, A, X, 'U', 'S', test1_pmax, test1_tol) |
| 55 | + # ensure X and A are unchanged |
| 56 | + assert_equal(A, Ah) |
| 57 | + assert_equal(X, Xh) |
| 58 | + # compare to test case results |
| 59 | + assert_almost_equal(Ar, test1_Ar, decimal=4) |
| 60 | + assert_almost_equal(Xr, test1_Xr, decimal=4) |
| 61 | + |
| 62 | +if __name__ == "__main__": |
| 63 | + unittest.main() |
0 commit comments