Skip to content

Commit 801f282

Browse files
committed
address @bnavigator comments
1 parent 53f7808 commit 801f282

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

control/mateqn.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def lyap(A, Q, C=None, E=None, method=None):
189189
_check_shape("E", E, n, n, square=True)
190190

191191
if method == 'scipy':
192-
raise ValueError(
192+
raise ControlArgument(
193193
"method='scipy' not valid for generalized Lyapunov equation")
194194

195195
# Make sure we have access to the write slicot routine
@@ -308,7 +308,7 @@ def dlyap(A, Q, C=None, E=None, method=None):
308308
_check_shape("C", C, n, m)
309309

310310
if method == 'scipy':
311-
raise ValueError(
311+
raise ControlArgument(
312312
"method='scipy' not valid for Sylvester equation")
313313

314314
# Solve the Sylvester equation by calling Slycot function sb04qd
@@ -321,7 +321,7 @@ def dlyap(A, Q, C=None, E=None, method=None):
321321
_check_shape("E", E, n, n, square=True)
322322

323323
if method == 'scipy':
324-
raise ValueError(
324+
raise ControlArgument(
325325
"method='scipy' not valid for generalized Lyapunov equation")
326326

327327
# Solve the generalized Lyapunov equation by calling Slycot
@@ -438,7 +438,7 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
438438
# See if we should solve this using SciPy
439439
if method == 'scipy':
440440
if not stabilizing:
441-
raise ValueError(
441+
raise ControlArgument(
442442
"method='scipy' not valid when stabilizing is not True")
443443

444444
X = sp.linalg.solve_continuous_are(A, B, Q, R)
@@ -477,7 +477,7 @@ def care(A, B, Q, R=None, S=None, E=None, stabilizing=True, method=None):
477477
# See if we should solve this using SciPy
478478
if method == 'scipy':
479479
if not stabilizing:
480-
raise ValueError(
480+
raise ControlArgument(
481481
"method='scipy' not valid when stabilizing is not True")
482482

483483
X = sp.linalg.solve_continuous_are(A, B, Q, R, s=S, e=E)
@@ -579,7 +579,7 @@ def dare(A, B, Q, R, S=None, E=None, stabilizing=True, method=None):
579579

580580
# Figure out how to solve the problem
581581
if method == 'scipy' and not stabilizing:
582-
raise ValueError(
582+
raise ControlArgument(
583583
"method='scipy' not valid when stabilizing is not True")
584584

585585
elif method == 'slycot':
@@ -683,7 +683,7 @@ def _slycot_or_scipy(method):
683683
elif method == 'scipy' or (method is None and not slycot_check()):
684684
return 'scipy'
685685
else:
686-
raise ValueError("Unknown method %s" % method)
686+
raise ControlArgument("Unknown method %s" % method)
687687

688688

689689
# Utility function to check matrix dimensions

control/tests/mateqn_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_lyap_g(self):
9999
zeros((2,2)))
100100

101101
# Make sure that trying to solve with SciPy generates an error
102-
with pytest.raises(ValueError, match="'scipy' not valid"):
102+
with pytest.raises(ControlArgument, match="'scipy' not valid"):
103103
X = lyap(A, Q, None, E, method='scipy')
104104

105105
def test_dlyap(self):
@@ -126,7 +126,7 @@ def test_dlyap_g(self):
126126
zeros((2,2)))
127127

128128
# Make sure that trying to solve with SciPy generates an error
129-
with pytest.raises(ValueError, match="'scipy' not valid"):
129+
with pytest.raises(ControlArgument, match="'scipy' not valid"):
130130
X = dlyap(A, Q, None, E, method='scipy')
131131

132132
@slycotonly
@@ -146,7 +146,7 @@ def test_dlyap_sylvester(self):
146146
assert_array_almost_equal(A @ X @ B.T - X + C, zeros((2,2)))
147147

148148
# Make sure that trying to solve with SciPy generates an error
149-
with pytest.raises(ValueError, match="'scipy' not valid"):
149+
with pytest.raises(ControlArgument, match="'scipy' not valid"):
150150
X = dlyap(A, B, C, method='scipy')
151151

152152
def test_care(self):

control/tests/statefbk_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import control as ct
1010
from control import lqe, pole, rss, ss, tf
11-
from control.exception import ControlDimension, ControlSlycot, slycot_check
11+
from control.exception import ControlDimension, ControlSlycot, \
12+
ControlArgument, slycot_check
1213
from control.mateqn import care, dare
1314
from control.statefbk import ctrb, obsv, place, place_varga, lqr, gram, acker
1415
from control.tests.conftest import (slycotonly, check_deprecated_matrix,
@@ -324,7 +325,7 @@ def test_LQR_3args(self, matarrayin, matarrayout, method):
324325

325326
def test_lqr_badmethod(self):
326327
A, B, Q, R = 0, 1, 10, 2
327-
with pytest.raises(ValueError, match="Unknown method"):
328+
with pytest.raises(ControlArgument, match="Unknown method"):
328329
K, S, poles = lqr(A, B, Q, R, method='nosuchmethod')
329330

330331
def test_lqr_slycot_not_installed(self):
@@ -450,7 +451,7 @@ def test_care(self, matarrayin):
450451
X, L, G = care(A, B, Q, R, S, E, stabilizing=False)
451452
assert np.all(np.real(L) > 0)
452453
else:
453-
with pytest.raises(ValueError, match="'scipy' not valid"):
454+
with pytest.raises(ControlArgument, match="'scipy' not valid"):
454455
X, L, G = care(A, B, Q, R, S, E, stabilizing=False)
455456

456457
def test_dare(self, matarrayin):
@@ -466,8 +467,8 @@ def test_dare(self, matarrayin):
466467
assert np.all(np.abs(L) < 1)
467468

468469
if slycot_check():
469-
X, L, G = care(A, B, Q, R, S, E, stabilizing=False)
470-
assert np.all(np.real(L) > 0)
470+
X, L, G = dare(A, B, Q, R, S, E, stabilizing=False)
471+
assert np.all(np.abs(L) > 1)
471472
else:
472-
with pytest.raises(ValueError, match="'scipy' not valid"):
473-
X, L, G = care(A, B, Q, R, S, E, stabilizing=False)
473+
with pytest.raises(ControlArgument, match="'scipy' not valid"):
474+
X, L, G = dare(A, B, Q, R, S, E, stabilizing=False)

0 commit comments

Comments
 (0)