Skip to content

Commit 43310f7

Browse files
committed
Small changes to make things more python 3 compatible
* Updated unit test code to use proper print functions * Got rid of 'long' as a type for constant systems
1 parent 038785a commit 43310f7

14 files changed

Lines changed: 82 additions & 45 deletions

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2012-11-02 Richard Murray <murray@altura.local>
2+
3+
* src/xferfcn.py, src/statesp.py, src/lti.py, src/bdalg.py:
4+
constants must now be of type 'int' rather than 'long' (for python 3
5+
compatibility)
6+
7+
* tests/statefbk_test.py, tests/slycot_convert_test.py,
8+
tests/convert_test.py: added import __future__ calls for python 3
9+
compatibility; updated print calls
10+
11+
* src/modelsimp.py, src/xferfcn.py, src/delay.py, src/phaseplot.py,
12+
src/margins.py, src/statesp.py, src/mateqn.py: added import
13+
__future__ calls for python 3 compatibility
14+
115
2012-11-02 Richard Murray <murray@altura.local>
216

317
* src/xferfcn.py, src/timeresp.py, src/statesp.py, src/statefbk.py,

src/bdalg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,18 @@ def feedback(sys1, sys2, sign=-1):
215215
"""
216216

217217
# Check for correct input types.
218-
if not isinstance(sys1, (int, long, float, complex, tf.TransferFunction,
218+
if not isinstance(sys1, (int, float, complex, tf.TransferFunction,
219219
ss.StateSpace)):
220220
raise TypeError("sys1 must be a TransferFunction or StateSpace object, \
221221
or a scalar.")
222-
if not isinstance(sys2, (int, long, float, complex, tf.TransferFunction,
222+
if not isinstance(sys2, (int, float, complex, tf.TransferFunction,
223223
ss.StateSpace)):
224224
raise TypeError("sys2 must be a TransferFunction or StateSpace object, \
225225
or a scalar.")
226226

227227
# If sys1 is a scalar, convert it to the appropriate LTI type so that we can
228228
# its feedback member function.
229-
if isinstance(sys1, (int, long, float, complex)):
229+
if isinstance(sys1, (int, float, complex)):
230230
if isinstance(sys2, tf.TransferFunction):
231231
sys1 = tf._convertToTransferFunction(sys1)
232232
elif isinstance(sys2, ss.StateSpace):

src/delay.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! TODO: add module docstring
12
# delay.py - functions involving time delays
23
#
34
# Author: Sawyer Fuller
@@ -40,7 +41,8 @@
4041
#
4142
# $Id$
4243

43-
from __future__ import division
44+
# Python 3 compatability (needs to go here)
45+
from __future__ import print_function
4446

4547
def pade(T, n=1):
4648
"""

src/lti.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def timebase(sys, strict=True):
7575
set to False, dt = True will be returned as 1.
7676
"""
7777
# System needs to be either a constant or an Lti system
78-
if isinstance(sys, (int, float, long, complex)):
78+
if isinstance(sys, (int, float, complex)):
7979
return None
8080
elif not isinstance(sys, Lti):
8181
raise ValueError("Timebase not defined")
@@ -104,7 +104,7 @@ def timebaseEqual(sys1, sys2):
104104
def isdtime(sys, strict=False):
105105
# TODO: add docstring
106106
# Check to see if this is a constant
107-
if isinstance(sys, (int, float, long, complex)):
107+
if isinstance(sys, (int, float, complex)):
108108
# OK as long as strict checking is off
109109
return True if not strict else False
110110

@@ -121,7 +121,7 @@ def isdtime(sys, strict=False):
121121
def isctime(sys, strict=False):
122122
# TODO: add docstring
123123
# Check to see if this is a constant
124-
if isinstance(sys, (int, float, long, complex)):
124+
if isinstance(sys, (int, float, complex)):
125125
# OK as long as strict checking is off
126126
return True if not strict else False
127127

src/margins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
"""margin.py
32
43
Functions for computing stability margins and related functions.
@@ -9,6 +8,9 @@
98
margin.phase_crossover_frequencies
109
"""
1110

11+
# Python 3 compatability (needs to go here)
12+
from __future__ import print_function
13+
1214
"""Copyright (c) 2011 by California Institute of Technology
1315
All rights reserved.
1416

src/mateqn.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# mateqn.py - matrix equation solvers (Lyapunov, Riccati)
2-
from __future__ import division
1+
""" mateqn.py
32
4-
""" Implementation of the functions lyap, dlyap, care and dare
3+
Matrix equation solvers (Lyapunov, Riccati)
4+
5+
Implementation of the functions lyap, dlyap, care and dare
56
for solution of Lyapunov and Riccati equations. """
67

8+
# Python 3 compatability (needs to go here)
9+
from __future__ import print_function
10+
711
"""Copyright (c) 2011, All rights reserved.
812
913
Redistribution and use in source and binary forms, with or without

src/modelsimp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! TODO: add module docstring
12
# modelsimp.py - tools for model simplification
23
#
34
# Author: Steve Brunton, Kevin Chen, Lauren Padilla
@@ -39,6 +40,9 @@
3940
#
4041
# $Id$
4142

43+
# Python 3 compatability
44+
from __future__ import print_function
45+
4246
# External packages and modules
4347
import numpy as np
4448
import control.ctrlutil as ctrlutil

src/phaseplot.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! TODO: add module docstring
12
# phaseplot.py - generate 2D phase portraits
23
#
34
# Author: Richard M. Murray
@@ -33,7 +34,9 @@
3334
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3435
# POSSIBILITY OF SUCH DAMAGE.
3536

