ENH: linalg: enable N-D batch support in special matrix functions#21446
ENH: linalg: enable N-D batch support in special matrix functions#21446j-bowhay merged 10 commits intoscipy:mainfrom
Conversation
It may be useful to move that into a new status/tracking issue, since it's a fairly important discussion that starts halfway in another PR now. Looks like all participants there are on board with the plan (and I am too, full batching support would be a clear win and very nice to have in my opinion), so this is more a "make it more discoverable" rather than a "possibly controversial" request for an issue.
I prefer option (1). It seems simpler, and the end result is the same. |
|
@rgommers thanks, that's definitely my preference, too. I proposed the other alternative in part based on your comment in gh-19890.
Just to check - the problem there was that the user could do nothing in the meantime to preserve the behavior without getting the And here, we don't have that problem - the user can get the same behavior without the warning simply by passing a I'll go ahead and add that warning. I will put up a tracking issue in a bit, but it will take a little while to put together something that covers more than just the special matrices. (The comment was only about special matrices, and those are getting taken care of pretty much all together.) |
Yes indeed. In this case, the user can simply do what the warning suggests (ravel) and the problem goes away. Then a warning is nice. If they can't take such an action, it's much less nice. |
|
Right - it's just that a stricter BC policy (which I've seen referred to as the "Hinsen principle", but only in scientific-python/specs#180) would require that either the behavior stays the same or an error is raised. I wanted to be sure that wasn't the concern. (I have trouble imaginging a use of |
I don't think it is. There are always tradeoffs, and of course it's never great to change behavior (in general we do have to try harder to avoid that than changes that yield exceptions). However in this case:
|
4558e09 to
eb94984
Compare
| n = f.shape[-1] | ||
|
|
||
| if f.ndim > 1 or s.ndim > 1: | ||
| from scipy.stats._resampling import _vectorize_statistic |
There was a problem hiding this comment.
We can eliminate this import by using the decorator from gh-21462.
|
By the way, if we remove the 2D checks from them, |
[docs only]
j-bowhay
left a comment
There was a problem hiding this comment.
A few minor comments but otherwise looks in good shape
|
Happy to look again once the comments above are resolved |
|
Sorry I missed that. |
Co-authored-by: Jake Bowhay <[email protected]>
Reference issue
#16090 (comment)
What does this implement/fix?
Begins to add N-dimensional batch support to the special matrix functions. This PR adds documentation, tests, and a simple implementation for API consistency. More performant implementations can come in follow-up PRs.
Additional information
gh-16090 will add support forDone!companion.gh-21419 will add support for
circulantA follow-up will add support forI decided to leave that code where it is and just import it. The import happens when the function is called for the first time to avoid import cycles. This is temporary and an immediate follow-up PR can either move the machinery toleslieandtoeplitz. These accept two arguments of different shapes. This is easy to handle with existing code; I'll just need move the machinery fromscipy.stats.axis_nan_policyto_lib._libto avoid circular imports or eliminate the need for the import by adding batch support directly.I left outtoeplitzbecause it documents that it ravels arrays of any number of dimensions, so we can't add batch support until after a cycle of warnings for >1 dimensional input. Which of the following is preferred?1. Emit aFutureWarningthat the behavior will change in SciPy 1.17; to ensure consistent behavior, the user mustravelinput before passing it intotoeplitz.2. Emit aDeprecationWarningabout support for >1 dimensional input. Raise an error in SciPy 1.17, and add N-D batch support after that.toeplitzgets aFutureWarningbecause it documents that it ravels N-D input. In SciPy 1.17 we can add N-D batch support as we do forleslie.I went ahead adding the code inside the function rather than using a decorator because I was going to have to edit the documentation of each function anyway. If we could leave the documentation alone and maybe just add a standard note about batch support, I might do all that with a decorator, instead.
Here is a wrapper we can use for most other
linalgfunctions:Details