Skip to content

Commit 4cf0e1b

Browse files
committed
move the schur tests into test_mb.py
1 parent 0820f64 commit 4cf0e1b

4 files changed

Lines changed: 141 additions & 159 deletions

File tree

slycot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# Identification routines (0/5 wrapped)
2424

25-
# Mathematical routines (3/81 wrapped)
25+
# Mathematical routines (6/81 wrapped)
2626
from .math import mc01td, mb03vd, mb03vy, mb03wd, mb05md, mb05nd
2727

2828
# Synthesis routines (14/50 wrapped)

slycot/tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ set(PYSOURCE
33
__init__.py
44
test_ag08bd.py
55
test_mb.py
6-
test_mb03schur.py
76
test_mc.py
87
test_sb10jd.py
98
test_sg02ad.py

slycot/tests/test_mb.py

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,152 @@
66
import unittest
77
import numpy as np
88

9-
from slycot import mb05md, mb05nd
9+
from slycot import mb03vd, mb03vy, mb03wd, mb05md, mb05nd
1010

1111
from numpy.testing import assert_allclose
1212

1313

1414
class test_mb(unittest.TestCase):
1515

16+
def test_mb03vd_mb03vy_ex(self):
17+
"""Test MB03VD and MB03VY
18+
with the example given in the MB03VD SLICOT documentation"""
19+
20+
n = 4
21+
p = 2
22+
ilo = 1
23+
ihi = 4
24+
A = np.zeros((n, n, p))
25+
A[:, :, 0] = [[1.5, -.7, 3.5, -.7],
26+
[1. , 0. , 2. , 3. ],
27+
[1.5, -.7, 2.5, -.3],
28+
[1. , 0. , 2. , 1. ]]
29+
A[:, :, 1] = [[1.5, -.7, 3.5, -.7],
30+
[1. , 0. , 2. , 3. ],
31+
[1.5, -.7, 2.5, -.3],
32+
[1. , 0. , 2. , 1. ]]
33+
34+
H_ref = np.zeros((n, n, p))
35+
H_ref[:, :, 0] = [[-2.3926, 2.7042, -0.9598, -1.2335],
36+
[ 4.1417, -1.7046, 1.3001, -1.3120],
37+
[ 0.0000, -1.6247, -0.2534, 1.6453],
38+
[ 0.0000, 0.0000, -0.0169, -0.4451]]
39+
40+
H_ref[:, :, 1] = [[-2.5495, 2.3402, 4.7021, 0.2329],
41+
[ 0.0000, 1.9725, -0.2483, -2.3493],
42+
[ 0.0000, 0.0000, -0.6290, -0.5975],
43+
[ 0.0000, 0.0000, 0.0000, -0.4426]]
44+
45+
Q_ref = np.zeros((n, n, p))
46+
Q_ref[:, :, 0] = [[ 1.0000, 0.0000, 0.0000, 0.0000],
47+
[ 0.0000, -0.7103, 0.5504, -0.4388],
48+
[ 0.0000, -0.4735, -0.8349, -0.2807],
49+
[ 0.0000, -0.5209, 0.0084, 0.8536]]
50+
51+
Q_ref[:, :, 1] = [[-0.5883, 0.2947, 0.7528, -0.0145],
52+
[-0.3922, -0.8070, 0.0009, -0.4415],
53+
[-0.5883, 0.4292, -0.6329, -0.2630],
54+
[-0.3922, -0.2788, -0.1809, 0.8577]]
55+
56+
HQ, Tau = mb03vd(n, ilo, ihi, A)
57+
58+
H = np.zeros_like(HQ)
59+
Q = np.zeros_like(HQ)
60+
61+
for k in range(p):
62+
Q[:, :, k] = np.tril(HQ[:, :, k])
63+
if k == 0:
64+
H[:, :, k] = np.triu(HQ[:n, :n, k], -1)
65+
elif k > 0:
66+
H[:, :, k] = np.triu(HQ[:n, :n, k])
67+
assert_allclose(H[:, :, k], H_ref[:, :, k], atol=1e-4)
68+
69+
Qr = mb03vy(n, ilo, ihi, Q, Tau)
70+
71+
for k in range(p):
72+
assert_allclose(Qr[:, :, k], Q_ref[:, :, k], atol=1e-4)
73+
74+
# Computer Error: too machine dependent to test to reference value
75+
# SSQ_ref = 2.93760e-15
76+
# SSQ = 0.
77+
# for k in range(p):
78+
# kp1 = k+1
79+
# if kp1 > p-1:
80+
# kp1 = 0
81+
# P = Qr[:, :, k].T.dot(A[: ,: ,k]).dot(Qr[: ,: ,kp1]) - H[: ,: ,k]
82+
# SSQ = np.sqrt(SSQ**2 + np.linalg.norm(P,'fro')**2)
83+
84+
def test_mb03wd_ex(self):
85+
"""Test MB03WD with the example given in the SLICOT documentation"""
86+
87+
n = 4
88+
p = 2
89+
ilo = 1
90+
ihi = 4
91+
iloz = 1
92+
ihiz = 4
93+
job = 'S'
94+
compz = 'V'
95+
A = np.zeros((n, n, p))
96+
A[:, :, 0] = [[1.5, -.7, 3.5, -.7],
97+
[1. , 0. , 2. , 3. ],
98+
[1.5, -.7, 2.5, -.3],
99+
[1. , 0. , 2. , 1. ]]
100+
A[:, :, 1] = [[1.5, -.7, 3.5, -.7],
101+
[1. , 0. , 2. , 3. ],
102+
[1.5, -.7, 2.5, -.3],
103+
[1. , 0. , 2. , 1. ]]
104+
105+
W_ref = np.array([6.449861+7.817717J,
106+
6.449861-7.817717J,
107+
0.091315+0.000000J,
108+
0.208964+0.000000J])
109+
110+
T_ref = np.zeros((n, n, p))
111+
T_ref[:, :, 0] = [[ 2.2112, 4.3718, -2.3362, 0.8907],
112+
[ -0.9179, 2.7688, -0.6570, -2.2426],
113+
[ 0.0000, 0.0000, 0.3022, 0.1932],
114+
[ 0.0000, 0.0000, 0.0000, -0.4571]]
115+
116+
T_ref[:, :, 1] = [[ 2.9169, 3.4539, 2.2016, 1.2367],
117+
[ 0.0000, 3.4745, 1.0209, -2.0720],
118+
[ 0.0000, 0.0000, 0.3022, -0.1932],
119+
[ 0.0000, 0.0000, 0.0000, -0.4571]]
120+
121+
Z_ref = np.zeros((n, n, p))
122+
Z_ref[:, :, 0] = [[ 0.3493, 0.6751, -0.6490, 0.0327],
123+
[ 0.7483, -0.4863, -0.1249, -0.4336],
124+
[ 0.2939, 0.5504, 0.7148, -0.3158],
125+
[ 0.4813, -0.0700, 0.2286, 0.8433]]
126+
127+
128+
Z_ref[:, :, 1] = [[ 0.2372, 0.7221, 0.6490, 0.0327],
129+
[ 0.8163, -0.3608, 0.1249, -0.4336],
130+
[ 0.2025, 0.5902, -0.7148, -0.3158],
131+
[ 0.4863, 0.0076, -0.2286, 0.8433]]
132+
133+
HQ, Tau = mb03vd(n, ilo, ihi, A)
134+
Q = mb03vy(n, ilo, ihi, HQ, Tau)
135+
T, Z, W = mb03wd(job, compz, n, ilo, ihi, iloz, ihiz, HQ, Q)
136+
137+
# TODO (?)
138+
# isolate eigenvalues with math.mb03wx
139+
140+
assert_allclose(W, W_ref, atol=1e-5)
141+
assert_allclose(T, T_ref, atol=1e-4)
142+
assert_allclose(Z, Z_ref, atol=1e-4)
143+
144+
# Computer Error: too machine dependent to test to reference value
145+
# SSQ_ref = 7.18432D-15
146+
# SSQ = 0.
147+
# for k in range(p):
148+
# kp1 = k+1
149+
# if kp1 > p-1:
150+
# kp1 = 0
151+
# P = Zrr[:, :, k].T.dot(A[: ,: ,k]).dot(Zrr[: ,: ,kp1]) - Hrr[: ,: ,k]
152+
# SSQ = np.sqrt(SSQ**2 + np.linalg.norm(P,'fro')**2)
153+
154+
16155
def test_mb05md(self):
17156
""" test_mb05md: verify Matrix exponential with slicot doc example
18157
data from http://slicot.org/objects/software/shared/doc/MB05MD.html

slycot/tests/test_mb03schur.py

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)