Skip to content

MAINT: Rework residue and residuez #10997

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

Merged
merged 16 commits into from
Nov 5, 2019
Merged

Conversation

nmayorov
Copy link
Contributor

@nmayorov nmayorov commented Oct 31, 2019

What does this implement/fix?

Implementation of partial fraction expansion relied on a textbook "residue method" with fraction differentiation and all that. I decided to investigate whether there are established numerical methods for doing PFE.

I have found a rather old paper called "Partial fractions expansion: a review of computational methodology and efficiency" with nine methods described there. And the "textbook method" was only mentioned as the one which is not recommended for computer implementation.

So I picked another method which is relatively easy to understand and implement, doesn't have special cases and quite efficient in terms of number of required operations. Number 6 in the paper.

I've extended the documentation and included tests for residuez. The new implementation passes all tests from #4562, #4464 and #4561

Overall it looks like a more solid proper implementation now. The previous one was more of a literal translation of a theoretical method and not very clean or efficiently written.

@ilayn @larsoner It's not super obvious changes, but someone needs to review this. I'm happy to clarify any specifics of the code.

Closes #4562, #4561, #10929

@nmayorov nmayorov added scipy.signal maintenance Items related to regular maintenance tasks labels Oct 31, 2019
@nmayorov nmayorov requested review from ilayn and larsoner October 31, 2019 12:42
@larsoner
Copy link
Member

This all sounds good to me. Thanks for looking into the algorithm. I'm willing to trust the tests to ensure that it's working properly. And having looked just briefly at the code, it looks like overall it's a simplification, which is great.

Failures appear real:

https://travis-ci.org/scipy/scipy/jobs/605488928

Let me know once CIs are happy (ignoring if necessary what #10993 fixes) and I'll take a deeper look.

@larsoner
Copy link
Member

Also, can you add closes tags to the top comment if this does indeed take care of #4562, #4464 and #4561 ?

@nmayorov
Copy link
Contributor Author

nmayorov commented Oct 31, 2019

This all sounds good to me. Thanks for looking into the algorithm. I'm willing to trust the tests to ensure that it's working properly. And having looked just briefly at the code, it looks like overall it's a simplification, which is great.

The algorithm is any complicated only for repeated roots. In this case iterations are not very difficult to understand or implement either.

Failures appear real:

There is sort of a bug in np.polydiv, fixed in numpy/numpy#10473

I worked around it by casting b and a to either float or complex datatypes. Maybe it's not an ideal approach, but it's reasonable, simple and provides some fixed accuracy of computations.

with pytest.raises(ValueError, match='some regex'):
residuez(1, 0)

Will change to that.

Also, can you add closes tags to the top comment if this does indeed take care of #4562, #4464 and #4561 ?

I'd keep #4564 for a similar cleanup of invres, invresz and tests for them.

@larsoner
Copy link
Member

larsoner commented Nov 1, 2019

with pytest.raises(ValueError, match='some regex'):
residuez(1, 0)

Will change to that.

Okay let me know when you push a commit for this and any other remaining comments and I'll look again.

@larsoner larsoner added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Nov 1, 2019
@larsoner larsoner added this to the 1.4.0 milestone Nov 1, 2019
@larsoner
Copy link
Member

larsoner commented Nov 1, 2019

@Psirus can you also take a look and see if you agree this supersedes #10929 ?

@nmayorov
Copy link
Contributor Author

nmayorov commented Nov 1, 2019

@larsoner

I think I fixed everything what necessary.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge. Let's leave it open for a couple of days in case someone else wants to look.

Feel free to ping me for a merge on Tuesday if nobody else comments.

@larsoner
Copy link
Member

larsoner commented Nov 5, 2019

It has been a few days, so I'll go ahead and get this in. Thanks @nmayorov !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected maintenance Items related to regular maintenance tasks scipy.signal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Misc residuez issues
2 participants