Skip to content

Commit 53f7808

Browse files
committed
fix up rebase issues
1 parent b284c47 commit 53f7808

File tree

3 files changed

+46
-50
lines changed

3 files changed

+46
-50
lines changed

control/mateqn.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737

3838
import warnings
3939
import numpy as np
40-
from numpy import shape, size, copy, zeros, eye, finfo, inexact, atleast_2d
40+
from numpy import copy, eye, dot, finfo, inexact, atleast_2d
4141

4242
import scipy as sp
43-
from scipy.linalg import eigvals, solve_discrete_are, solve
43+
from scipy.linalg import eigvals, solve
4444

45-
from .exception import ControlSlycot, ControlArgument, slycot_check
45+
from .exception import ControlSlycot, ControlArgument, ControlDimension, \
46+
slycot_check
4647
from .statesp import _ssmatrix
4748

4849
# Make sure we have access to the right slycot routines
@@ -136,9 +137,9 @@ def lyap(A, Q, C=None, E=None, method=None):
136137
method = _slycot_or_scipy(method)
137138
if method == 'slycot':
138139
if sb03md is None:
139-
raise ControlSlycot("can't find slycot module 'sb03md'")
140+
raise ControlSlycot("Can't find slycot module 'sb03md'")
140141
if sb04md is None:
141-
raise ControlSlycot("can't find slycot module 'sb04md'")
142+
raise ControlSlycot("Can't find slycot module 'sb04md'")
142143

143144
# Reshape input arrays
144145
A = np.array(A, ndmin=2)
@@ -196,7 +197,7 @@ def lyap(A, Q, C=None, E=None, method=None):
196197
from slycot import sg03ad
197198

198199
except ImportError:
199-
raise ControlSlycot("can't find slycot module 'sg03ad'")
200+
raise ControlSlycot("Can't find slycot module 'sg03ad'")
200201

201202
# Solve the generalized Lyapunov equation by calling Slycot
202203
# function sg03ad
@@ -265,11 +266,11 @@ def dlyap(A, Q, C=None, E=None, method=None):
265266
if method == 'slycot':
266267
# Make sure we have access to the right slycot routines
267268
if sb03md is None:
268-
raise ControlSlycot("can't find slycot module 'sb03md'")
269+
raise ControlSlycot("Can't find slycot module 'sb03md'")
269270
if sb04qd is None:
270-
raise ControlSlycot("can't find slycot module 'sb04qd'")
271+
raise ControlSlycot("Can't find slycot module 'sb04qd'")
271272
if sg03ad is None:
272-
raise ControlSlycot("can't find slycot module 'sg03ad'")
273+
raise ControlSlycot("Can't find slycot module 'sg03ad'")
273274

274275
# Reshape input arrays
275276
A = np.array(A, ndmin=2)
@@ -399,18 +400,18 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
399400
try:
400401
from slycot import sb02md
401402
except ImportError:
402-
raise ControlSlycot("can't find slycot module 'sb02md'")
403+
raise ControlSlycot("Can't find slycot module 'sb02md'")
403404

404405
try:
405406
from slycot import sb02mt
406407
except ImportError:
407-
raise ControlSlycot("can't find slycot module 'sb02mt'")
408+
raise ControlSlycot("Can't find slycot module 'sb02mt'")
408409

409410
# Make sure we can find the required slycot routine
410411
try:
411412
from slycot import sg02ad
412413
except ImportError:
413-
raise ControlSlycot("can't find slycot module 'sg02ad'")
414+
raise ControlSlycot("Can't find slycot module 'sg02ad'")
414415

415416
# Reshape input arrays
416417
A = np.array(A, ndmin=2)
@@ -500,10 +501,7 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
500501
'R', n, m, 0, A, E, B, Q, R, S)
501502

502503
# Calculate the closed-loop eigenvalues L
503-
L = zeros(n)
504-
L.dtype = 'complex64'
505-
for i in range(n):
506-
L[i] = (alfar[i] + alfai[i]*1j) / beta[i]
504+
L = np.array([(alfar[i] + alfai[i]*1j) / beta[i] for i in range(n)])
507505

508506
# Calculate the gain matrix G
509507
G = solve(R_b, B_b.T @ X @ E_b + S_b.T)
@@ -598,7 +596,7 @@ def dare(A, B, Q, R, S=None, E=None, stabilizing=True, method=None):
598596

