-
Notifications
You must be signed in to change notification settings - Fork 2
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: modify namespace based on backend #61
Conversation
+1
I'm generally not a fan of
what is the motivation for that working? I don't think I understand the use-case. |
Principle? Ideally, I think it would work "just like a module" rather than the alternative of "sort of like a module" |
Does |
No. You mean array_api_compat? from array_api_compat import array_namespace
import numpy as np
x = np.asarray(1)
xp = array_namespace(x)
from xp import asarray Why is that the behavior to match? I suppose it depends on whether this is mostly for end users or a tool for developers of libraries that work with any backend. For library developers, I agree that
But that's not what I've had in mind. I've thought of
as something like an import statement. If it could be written as
I would prefer that. |
Right, I can see how that would be more intuitive for users. I would say we could punt on it until it is requested though. |
How about this: from marray import numpy as mnp
mnp
# <module 'marray.numpy'>
mnp.asarray([1, 2, 3])
# MArray(array([1, 2, 3]), array([False, False, False]))
import numpy # there's no conflict
numpy # <module 'numpy' from 'C:\\Users\\matth\\Desktop\\marray\\.pixi\\envs\\dev\\Lib\\site-packages\\numpy\\__init__.py'>
from marray import array_api_strict as mxp
# <module 'marray.array_api_strict'>
mxp.asarray([1, 2, 3])
# MArray(
# Array([1, 2, 3], dtype=array_api_strict.int64),
# Array([False, False, False], dtype=array_api_strict.bool)
# ) That brings the number of lines to get up and running from four down to two. Incidentally... from marray import numpy
from marray.numpy import asarray # works |
that's clever! sure thing |
If CI is green, I'm happy with this. Follow-up work:
|
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.
LGTM! I think I still prefer foo(bar(...))
in the context of wrapping to foo.bar....
, but I think it's fine given that it matches the import structure
the patch file nonsense will be banished once data-apis/array-api-tests#334 is reviewed :) |
actually, you might not even need to wait for that PR if |
You can't just |
Ah, true, but fortunately, if you give array-api-tests the former in an env-var, it executes the latter. |
Closes gh-59
@lucascolley I think this is what you had in mind for gh-59
A problem is that this no longer works:
I don't think we can tell the name that the user assigns the namespace to, and I don't think we can have parentheses in the name we want to be able to import from. I can think of a few ways to address these issues, but I'll let you suggest first.
One (orthogonal) thought is that maybe the name should involve
marray
instead ofmxp
. Another is that maybeget_namespace
should bemarray
.