Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Quantity basics #2

wants to merge 6 commits into from

Conversation

mhvk
Copy link
Contributor

@mhvk mhvk commented Nov 18, 2024

Support for numpy, array-api-strict, dask, and jax, with basic tests for all, and ufuncs for numpy only. Pushing now in part to check whether CI works properly.

Copy link
Member

@nstarman nstarman left a 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?
Copy link
Member

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)
Copy link
Member

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.

Suggested change
return self.__class__(self.value.__getitem__(item), self.unit)
return replace(self, value=self.value.__getitem__(item))

quantity/core.py Outdated
Comment on lines 140 to 143
try:
xp = self.value.__array_namespace__()
except AttributeError:
xp = np
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants