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

NDCube does not support arithmetic via numpy ufuncs #591

Open
Cadair opened this issue Feb 14, 2023 · 0 comments
Open

NDCube does not support arithmetic via numpy ufuncs #591

Cadair opened this issue Feb 14, 2023 · 0 comments

Comments

@Cadair
Copy link
Member

Cadair commented Feb 14, 2023

Describe the bug

Numpy ufuncs are things like np.add and np.equal, currently we support arithmetic methods via the standard Python operands like + (through __add__) but not the equivalent ufunc.

I discovered this issue because the following doesn't work:

cube = NDCube(...)
arr = np.array([cube], dtype=object)
np.equal(arr, cube)

In addition some things like np.maximum and np.isinf might be quite nice to have working without having to access .data, also if we implement __array_ufunc__ we can have those things return quantities.


See Recommendations for implementing binary operations in the NEP for how I think we need to go about this.

The overview is:

  • Implement all the arithmetic methods in __array_ufunc__.
  • Have the Python operator methods __add__ etc, call the numpy ufunc, i.e. __add__ calls np.add.
  • Ensure that our operator methods return NotImplemented if the other operand has __array_ufunc__ = None.
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

No branches or pull requests

1 participant