Skip to content

Convert TransferFunction's shallow copy to deep copy. #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dapperfu opened this issue Feb 9, 2017 · 2 comments
Closed

Convert TransferFunction's shallow copy to deep copy. #130

dapperfu opened this issue Feb 9, 2017 · 2 comments
Assignees

Comments

@dapperfu
Copy link
Contributor

dapperfu commented Feb 9, 2017

I spent quite a bit of time trying to debug an error and finally stumbled on the documentation:

# Beware: this is a shallow copy! This should be okay,
# but be careful.

It took me a bit of digging and debugging before I realized my errors caused by the shallow copy:

>>> print(num)
>>> print(type(num[0]))

[[1], [2]]
<class 'list'>

>>> sys1 = control.TransferFunction([num],[den])
>>> sys1

>>> print(num)
>>> print(type(num[0]))

[array([1]), array([2])]
<class 'numpy.ndarray'>

This can make scripts behave different based on the order of operation:

num = ...
den = ...
myfunc(num)
TransferFunction(num, den)

vs.

num = ...
den = ...
TransferFunction(num, den)
myfunc(num)

To new Python users having the variables 'num' & 'den' behave different before and after calling TransferFunction can be confusing and off-putting.

@roryyorke
Copy link
Contributor

also reported in #112. It probably just needs self.num = copy.deepcopy(num) (and the same for den) in TransferFunction.__init__, but I guess someone needs to read through those giant if-else-.. statements to check for complications.

@murrayrm
Copy link
Member

This has been fixed in PR #135.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants