Skip to content

Commit f7d18f1

Browse files
authored
Merge pull request #912 from murrayrm/bdshur_bug-09Jun2023
fix bdschur (see issue #911)
2 parents 56b9402 + d153aed commit f7d18f1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

control/canonical.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,7 @@ def bdschur(a, condmax=None, sort=None):
450450
aschur, tschur, condmax)
451451

452452
if sort in ('continuous', 'discrete'):
453-
454453
idxs = np.cumsum(np.hstack([0, blksizes[:-1]]))
455-
456454
ev_per_blk = [complex(eigvals[i].real, abs(eigvals[i].imag))
457455
for i in idxs]
458456

@@ -470,7 +468,7 @@ def bdschur(a, condmax=None, sort=None):
470468
permidx = np.hstack([blkidxs[i] for i in sortidx])
471469
rperm = np.eye(amodal.shape[0])[permidx]
472470

473-
tmodal = tmodal @ rperm
471+
tmodal = tmodal @ rperm.T
474472
amodal = rperm @ amodal @ rperm.T
475473
blksizes = blksizes[sortidx]
476474

control/tests/canonical_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ def test_bdschur_sort(eigvals, sorted_blk_eigvals, sort):
287287

288288
b, t, blksizes = bdschur(a, sort=sort)
289289
assert len(blksizes) == len(sorted_blk_eigvals)
290+
np.testing.assert_allclose(a, t @ b @ t.T)
291+
np.testing.assert_allclose(t.T, np.linalg.inv(t))
290292

291293
blocks = extract_bdiag(b, blksizes)
292294
for block, blk_eigval in zip(blocks, sorted_blk_eigvals):

0 commit comments

Comments
 (0)