599597
Rmat = _ssmatrix(R)
600598
Qmat = _ssmatrix(Q)
601-
X = solve_discrete_are(A, B, Qmat, Rmat, e=E, s=S)
599+
X = sp.linalg.solve_discrete_are(A, B, Qmat, Rmat, e=E, s=S)
602600
if S is None:
603601
G = solve(B.T @ X @ B + Rmat, B.T @ X @ A)
604602
else:
@@ -616,18 +614,18 @@ def _dare_slycot(A, B, Q, R, S=None, E=None, stabilizing=True):
616614
try:
617615
from slycot import sb02md
618616
except ImportError:
619-
raise ControlSlycot("can't find slycot module 'sb02md'")
617+
raise ControlSlycot("Can't find slycot module 'sb02md'")
620618

621619
try:
622620
from slycot import sb02mt
623621
except ImportError:
624-
raise ControlSlycot("can't find slycot module 'sb02mt'")
622+
raise ControlSlycot("Can't find slycot module 'sb02mt'")
625623

626624
# Make sure we can find the required slycot routine
627625
try:
628626
from slycot import sg02ad
629627
except ImportError:
630-
raise ControlSlycot("can't find slycot module 'sg02ad'")
628+
raise ControlSlycot("Can't find slycot module 'sg02ad'")
631629

632630
# Reshape input arrays
633631
A = np.array(A, ndmin=2)
@@ -667,10 +665,8 @@ def _dare_slycot(A, B, Q, R, S=None, E=None, stabilizing=True):
667665
sg02ad('D', 'B', 'N', 'U', 'N', 'N', sort,
668666
'R', n, m, 0, A, E, B, Q, R, S)
669667

670-
L = zeros(n)
671-
L.dtype = 'complex64'
672-
for i in range(n):
673-
L[i] = (alfar[i] + alfai[i]*1j)/beta[i]
668+
# Calculate the closed-loop eigenvalues L
669+
L = np.array([(alfar[i] + alfai[i]*1j) / beta[i] for i in range(n)])
674670

675671
# Calculate the gain matrix G
676672
G = solve(B_b.T @ X @ B_b + R_b, B_b.T @ X @ A_b + S_b.T)
@@ -687,19 +683,19 @@ def _slycot_or_scipy(method):
687683
elif method == 'scipy' or (method is None and not slycot_check()):
688684
return 'scipy'
689685
else:
690-
raise ValueError("unknown method %s" % method)
686+
raise ValueError("Unknown method %s" % method)
691687

692688

693689
# Utility function to check matrix dimensions
694690
def _check_shape(name, M, n, m, square=False, symmetric=False):
695691
if square and M.shape[0] != M.shape[1]:
696-
raise ControlArgument("%s must be a square matrix" % name)
692+
raise ControlDimension("%s must be a square matrix" % name)
697693

698694
if symmetric and not _is_symmetric(M):
699695
raise ControlArgument("%s must be a symmetric matrix" % name)
700696

701697
if M.shape[0] != n or M.shape[1] != m:
702-
raise ControlArgument("Incompatible dimensions of %s matrix" % name)
698+
raise ControlDimension("Incompatible dimensions of %s matrix" % name)
703699

704700

705701
# Utility function to check if a matrix is symmetric

control/tests/mateqn_test.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import control as ct
4343
from control.mateqn import lyap, dlyap, care, dare
44-
from control.exception import ControlArgument, slycot_check
44+
from control.exception import ControlArgument, ControlDimension, slycot_check
4545
from control.tests.conftest import slycotonly
4646

4747

@@ -334,21 +334,21 @@ def test_raise(self):
334334
Efq = array([[2, 1, 0], [1, 2, 0]])
335335

336336
for cdlyap in [lyap, dlyap]:
337-
with pytest.raises(ControlArgument):
337+
with pytest.raises(ControlDimension):
338338
cdlyap(Afq, Q)
339-
with pytest.raises(ControlArgument):
339+
with pytest.raises(ControlDimension):
340340
cdlyap(A, Qfq)
341341
with pytest.raises(ControlArgument):
342342
cdlyap(A, Qfs)
343-
with pytest.raises(ControlArgument):
343+
with pytest.raises(ControlDimension):
344344
cdlyap(Afq, Q, C)
345-
with pytest.raises(ControlArgument):
345+
with pytest.raises(ControlDimension):
346346
cdlyap(A, Qfq, C)
347-
with pytest.raises(ControlArgument):
347+
with pytest.raises(ControlDimension):
348348
cdlyap(A, Q, Cfd)
349-
with pytest.raises(ControlArgument):
349+
with pytest.raises(ControlDimension):
350350
cdlyap(A, Qfq, None, E)
351-
with pytest.raises(ControlArgument):
351+
with pytest.raises(ControlDimension):
352352
cdlyap(A, Q, None, Efq)
353353
with pytest.raises(ControlArgument):
354354
cdlyap(A, Qfs, None, E)
@@ -365,30 +365,30 @@ def test_raise(self):
365365
E = array([[2, 1], [1, 2]])
366366
Ef = array([[2, 1], [1, 2], [1, 2]])
367367

