-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Quantity basics #2
base: main
Are you sure you want to change the base?
Conversation
406df6c
to
c89827e
Compare
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.
Looking good! some quick comments.
|
||
@property | ||
def __array_namespace__(self): | ||
# TODO: make our own? |
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 think eventually, but not urgently.
return np | ||
|
||
def __getitem__(self, item): | ||
return self.__class__(self.value.__getitem__(item), self.unit) |
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.
Not sure about the comparative speed, but using dataclasses.replace
works better for subclasses, e.g. Angle, which have additional attributes.
return self.__class__(self.value.__getitem__(item), self.unit) | |
return replace(self, value=self.value.__getitem__(item)) |
quantity/core.py
Outdated
try: | ||
xp = self.value.__array_namespace__() | ||
except AttributeError: | ||
xp = np |
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.
what about defining a __value_array_namespace__
that does this?
def __value_array_namespace__(self):
try:
xp = self.value.__array_namespace__()
except AttributeError:
xp = np
return xp
Support for
numpy
,array-api-strict
,dask
, andjax
, with basic tests for all, and ufuncs fornumpy
only. Pushing now in part to check whether CI works properly.