From: <kk...@us...> - 2011-02-08 22:17:57
|
Revision: 98 http://python-control.svn.sourceforge.net/python-control/?rev=98&view=rev Author: kkchen Date: 2011-02-08 22:17:51 +0000 (Tue, 08 Feb 2011) Log Message: ----------- Added a copy() deepcopy routine to Lti subclasses. Also renamed rss_generate to _rss_generate and corrected some comments. Kevin K. Chen <kk...@pr...> Modified Paths: -------------- branches/control-0.4a/src/bdalg.py branches/control-0.4a/src/lti.py branches/control-0.4a/src/matlab.py branches/control-0.4a/src/statesp.py branches/control-0.4a/src/xferfcn.py Modified: branches/control-0.4a/src/bdalg.py =================================================================== --- branches/control-0.4a/src/bdalg.py 2011-02-08 22:17:44 UTC (rev 97) +++ branches/control-0.4a/src/bdalg.py 2011-02-08 22:17:51 UTC (rev 98) @@ -9,7 +9,9 @@ negate feedback -Copyright (c) 2010 by California Institute of Technology +""" + +"""Copyright (c) 2010 by California Institute of Technology All rights reserved. Redistribution and use in source and binary forms, with or without Modified: branches/control-0.4a/src/lti.py =================================================================== --- branches/control-0.4a/src/lti.py 2011-02-08 22:17:44 UTC (rev 97) +++ branches/control-0.4a/src/lti.py 2011-02-08 22:17:51 UTC (rev 98) @@ -21,6 +21,7 @@ "virtual" functions. These are: __init__ + copy __str__ __neg__ __add__ Modified: branches/control-0.4a/src/matlab.py =================================================================== --- branches/control-0.4a/src/matlab.py 2011-02-08 22:17:44 UTC (rev 97) +++ branches/control-0.4a/src/matlab.py 2011-02-08 22:17:51 UTC (rev 98) @@ -13,7 +13,9 @@ have the same names as their MATLAB equivalents are automatically imported here. -Copyright (c) 2009 by California Institute of Technology +""" + +"""Copyright (c) 2009 by California Institute of Technology All rights reserved. Redistribution and use in source and binary forms, with or without @@ -65,7 +67,7 @@ # Control system library import ctrlutil import freqplot -from statesp import StateSpace, rss_generate, convertToStateSpace +from statesp import StateSpace, _rss_generate, convertToStateSpace from xferfcn import TransferFunction, convertToTransferFunction from exception import ControlArgument @@ -511,7 +513,7 @@ """ - return rss_generate(states, inputs, outputs, 'c') + return _rss_generate(states, inputs, outputs, 'c') def drss(states=1, inputs=1, outputs=1): """ @@ -544,7 +546,7 @@ """ - return rss_generate(states, inputs, outputs, 'd') + return _rss_generate(states, inputs, outputs, 'd') def pole(sys): """ Modified: branches/control-0.4a/src/statesp.py =================================================================== --- branches/control-0.4a/src/statesp.py 2011-02-08 22:17:44 UTC (rev 97) +++ branches/control-0.4a/src/statesp.py 2011-02-08 22:17:51 UTC (rev 98) @@ -9,6 +9,8 @@ Routines in this module: StateSpace.__init__ +StateSpace._remove_useless_states +StateSpace.copy StateSpace.__str__ StateSpace.__neg__ StateSpace.__add__ @@ -26,9 +28,11 @@ StateSpace.feedback StateSpace.returnScipySignalLti convertToStateSpace -rss_generate +_rss_generate -Copyright (c) 2010 by California Institute of Technology +""" + +"""Copyright (c) 2010 by California Institute of Technology All rights reserved. Redistribution and use in source and binary forms, with or without @@ -74,6 +78,7 @@ from numpy.linalg import inv, det, solve from numpy.linalg.linalg import LinAlgError from scipy.signal import lti +from copy import deepcopy from slycot import td04ad from lti import Lti import xferfcn @@ -162,6 +167,11 @@ self.B = delete(self.B, useless, 0) self.C = delete(self.C, useless, 1) + def copy(self): + """Return a deep copy of the instance.""" + + return deepcopy(self) + def __str__(self): """String representation of the state space.""" @@ -207,9 +217,9 @@ return StateSpace(A, B, C, D) - # Reverse addition - just switch the arguments + # Right addition - just switch the arguments def __radd__(self, other): - """Reverse add two LTI systems (parallel connection).""" + """Right add two LTI systems (parallel connection).""" return self + other @@ -220,7 +230,7 @@ return self + (-other) def __rsub__(self, other): - """Reverse subtract two LTI systems.""" + """Right subtract two LTI systems.""" return other + (-self) @@ -253,10 +263,10 @@ return StateSpace(A, B, C, D) - # Reverse multiplication of two transfer functions (series interconnection) + # Right multiplication of two transfer functions (series interconnection) # Just need to convert LH argument to a state space object def __rmul__(self, other): - """Reverse multiply two LTI objects (serial connection).""" + """Right multiply two LTI objects (serial connection).""" # Check for a couple of special cases if isinstance(other, (int, long, float, complex)): @@ -276,7 +286,7 @@ raise NotImplementedError("StateSpace.__div__ is not implemented yet.") def __rdiv__(self, other): - """Reverse divide two LTI systems.""" + """Right divide two LTI systems.""" raise NotImplementedError("StateSpace.__rdiv__ is not implemented yet.") @@ -465,7 +475,7 @@ else: raise TypeError("Can't convert given type to StateSpace system.") -def rss_generate(states, inputs, outputs, type): +def _rss_generate(states, inputs, outputs, type): """Generate a random state space. This does the actual random state space generation expected from rss and Modified: branches/control-0.4a/src/xferfcn.py =================================================================== --- branches/control-0.4a/src/xferfcn.py 2011-02-08 22:17:44 UTC (rev 97) +++ branches/control-0.4a/src/xferfcn.py 2011-02-08 22:17:51 UTC (rev 98) @@ -10,6 +10,7 @@ TransferFunction.__init__ TransferFunction._truncatecoeff +TransferFunction.copy TransferFunction.__str__ TransferFunction.__neg__ TransferFunction.__add__ @@ -31,7 +32,9 @@ _addSISO convertToTransferFunction -Copyright (c) 2010 by California Institute of Technology +""" + +"""Copyright (c) 2010 by California Institute of Technology All rights reserved. Redistribution and use in source and binary forms, with or without @@ -208,6 +211,11 @@ data[p][i][j] = data[p][i][j][nonzero:] [self.num, self.den] = data + def copy(self): + """Return a deep copy of the instance.""" + + return deepcopy(self) + def __str__(self): """String representation of the transfer function.""" @@ -276,7 +284,7 @@ return TransferFunction(num, den) def __radd__(self, other): - """Reverse add two LTI objects (parallel connection).""" + """Right add two LTI objects (parallel connection).""" return self + other; @@ -286,7 +294,7 @@ return self + (-other) def __rsub__(self, other): - """Reverse subtract two LTI objects.""" + """Right subtract two LTI objects.""" return other + (-self) @@ -328,7 +336,7 @@ return TransferFunction(num, den) def __rmul__(self, other): - """Reverse multiply two LTI objects (serial connection).""" + """Right multiply two LTI objects (serial connection).""" return self * other @@ -351,7 +359,7 @@ # TODO: Division of MIMO transfer function objects is not written yet. def __rdiv__(self, other): - """Reverse divide two LTI objects.""" + """Right divide two LTI objects.""" if (self.inputs > 1 or self.outputs > 1 or other.inputs > 1 or other.outputs > 1): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |