Skip to content

Commit 4e2d153

Browse files
committed
updated division operators for FRD and TransferFunction to be python3 compatible
1 parent 81ee887 commit 4e2d153

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2013-07-15 Richard Murray <murray@altura-2.local>
2+
3+
* src/frdata.py, src/xferfcn.py: updated to use __truediv__ and
4+
__rtruediv__ for compatibility with python3
5+
16
2013-07-14 Richard Murray <murray@altura-2.local>
27

38
* src/dtime.py (sample_system): added check to make sure

src/frdata.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import division
12
"""frdata.py
23
34
Frequency response data representation and functions.
@@ -17,8 +18,8 @@
1718
FRD.__rsub__
1819
FRD.__mul__
1920
FRD.__rmul__
20-
FRD.__div__
21-
FRD.__rdiv__
21+
FRD.__truediv__
22+
FRD.__rtruediv__
2223
FRD.evalfr
2324
FRD.freqresp
2425
FRD.pole
@@ -289,7 +290,7 @@ def __rmul__(self, other):
289290
return FRD(fresp, self.omega)
290291

291292
# TODO: Division of MIMO transfer function objects is not written yet.
292-
def __div__(self, other):
293+
def __truediv__(self, other):
293294
"""Divide two LTI objects."""
294295

295296
if isinstance(other, (int, float, complex)):
@@ -301,12 +302,12 @@ def __div__(self, other):
301302
if (self.inputs > 1 or self.outputs > 1 or
302303
other.inputs > 1 or other.outputs > 1):
303304
raise NotImplementedError(
304-
"FRD.__div__ is currently implemented only for SISO systems.")
305+
"FRD.__truediv__ is currently implemented only for SISO systems.")
305306

306307
return FRD(self.fresp/other.fresp, self.omega)
307308

308309
# TODO: Division of MIMO transfer function objects is not written yet.
309-
def __rdiv__(self, other):
310+
def __rtruediv__(self, other):
310311
"""Right divide two LTI objects."""
311312
if isinstance(other, (int, float, complex)):
312313
return FRD(other / self.fresp, self.omega)
@@ -316,7 +317,7 @@ def __rdiv__(self, other):
316317
if (self.inputs > 1 or self.outputs > 1 or
317318
other.inputs > 1 or other.outputs > 1):
318319
raise NotImplementedError(
319-
"FRD.__rdiv__ is currently implemented only for SISO systems.")
320+
"FRD.__rtruediv__ is currently implemented only for SISO systems.")
320321

321322
return other / self
322323

src/xferfcn.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
# Python 3 compatability (needs to go here)
3939
from __future__ import print_function
40+
from __future__ import division
4041

4142
"""Copyright (c) 2010 by California Institute of Technology
4243
All rights reserved.
@@ -470,7 +471,7 @@ def __rmul__(self, other):
470471
return TransferFunction(num, den, dt)
471472

472473
# TODO: Division of MIMO transfer function objects is not written yet.
473-
def __div__(self, other):
474+
def __truediv__(self, other):
474475
"""Divide two LTI objects."""
475476

476477
if isinstance(other, (int, float, complex)):
@@ -482,7 +483,7 @@ def __div__(self, other):
482483

483484
if (self.inputs > 1 or self.outputs > 1 or
484485
other.inputs > 1 or other.outputs > 1):
485-
raise NotImplementedError("TransferFunction.__div__ is currently \
486+
raise NotImplementedError("TransferFunction.__truediv__ is currently \
486487
implemented only for SISO systems.")
487488

488489
# Figure out the sampling time to use
@@ -499,7 +500,7 @@ def __div__(self, other):
499500
return TransferFunction(num, den, dt)
500501

501502
# TODO: Division of MIMO transfer function objects is not written yet.
502-
def __rdiv__(self, other):
503+
def __rtruediv__(self, other):
503504
"""Right divide two LTI objects."""
504505
if isinstance(other, (int, float, complex)):
505506
other = _convertToTransferFunction(other, inputs=self.inputs,
@@ -509,7 +510,7 @@ def __rdiv__(self, other):
509510

510511
if (self.inputs > 1 or self.outputs > 1 or
511512
other.inputs > 1 or other.outputs > 1):
512-
raise NotImplementedError("TransferFunction.__rdiv__ is currently \
513+
raise NotImplementedError("TransferFunction.__rtruediv__ is currently \
513514
implemented only for SISO systems.")
514515

515516
return other / self

0 commit comments

Comments
 (0)