Skip to content

Commit 1cadd32

Browse files
committed
BUG: correct mb03rd for default X=None argument
Added a test for this case.
1 parent 055e9d6 commit 1cadd32

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

slycot/math.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def mb03rd(n, A, X=None, jobx='U', sort='N', pmax=1.0, tol=0.0):
4242
The matrix `A` to be block-diagonalized, in real Schur form.
4343
X : (n, n) array_like, optional
4444
A given matrix `X`, for accumulation of transformations (only if
45-
`jobx`='U')
45+
`jobx`='U'). Default value is identity matrix of order `n`.
4646
jobx : {'N', 'U'}, optional
4747
Specifies whether or not the transformations are
4848
accumulated, as follows:
@@ -230,7 +230,7 @@ def mb03rd(n, A, X=None, jobx='U', sort='N', pmax=1.0, tol=0.0):
230230
'dwork' + hidden, 'info']
231231

232232
if X is None:
233-
X = np.zeros((1, n))
233+
X = np.eye(n)
234234

235235
Ar, Xr, nblcks, blsize, wr, wi, info = _wrapper.mb03rd(
236236
jobx, sort, n, pmax, A, X, tol)

slycot/tests/test_mb.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ def test_mb03rd(self):
8686
test1_n, A, X, 'N', sort, test1_pmax, test1_tol)
8787
assert Xr is None
8888

89+
90+
def test_mb03rd_default(self):
91+
# regression: mb03rd was failing with no third arg (X) supplied
92+
A = np.array([[ 6, -1, -7, -2, 2],
93+
[-3, 4, 2, -7, 6],
94+
[-6, -9, -3, -1, 10],
95+
[-2, -4, 1, 5, 7],
96+
[-7, -5, -6, 6, 7]])
97+
98+
Aschur, Tschur = schur(A)
99+
100+
X = Tschur.copy()
101+
102+
Ar, Xr, blsize, W = mb03rd(Aschur.shape[0], Aschur, X, 'U', 'N', pmax=1.0, tol=0.0)
103+
104+
Ar2, Xr2, blsize2, W2 = mb03rd(Aschur.shape[0], Aschur)
105+
106+
assert_allclose(Ar, Ar2)
107+
assert_allclose(Xr, Tschur.dot(Xr2))
108+
109+
89110
def test_mb03vd_mb03vy_ex(self):
90111
"""Test MB03VD and MB03VY
91112
with the example given in the MB03VD SLICOT documentation"""

0 commit comments

Comments
 (0)