Skip to content

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

Description

@dapperfu

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.

Activity

  1. roryyorke commented on Feb 9, 2017

    @roryyorke
    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.

  2. self-assigned this
    on Feb 10, 2017
  3. murrayrm commented on Dec 30, 2017

    @murrayrm
    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions