-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ENH: ndimage: uarray based backend support #14356
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
base: main
Are you sure you want to change the base?
Conversation
f414502
to
42194cb
Compare
Separate is better, since it's an orthogonal change. Let me open an issue about that with some motivation and history, so we have a single place that we can reference when we start fixing this in various submodules. |
Yeah, that sounds good! Will pick it up after you raise the issue. Thanks:) |
A separate test to ensure a third-party backend works but not running duplicate tests sounds very reasonable to me. Let's wait for @peterbell10 or @grlee77 to comment though, they know more about how testing in |
We could copy the mock backend approach from the fft tests. I don't know that it is necesarry to mock every function in the ndimage namespace, though. |
I think it's valuable to test that each function really does do dispatching. If you're just worried about lines of code, then you could always define a backend that just records the arguments to class MockBackend:
__ua_domain__ = "numpy.scipy"
def __init__(self, return_value=None):
self.num_calls = 0
self.last_args = None
self.return_value = return_value
def __ua_function__(self, method, args, kwargs):
self.num_calls += 1
self.last_args = (method, args, kwargs)
return self.return_value |
@peterbell10 could you please explain this a bit more for me. I'm not very sure how we can call different functions without passing the required arguments which unlike Thanks in advance :) |
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've followed a specific pattern for the arg replacer names based on reusability. See below.
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.
Thanks for the careful review, I've made the changes.
I've made the changes according to @grlee77's comment which sounds like a good approach:
A couple of other things to take note of:
I guess some of the changes here overlap with the changes to be made for the deprecation of public like modules in ndimage but that's okay. I'll add a link to this comment in the description of the deprecation PR, just in case someone wants to understand the changes made, later. |
Ahh, need to fix the merge conflicts before Edit 1: Looks like if you add a new file with the same name which was earlier renamed to something else, github will show a huge diff. See AnirudhDagar#1 for demonstration. |
31a9882
to
5ad4b12
Compare
@peterbell10 @grlee77 @rgommers Thank you for your patience with this one. As I mentioned earlier, the diff is extremely large when following @grlee77 suggestion in a single PR. I propose to split this PR into three sequential PRs each adding the following:
To make sure the proposed method works in mitigating the huge diff, I tried it out on my own fork.
This will keep git blame (You can look at my Please let me know your opinion on this, if it looks good, then I'll go ahead :)) |
Drive-by comment: you can always send a series of PRs where PR N depends on N-1, and rebase N on master once N-1 is merged. |
This isn't ideal, because we cannot merge PR 1 separately - that will break master, and the second PR may need more discussion. Your idea of splitting the rename off is great, but you want that new PR to do both the rename to After that, rebase this PR on master, and you have a small diff back here. |
Please see the offline discussion below we had regarding the comment above. Anirudh:
Ralf:
In a nutshell, to conclude, I agree it is a much better idea to follow what was initially suggested by Ralf as the above points make a lot of sense and the way I was pitching it earlier is not compliant with these points. I'll send a PR for achieving this now. Thanks again everyone for the patience and useful feedback/suggestions. :)) |
DOC: set backend str to scipy and fix docs DOC: Fix notes about uarray domain hierarchy MAINT: explicitly define ndimage __all__
* ENH: Add filters multimethods * ENH: Add fourier multimethods * ENH: Add interpolation, measurements, morphology multimethods
cc @GenevieveBuckley (in case you have thoughts on this 🙂) |
Thanks for pinging me, @jakirkham
I think this seems important. Apologies if this is something that's already been discussed/resolved, there's a going on here in the thread. |
Hi @GenevieveBuckley, |
Thanks, @grlee77 @peterbell10 for reviewing this multiple times, suggesting changes and overall improving the work here. I guess we are finally there. Let me know if we'd like to keep the commit history (in that case I can do an interactive rebase and improve if required as it is slightly messy right now) or squash the commits on merge. cc @rgommers |
I think we'd probably want to squash-merge this. If you prefer you can rewrite the whole history, it should probably be ~4-5 commits then. |
I don't have any strong opinions on this. Let's do a squash merge if that's ideal. |
Gentle ping. Should be good to go. :) @leofang once this is merged, I'd like to discuss the CuPy support. Edit2: Please don't merge this yet! There is a bigger picture, we'll wait a few more days and hopefully get this merged then. Thanks in advance! |
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.
This looks excellent, thanks a lot @AnirudhDagar for the hard work, and @peterbell10 and @grlee77 for the thorough reviews!
I'm just adding a blocking review for the sole reason that we should not merge this just yet. For the same reason as discussed in #14407 (comment): we need to (a) sketch the big picture of where this uarray interop work is going, and (b) have a discussion about it on the mailing list.
@AnirudhDagar wrote a very nice blog post that will help illustrate where we are heading: https://labs.quansight.org/blog/2021/10/array-libraries-interoperability/. A second blog post is in the making with more of a high-level technical overview - that should be ready within a few days (so please do not start the discussion now/here). Once that is published, we will have that discussion, and once it has settled down we can (presumably) merge this PR.
Thanks for the ping, @AnirudhDagar! This looks cool. @kmaehashi has been busy renovating CuPy's CI support recently, so it might be easier now to get this kind of tests done. He probably is in a better position to comment on this regard 🙂 |
Yeah, it should be easy to add a test axis to verify CuPy's |
|
||
.. versionadded:: 1.8.0 | ||
""" | ||
__ua_domain__ = "numpy.scipy.ndimage" |
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 understand the intention and I know this is done the same way for scipy.fft
, but it's weird to call the hypothetical top-level backend numpy
.
uarray supports a list of domains that can be used when implementing a single backend that supports multiple domains Quansight-Labs/uarray#243 and it's just easier to understand the domain hierarchy when there's no "numpy."
at the beginning of the string.
@hameerabbasi, @peterbell10 what do you think, is it really necessary to have numpy
here?
@rgommers Where does the team stand on the overall design decisions/blocking comment above? Probably bet to bump the milestone before we branch ~later this week? |
Yes, we're going to have to bump this unfortunately - not enough bandwidth to push these discussions forward right now. Moving to the 1.10.0 milestone. |
Reference issue
See gh-14353
What does this implement/fix?
This adds support for
uarray
backend implementation toscipy.ndimage
.A simple example tested after adding dummy CuPy backend on this branch, verifies the backend.
Question
EDIT 3: This has been resolved, and we now run the whole
ndimage
test suite based onuarray
.Currently, I've not added any additional tests. We're now running the existing test suite via the multimethods.Edit 2: We now have separate tests for testing the backend based on the approach below.
We could do something similar to test_backend.py and mock_backend.py just to make sure that a third party backend can be properly registered and used via a context manager, but adding every function under ndimage in thoses tests is not something we should be doing (it is redundant to the current test suite since we set thescipy
global backend anyway and will probably be a repetition).Edit 1: I realized it doesn't really matter since the only thing that is being tested is whether dispatching works through the mock backend or not.
Let me know if it is necessary to include this type of test forndimage
as well.@rgommers just to confirm, do you want me to address the private/public namespace concerns of
ndimage
from cupy/cupy#5047 in this PR itself? Or should I do that subsequently, once this PR lands to keep them separated?cc @peterbell10 @grlee77
Additional Information
I've also removed the use of unnecessary private method
scipy.ndimage.filters.rank_filter
in favour ofscipy.ndimage.rank_filter
from the test suite.