368-
with pytest.raises(ControlArgument):
368+
with pytest.raises(ControlDimension):
369369
care(Afq, B, Q)
370-
with pytest.raises(ControlArgument):
370+
with pytest.raises(ControlDimension):
371371
care(A, B, Qfq)
372-
with pytest.raises(ControlArgument):
372+
with pytest.raises(ControlDimension):
373373
care(A, Bf, Q)
374-
with pytest.raises(ControlArgument):
374+
with pytest.raises(ControlDimension):
375375
care(1, B, 1)
376376
with pytest.raises(ControlArgument):
377377
care(A, B, Qfs)
378378
with pytest.raises(ControlArgument):
379379
dare(A, B, Q, Rfs)
380380
for cdare in [care, dare]:
381-
with pytest.raises(ControlArgument):
381+
with pytest.raises(ControlDimension):
382382
cdare(Afq, B, Q, R, S, E)
383-
with pytest.raises(ControlArgument):
383+
with pytest.raises(ControlDimension):
384384
cdare(A, B, Qfq, R, S, E)
385-
with pytest.raises(ControlArgument):
385+
with pytest.raises(ControlDimension):
386386
cdare(A, Bf, Q, R, S, E)
387-
with pytest.raises(ControlArgument):
387+
with pytest.raises(ControlDimension):
388388
cdare(A, B, Q, R, S, Ef)
389-
with pytest.raises(ControlArgument):
389+
with pytest.raises(ControlDimension):
390390
cdare(A, B, Q, Rfq, S, E)
391-
with pytest.raises(ControlArgument):
391+
with pytest.raises(ControlDimension):
392392
cdare(A, B, Q, R, Sf, E)
393393
with pytest.raises(ControlArgument):
394394
cdare(A, B, Qfs, R, S, E)

control/tests/statefbk_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ def test_LQR_3args(self, matarrayin, matarrayout, method):
324324

325325
def test_lqr_badmethod(self):
326326
A, B, Q, R = 0, 1, 10, 2
327-
with pytest.raises(ValueError, match="unknown"):
327+
with pytest.raises(ValueError, match="Unknown method"):
328328
K, S, poles = lqr(A, B, Q, R, method='nosuchmethod')
329329

330330
def test_lqr_slycot_not_installed(self):
331331
A, B, Q, R = 0, 1, 10, 2
332332
if not slycot_check():
333-
with pytest.raises(ControlSlycot, match="can't find slycot"):
333+
with pytest.raises(ControlSlycot, match="Can't find slycot"):
334334
K, S, poles = lqr(A, B, Q, R, method='slycot')
335335

336336
@pytest.mark.xfail(reason="warning not implemented")
@@ -378,11 +378,11 @@ def test_lqr_call_format(self):
378378
np.testing.assert_array_almost_equal(Eref, E)
379379

380380
# Inconsistent system dimensions
381-
with pytest.raises(ct.ControlDimension, match="inconsistent system"):
381+
with pytest.raises(ct.ControlDimension, match="Incompatible dimen"):
382382
K, S, E = lqr(sys.A, sys.C, Q, R)
383383

384384
# incorrect covariance matrix dimensions
385-
with pytest.raises(ct.ControlDimension, match="incorrect weighting"):
385+
with pytest.raises(ct.ControlDimension, match="Q must be a square"):
386386
K, S, E = lqr(sys.A, sys.B, sys.C, R, Q)
387387

388388
def check_LQE(self, L, P, poles, G, QN, RN):
@@ -420,7 +420,7 @@ def test_lqe_call_format(self):
420420
sys_siso = rss(4, 1, 1)
421421
L_ss, P_ss, E_ss = lqe(sys_siso, np.eye(1), np.eye(1))
422422
L_tf, P_tf, E_tf = lqe(tf(sys_siso), np.eye(1), np.eye(1))
423-
np.testing.assert_array_almost_equal(E_ss, E_tf)
423+
np.testing.assert_array_almost_equal(np.sort(E_ss), np.sort(E_tf))
424424

425425
# Make sure we get an error if we specify N
426426
with pytest.raises(ct.ControlNotImplemented):

0 commit comments

Comments
 (0)