Skip to content

Commit 44787eb

Browse files
author
Kevin Chen
committed
convertTo{StateSpace,TransferFunction} made 'private'.
Kevin K. Chen <kkchen@princeton.edu>
1 parent f309485 commit 44787eb

5 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/TestXferFcn.py

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

33
import numpy as np
44
from statesp import StateSpace
5-
from xferfcn import TransferFunction, convertToTransferFunction
5+
from xferfcn import TransferFunction, _convertToTransferFunction
66
import unittest
77

88
class TestXferFcn(unittest.TestCase):
@@ -417,7 +417,7 @@ def testConvertToTransferFunction(self):
417417
D = [[1., 0.], [0., 1.], [1., 0.]]
418418
sys = StateSpace(A, B, C, D)
419419

420-
tfsys = convertToTransferFunction(sys)
420+
tfsys = _convertToTransferFunction(sys)
421421

422422
num = [[np.array([1., -7., 10.]), np.array([-1., 10.])],
423423
[np.array([2., -8.]), np.array([1., -2., -8.])],

src/bdalg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ def feedback(sys1, sys2, sign=-1):
211211
# its feedback member function.
212212
if isinstance(sys1, (int, long, float, complex)):
213213
if isinstance(sys2, tf.TransferFunction):
214-
sys1 = tf.convertToTransferFunction(sys1)
214+
sys1 = tf._convertToTransferFunction(sys1)
215215
elif isinstance(sys2, ss.StateSpace):
216-
sys1 = ss.convertToStateSpace(sys1)
216+
sys1 = ss._convertToStateSpace(sys1)
217217
else: # sys2 is a scalar.
218-
sys1 = tf.convertToTransferFunction(sys1)
219-
sys2 = tf.convertToTransferFunction(sys2)
218+
sys1 = tf._convertToTransferFunction(sys1)
219+
sys2 = tf._convertToTransferFunction(sys2)
220220

221221
return sys1.feedback(sys2, sign)

src/matlab.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
# Control system library
6868
import ctrlutil
6969
import freqplot
70-
from statesp import StateSpace, _rss_generate, convertToStateSpace
71-
from xferfcn import TransferFunction, convertToTransferFunction
70+
from statesp import StateSpace, _rss_generate, _convertToStateSpace
71+
from xferfcn import TransferFunction, _convertToTransferFunction
7272
from exception import ControlArgument
7373

7474
# Import MATLAB-like functions that can be used as-is
@@ -413,12 +413,12 @@ def ss2tf(*args):
413413

414414
if len(args) == 4:
415415
# Assume we were given the A, B, C, D matrix
416-
return convertToTransferFunction(StateSpace(args[0], args[1], args[2],
416+
return _convertToTransferFunction(StateSpace(args[0], args[1], args[2],
417417
args[3]))
418418
elif len(args) == 1:
419419
sys = args[0]
420420
if isinstance(sys, StateSpace):
421-
return convertToTransferFunction(sys)
421+
return _convertToTransferFunction(sys)
422422
else:
423423
raise TypeError("ss2tf(sys): sys must be a StateSpace object. It \
424424
is %s." % type(sys))
@@ -472,13 +472,13 @@ def tf2ss(*args):
472472

473473
if len(args) == 2:
474474
# Assume we were given the num, den
475-
return convertToStateSpace(TransferFunction(args[0], args[1]))
475+
return _convertToStateSpace(TransferFunction(args[0], args[1]))
476476
elif len(args) == 1:
477477
sys = args[0]
478478
if not isinstance(sys, TransferFunction):
479479
raise TypeError("tf2ss(sys): sys must be a TransferFunction \
480480
object.")
481-
return convertToStateSpace(sys)
481+
return _convertToStateSpace(sys)
482482
else:
483483
raise ValueError("Needs 1 or 2 arguments; received %i." % len(args))
484484

src/statesp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
StateSpace.zero
2828
StateSpace.feedback
2929
StateSpace.returnScipySignalLti
30-
convertToStateSpace
30+
_convertToStateSpace
3131
_rss_generate
3232
3333
"""
@@ -197,7 +197,7 @@ def __add__(self, other):
197197
A, B, C = self.A, self.B, self.C;
198198
D = self.D + other;
199199
else:
200-
other = convertToStateSpace(other)
200+
other = _convertToStateSpace(other)
201201

202202
# Check to make sure the dimensions are OK
203203
if ((self.inputs != other.inputs) or
@@ -245,7 +245,7 @@ def __mul__(self, other):
245245
C = self.C * other
246246
D = self.D * other
247247
else:
248-
other = convertToStateSpace(other)
248+
other = _convertToStateSpace(other)
249249

250250
# Check to make sure the dimensions are OK
251251
if self.inputs != other.outputs:
@@ -357,7 +357,7 @@ def zero(self):
357357
def feedback(self, other, sign=-1):
358358
"""Feedback interconnection between two LTI systems."""
359359

360-
other = convertToStateSpace(other)
360+
other = _convertToStateSpace(other)
361361

362362
# Check to make sure the dimensions are OK
363363
if ((self.inputs != other.outputs) or (self.outputs != other.inputs)):
@@ -414,16 +414,16 @@ def returnScipySignalLti(self):
414414

415415
return out
416416

417-
def convertToStateSpace(sys, **kw):
417+
def _convertToStateSpace(sys, **kw):
418418
"""Convert a system to state space form (if needed).
419419
420420
If sys is already a state space, then it is returned. If sys is a transfer
421421
function object, then it is converted to a state space and returned. If sys
422422
is a scalar, then the number of inputs and outputs can be specified
423423
manually, as in:
424424
425-
>>> sys = convertToStateSpace(3.) # Assumes inputs = outputs = 1
426-
>>> sys = convertToStateSpace(1., inputs=3, outputs=2)
425+
>>> sys = _convertToStateSpace(3.) # Assumes inputs = outputs = 1
426+
>>> sys = _convertToStateSpace(1., inputs=3, outputs=2)
427427
428428
In the latter example, A = B = C = 0 and D = [[1., 1., 1.]
429429
[1., 1., 1.]].
@@ -432,14 +432,14 @@ def convertToStateSpace(sys, **kw):
432432

433433
if isinstance(sys, StateSpace):
434434
if len(kw):
435-
raise TypeError("If sys is a StateSpace, convertToStateSpace \
435+
raise TypeError("If sys is a StateSpace, _convertToStateSpace \
436436
cannot take keywords.")
437437

438438
# Already a state space system; just return it
439439
return sys
440440
elif isinstance(sys, xferfcn.TransferFunction):
441441
if len(kw):
442-
raise TypeError("If sys is a TransferFunction, convertToStateSpace \
442+
raise TypeError("If sys is a TransferFunction, _convertToStateSpace \
443443
cannot take keywords.")
444444

445445
# Change the numerator and denominator arrays so that the transfer

src/xferfcn.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
TransferFunction._common_den
3131
_tfpolyToString
3232
_addSISO
33-
convertToTransferFunction
33+
_convertToTransferFunction
3434
3535
"""
3636

@@ -261,7 +261,7 @@ def __add__(self, other):
261261

262262
# Convert the second argument to a transfer function.
263263
if not isinstance(other, TransferFunction):
264-
other = convertToTransferFunction(other, inputs=self.inputs,
264+
other = _convertToTransferFunction(other, inputs=self.inputs,
265265
outputs=self.outputs)
266266

267267
# Check that the input-output sizes are consistent.
@@ -303,10 +303,10 @@ def __mul__(self, other):
303303

304304
# Convert the second argument to a transfer function.
305305
if isinstance(other, (int, float, long, complex)):
306-
other = convertToTransferFunction(other, inputs=self.inputs,
306+
other = _convertToTransferFunction(other, inputs=self.inputs,
307307
outputs=self.inputs)
308308
else:
309-
other = convertToTransferFunction(other)
309+
other = _convertToTransferFunction(other)
310310

311311
# Check that the input-output sizes are consistent.
312312
if self.inputs != other.outputs:
@@ -350,7 +350,7 @@ def __div__(self, other):
350350
implemented only for SISO systems.")
351351

352352
# Convert the second argument to a transfer function.
353-
other = convertToTransferFunction(other)
353+
other = _convertToTransferFunction(other)
354354

355355
num = polymul(self.num[0][0], other.den[0][0])
356356
den = polymul(self.den[0][0], other.num[0][0])
@@ -435,7 +435,7 @@ def zero(self):
435435
def feedback(self, other, sign=-1):
436436
"""Feedback interconnection between two LTI objects."""
437437

438-
other = convertToTransferFunction(other)
438+
other = _convertToTransferFunction(other)
439439

440440
if (self.inputs > 1 or self.outputs > 1 or
441441
other.inputs > 1 or other.outputs > 1):
@@ -650,16 +650,16 @@ def _addSISO(num1, den1, num2, den2):
650650

651651
return num, den
652652

653-
def convertToTransferFunction(sys, **kw):
653+
def _convertToTransferFunction(sys, **kw):
654654
"""Convert a system to transfer function form (if needed).
655655
656656
If sys is already a transfer function, then it is returned. If sys is a
657657
state space object, then it is converted to a transfer function and
658658
returned. If sys is a scalar, then the number of inputs and outputs can be
659659
specified manually, as in:
660660
661-
>>> sys = convertToTransferFunction(3.) # Assumes inputs = outputs = 1
662-
>>> sys = convertToTransferFunction(1., inputs=3, outputs=2)
661+
>>> sys = _convertToTransferFunction(3.) # Assumes inputs = outputs = 1
662+
>>> sys = _convertToTransferFunction(1., inputs=3, outputs=2)
663663
664664
In the latter example, sys's matrix transfer function is [[1., 1., 1.]
665665
[1., 1., 1.]].
@@ -669,12 +669,12 @@ def convertToTransferFunction(sys, **kw):
669669
if isinstance(sys, TransferFunction):
670670
if len(kw):
671671
raise TypeError("If sys is a TransferFunction, \
672-
convertToTransferFunction cannot take keywords.")
672+
_convertToTransferFunction cannot take keywords.")
673673

674674
return sys
675675
elif isinstance(sys, statesp.StateSpace):
676676
if len(kw):
677-
raise TypeError("If sys is a StateSpace, convertToTransferFunction \
677+
raise TypeError("If sys is a StateSpace, _convertToTransferFunction \
678678
cannot take keywords.")
679679

680680
# Use Slycot to make the transformation.

0 commit comments

Comments
 (0)