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
ENH:linalg: expm overhaul and ndarray processing #15079
Conversation
|
||
Parameters | ||
---------- | ||
A : (N, N) array_like or sparse matrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change not break backwards compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally people should be using scipy.sparse.linalg.expm
and dense version kind of hijacks the sparse version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nitpicks. And I can't review the cython bits.
expected = np.dot(scipy.linalg.expm(A), B) | ||
expected = np.dot(sp_expm(A), B) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these changes signal
- an API change (
scipy.linalg.expm
used to be sparse, now it's dense) or - a mistake in the original tests using dense
expm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should explain this somewhere indeed. Previously, we were using sparse implementation in case of a dense input. Here dense gets its own implementation such that sparse one can live in its own environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that then sounds like something that can easily trip up sparse users. scipy.linalg.expm
no longer being sparse, that is. And we'd prefer it for people to use the top-level version of a name where possible, so scipy.linalg.expm
was probably the preferred version in the original.
Hi @ilayn! Here are the results on my machine:
|
Whoa! That's really good and bad :) Good for small matrices bad for large ones because around 360 we switch to estimation. I'll check again. Thanks Matt good data point for me. |
Yes, OpenBLAS behaviors are not very easy to explain unfortunately. I've been hit with a different kind of an issue but still no idea what the problem might be. Once 1.8.0 is out I'll try to dissect more this interesting behavior. At least the small matrix behavior looks consistent across MKL and OpenBLAS so far which is promising. |
Thanks @Kai-Striega . It looks like you have MKL right? |
@ilayn I'm not sure how to check, looking at the output of
|
Ok apart from one consistently timing-out test this is all good to go from my side. |
Could we get an approval from one of the reviewers? PR is pretty big, not trying to block it |
No worries @tylerjereddy if you feel like this is getting rushed, I'm OK with the milestone bump. Come to think of it maybe it is better to finish the full suite of matfuncs, solve and eig together in one release. |
Let's bump this one to 1.9.0 then, thanks @ilayn |
56c8607
to
d21f745
Compare
on one step and fails on another step if I use
Nevermind found it. |
Benchmarks were the last thing that needed tweaking. Hence this is final for review. Current benchmark for sparse (existing
|
Hmm don't know why the sudden pytest mark errors appeared. Doesn't seem to be related. |
[ci skip] [skip ci] [skip azp]
It's been quite a while that I got all green in CI so I'd like to celebrate it by merging tomorrow if everybody is OK with it :) |
I just had a quick browse through. I think that makes sense. It's too much code to review in detail for any other maintainer I think - but it's a rewrite of an existing function, so it's reasonable to rely on test coverage and green CI. |
Indeed I wish I had some more eyes on it but given the state of the overhaul (which is basically calling lots of LAPACK functions) I can understand that only thing to do for me is to brace for impact on 1.9 release for things that the tests don't cover. |
OK fingers crossed. Thanks all ! |
Closes #354
Closes #4897
Closes #12838
What does this implement/fix?
This is a complete overhaul of the function
scipy.linalg.expm
. Two important properties are the performance increase and being able to handle ndarrays withn>=2
. Moreover, diagonal and triangular matrices are recognized and treated as such. The existing tests pass with very tiny adjustments.If you can provide some benchmark feedback for the new and the old version, that'd be great. It doesn't have to be scientific, "yes it is fast" "no I don't see any difference" is also fine.
Produced via:
Additional information
There are some tests missing for the new functionality. I will try to add them asap.
Things left out
I ran out of steam at some point since the logic became too much for me to hold it in my head, but hermitian matrices through a Schur factorization can also benefit from some performance increases. At some point I hope I will come back to this.