Skip to content

fix issue #240: _common_den was not padding properly#242

Merged
murrayrm merged 1 commit intopython-control:masterfrom
murrayrm:fix_common_den
Dec 22, 2018
Merged

fix issue #240: _common_den was not padding properly#242
murrayrm merged 1 commit intopython-control:masterfrom
murrayrm:fix_common_den

Conversation

@murrayrm
Copy link
Copy Markdown
Member

@murrayrm murrayrm commented Nov 4, 2018

This PR fixes a problem where xferfcn._common_den was not properly padding the numerator coefficients and this was causing an apparent bug in tf2ss for MIMO systems (see issue #240). The issue occurred in the following code in xferfcn.py:

m = npmax - len(numpoly)
if m < 0:
    num[i,j,::-1] = numpoly
else:
    num[i,j,:m:-1] = numpoly

where npmax is the maximum number of poles across all inputs.

What this code is doing is putting the coefficients for numpoly at the right end of the array num[i,j], which has length npmax+1. However, what td04ad looks at is only the portion of the numerator array that is the order of the denominator array for that particular input (not the max across all inputs). So this code was shifting things too far to the right in the case where you had an input that had less than the maximum number of poles (discovered in issue #240, as part of a simulation bug).

The new code is

num[i, j, np+1-len(numpoly):np+1] = numpoly[::-1]

where np is the number of poles for this input (and hence np+1 is the portion of the input array that td04ad will use.

In addition to fixing this bug, two unit tests were added:

@repagh should have a look at this since it is in a section of code that he wrote.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-12.8%) to 66.123% when pulling b1c6670 on murrayrm:fix_common_den into 4b0101c on python-control:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-12.8%) to 66.123% when pulling b1c6670 on murrayrm:fix_common_den into 4b0101c on python-control:master.

@murrayrm
Copy link
Copy Markdown
Member Author

murrayrm commented Nov 5, 2018

Unit tests are failing in LQR checks. The test case is based on a state space system that is computed from a transfer function, so could be a problem in this PR (but it worked on my local machine, so something odd is going on).

Will look into the issue and try to fix later.

@murrayrm
Copy link
Copy Markdown
Member Author

murrayrm commented Nov 5, 2018

Not able to replicate the unit test failure under MacOS. Tried python3.5 and python3.7, but all unit tests pass.

Will have to start up a linux instance and see if I can generate the error.

@murrayrm
Copy link
Copy Markdown
Member Author

murrayrm commented Nov 5, 2018

Tried recreating the error on Ubuntu linux (trusty), but all unit tests seemed to work. ??

Also, murrayrm/python-control:master, which should just be a copy of python-control/python-control:master fails on unit tests for python 2.7 and 3.5, but is OK for 3.6 (here). Something funny going on.

@repagh
Copy link
Copy Markdown
Member

repagh commented Dec 8, 2018

I checked out the PR and tested locally; looks good and correct results (Fedora 27). I also can't figure out why the tests fail on travis.

@murrayrm
Copy link
Copy Markdown
Member Author

Found the problem with Travis CI failures. See issue #252 and PR #253.

Since @repagh OK'd the fix and we now know what was causing the Travis CI issue, plan to merge in the coming few days.

@murrayrm murrayrm added the bug label Dec 21, 2018
@murrayrm murrayrm added this to the 0.8.1 milestone Dec 21, 2018
@murrayrm murrayrm self-assigned this Dec 21, 2018
@murrayrm murrayrm merged commit 72f427d into python-control:master Dec 22, 2018
@murrayrm murrayrm deleted the fix_common_den branch April 21, 2019 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants