Skip to content

Commit 39b874a

Browse files
authored
Merge pull request #576 from bnavigator/slycot5.7-sb03md
use new Slycot sb03md57 call signature if available
2 parents 2500199 + 67c4719 commit 39b874a

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

control/mateqn.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#
66
# Author: Bjorn Olofsson
77

8-
# Python 3 compatibility (needs to go here)
9-
from __future__ import print_function
10-
118
# Copyright (c) 2011, All rights reserved.
129

1310
# Redistribution and use in source and binary forms, with or without
@@ -44,6 +41,34 @@
4441
from .exception import ControlSlycot, ControlArgument
4542
from .statesp import _ssmatrix
4643

44+
# Make sure we have access to the right slycot routines
45+
try:
46+
from slycot import sb03md57
47+
# wrap without the deprecation warning
48+
def sb03md(n, C, A, U, dico, job='X',fact='N',trana='N',ldwork=None):
49+
ret = sb03md57(A, U, C, dico, job, fact, trana, ldwork)
50+
return ret[2:]
51+
except ImportError:
52+
try:
53+
from slycot import sb03md
54+
except ImportError:
55+
sb03md = None
56+
57+
try:
58+
from slycot import sb04md
59+
except ImportError:
60+
sb04md = None
61+
62+
try:
63+
from slycot import sb04qd
64+
except ImportError:
65+
sb0qmd = None
66+
67+
try:
68+
from slycot import sg03ad
69+
except ImportError:
70+
sb04ad = None
71+
4772
__all__ = ['lyap', 'dlyap', 'dare', 'care']
4873

4974
#
@@ -93,17 +118,12 @@ def lyap(A, Q, C=None, E=None):
93118
state space operations. See :func:`~control.use_numpy_matrix`.
94119
"""
95120

96-
# Make sure we have access to the right slycot routines
97-
try:
98-
from slycot import sb03md
99-
except ImportError:
121+
if sb03md is None:
100122
raise ControlSlycot("can't find slycot module 'sb03md'")
101-
102-
try:
103-
from slycot import sb04md
104-
except ImportError:
123+
if sb04md is None:
105124
raise ControlSlycot("can't find slycot module 'sb04md'")
106125

126+
107127
# Reshape 1-d arrays
108128
if len(shape(A)) == 1:
109129
A = A.reshape(1, A.size)
@@ -279,19 +299,11 @@ def dlyap(A, Q, C=None, E=None):
279299
of the same dimension. """
280300

281301
# Make sure we have access to the right slycot routines
282-
try:
283-
from slycot import sb03md
284-
except ImportError:
302+
if sb03md is None:
285303
raise ControlSlycot("can't find slycot module 'sb03md'")
286-
287-
try:
288-
from slycot import sb04qd
289-
except ImportError:
304+
if sb04qd is None:
290305
raise ControlSlycot("can't find slycot module 'sb04qd'")
291-
292-
try:
293-
from slycot import sg03ad
294-
except ImportError:
306+
if sg03ad is None:
295307
raise ControlSlycot("can't find slycot module 'sg03ad'")
296308

297309
# Reshape 1-d arrays

control/statefbk.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@
4747
from .statesp import _ssmatrix
4848
from .exception import ControlSlycot, ControlArgument, ControlDimension
4949

50+
# Make sure we have access to the right slycot routines
51+
try:
52+
from slycot import sb03md57
53+
# wrap without the deprecation warning
54+
def sb03md(n, C, A, U, dico, job='X',fact='N',trana='N',ldwork=None):
55+
ret = sb03md57(A, U, C, dico, job, fact, trana, ldwork)
56+
return ret[2:]
57+
except ImportError:
58+
try:
59+
from slycot import sb03md
60+
except ImportError:
61+
sb03md = None
62+
63+
try:
64+
from slycot import sb03od
65+
except ImportError:
66+
sb03od = None
67+
68+
5069
__all__ = ['ctrb', 'obsv', 'gram', 'place', 'place_varga', 'lqr', 'lqe',
5170
'acker']
5271

@@ -574,7 +593,7 @@ def gram(sys, type):
574593
* if `type` is not 'c', 'o', 'cf' or 'of'
575594
* if system is unstable (sys.A has eigenvalues not in left half plane)
576595
577-
ImportError
596+
ControlSlycot
578597
if slycot routine sb03md cannot be found
579598
if slycot routine sb03od cannot be found
580599
@@ -614,9 +633,7 @@ def gram(sys, type):
614633
if type == 'c' or type == 'o':
615634
# Compute Gramian by the Slycot routine sb03md
616635
# make sure Slycot is installed
617-
try:
618-
from slycot import sb03md
619-
except ImportError:
636+
if sb03md is None:
620637
raise ControlSlycot("can't find slycot module 'sb03md'")
621638
if type == 'c':
622639
tra = 'T'
@@ -634,9 +651,7 @@ def gram(sys, type):
634651

635652
elif type == 'cf' or type == 'of':
636653
# Compute cholesky factored gramian from slycot routine sb03od
637-
try:
638-
from slycot import sb03od
639-
except ImportError:
654+
if sb03od is None:
640655
raise ControlSlycot("can't find slycot module 'sb03od'")
641656
tra = 'N'
642657
n = sys.nstates

0 commit comments

Comments
 (0)