37+
# Python 3 compatability
3638
from __future__ import print_function
39+
3740
import numpy as np
3841
import matplotlib.pyplot as mpl
3942
from matplotlib.mlab import frange, find

src/statesp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
3434
"""
3535

36+
# Python 3 compatability (needs to go here)
37+
from __future__ import print_function
38+
3639
"""Copyright (c) 2010 by California Institute of Technology
3740
All rights reserved.
3841
@@ -231,7 +234,7 @@ def __add__(self, other):
231234
"""Add two LTI systems (parallel connection)."""
232235

233236
# Check for a couple of special cases
234-
if (isinstance(other, (int, long, float, complex))):
237+
if (isinstance(other, (int, float, complex))):
235238
# Just adding a scalar; put it in the D matrix
236239
A, B, C = self.A, self.B, self.C;
237240
D = self.D + other;
@@ -288,7 +291,7 @@ def __mul__(self, other):
288291
"""Multiply two LTI objects (serial connection)."""
289292

290293
# Check for a couple of special cases
291-
if isinstance(other, (int, long, float, complex)):
294+
if isinstance(other, (int, float, complex)):
292295
# Just multiplying by a scalar; change the output
293296
A, B = self.A, self.B
294297
C = self.C * other
@@ -329,7 +332,7 @@ def __rmul__(self, other):
329332
"""Right multiply two LTI objects (serial connection)."""
330333

331334
# Check for a couple of special cases
332-
if isinstance(other, (int, long, float, complex)):
335+
if isinstance(other, (int, float, complex)):
333336
# Just multiplying by a scalar; change the input
334337
A, C = self.A, self.C;
335338
B = self.B * other;
@@ -551,7 +554,7 @@ def _convertToStateSpace(sys, **kw):
551554
return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D,
552555
sys.dt)
553556

554-
elif isinstance(sys, (int, long, float, complex)):
557+
elif isinstance(sys, (int, float, complex)):
555558
if "inputs" in kw:
556559
inputs = kw["inputs"]
557560
else:

src/xferfcn.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
"""xferfcn.py
32
43
Transfer function representation and functions.
@@ -35,6 +34,9 @@
3534
3635
"""
3736

37+
# Python 3 compatability (needs to go here)
38+
from __future__ import print_function
39+
3840
"""Copyright (c) 2010 by California Institute of Technology
3941
All rights reserved.
4042
@@ -142,15 +144,15 @@ def __init__(self, *args):
142144
# this is a shallow copy! This should be okay, but be careful.
143145
data = [num, den]
144146
for i in range(len(data)):
145-
if isinstance(data[i], (int, float, long, complex)):
147+
if isinstance(data[i], (int, float, complex)):
146148
# Convert scalar to list of list of array.
147149
if (isinstance(data[i], int)):
148150
# Convert integers to floats at this point
149151
data[i] = [[array([data[i]], dtype=float)]]
150152
else:
151153
data[i] = [[array([data[i]])]]
152154
elif (isinstance(data[i], (list, tuple, ndarray)) and
153-
isinstance(data[i][0], (int, float, long, complex))):
155+
isinstance(data[i][0], (int, float, complex))):
154156
# Convert array to list of list of array.
155157
if (isinstance(data[i][0], int)):
156158
# Convert integers to floats at this point
@@ -161,7 +163,7 @@ def __init__(self, *args):
161163
elif (isinstance(data[i], list) and
162164
isinstance(data[i][0], list) and
163165
isinstance(data[i][0][0], (list, tuple, ndarray)) and
164-
isinstance(data[i][0][0][0], (int, float, long, complex))):
166+
isinstance(data[i][0][0][0], (int, float, complex))):
165167
# We might already have the right format. Convert the
166168
# coefficient vectors to arrays, if necessary.
167169
for j in range(len(data[i])):
@@ -362,7 +364,7 @@ def __mul__(self, other):
362364
"""Multiply two LTI objects (serial connection)."""
363365

364366
# Convert the second argument to a transfer function.
365-
if isinstance(other, (int, float, long, complex)):
367+
if isinstance(other, (int, float, complex)):
366368
other = _convertToTransferFunction(other, inputs=self.inputs,
367369
outputs=self.inputs)
368370
else:
@@ -412,7 +414,7 @@ def __rmul__(self, other):
412414
def __div__(self, other):
413415
"""Divide two LTI objects."""
414416

415-
if isinstance(other, (int, float, long, complex)):
417+
if isinstance(other, (int, float, complex)):
416418
other = _convertToTransferFunction(other, inputs=self.inputs,
417419
outputs=self.inputs)
418420
else:
@@ -440,7 +442,7 @@ def __div__(self, other):
440442
# TODO: Division of MIMO transfer function objects is not written yet.
441443
def __rdiv__(self, other):
442444
"""Right divide two LTI objects."""
443-
if isinstance(other, (int, float, long, complex)):
445+
if isinstance(other, (int, float, complex)):
444446
other = _convertToTransferFunction(other, inputs=self.inputs,
445447
outputs=self.inputs)
446448
else:
@@ -906,7 +908,7 @@ def _convertToTransferFunction(sys, **kw):
906908

907909
return TransferFunction(num, den, sys.dt)
908910

909-
elif isinstance(sys, (int, long, float, complex)):
911+
elif isinstance(sys, (int, float, complex)):
910912
if "inputs" in kw:
911913
inputs = kw["inputs"]
912914
else:

0 commit comments

Comments
 (0)