-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix: backends should have defaults for user-facing operations #1940
Conversation
Codecov Report
Additional details and impacted files
|
@jpivarski would you be happy for me to change |
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.
So backend_of
would normally raise an exception if it can't infer a backend without an explicit default=cpu
?
awkward/src/awkward/_backends.py
Lines 176 to 182 in 31ce657
nplike = nplike_of(*objects, default=None) | |
if nplike is not None: | |
return _backend_for_nplike(nplike) | |
elif default is _UNSET: | |
raise ak._errors.wrap_error(ValueError("could not find backend for", objects)) | |
else: | |
return default |
Okay, yeah, it does. So you need to provide default=cpu
for any user-facing functions.
Looks good; go ahead and merge it!
Yes. My call was that we really care about the backend, and due to interop it's very hard to tell if we get it wrong (JAX can adopt NumPy, CuPy can adopt NumPy). Better to fail loudly. |
@jpivarski would you mind confirming on #1940 (comment) ? I know you're busy with lots of things at the moment, but don't want to merge this without an OK! |
Yeah, It is better to fail loudly. I hadn't noticed that this is a draft PR. If it's a draft because you still have a lot of user-facing functions to update, you don't need re-approval to merge it. I'm in favor of the principle. |
Thanks! I'm going to make two changes; removing |
Raising an error in mixed cases is right. We should not have any array with different backends in different nodes. |
OK, this is done. I've added a check to ensure that we throw a |
The safe default for
ak._backends.backend_of
is to fail if the inputs don't have a well defined backend e.g. forlists
. However, for user-facing operations, this is not correct; we want to assume NumPy for these types. Agrep
shows that only a fewoperations
need this fix.I haven't added any tests because we should really do this as part of a coverage pass for all of our operations.
📚 The documentation for this PR will be available at https://awkward-array.readthedocs.io/en/agoose77-fix-backend-default/ once Read the Docs has finished building 🔨