Raise `NotImplemented` in binary operations with non-CuPy arrays
See original GitHub issueBinary operations in CuPy currently raise TypeError
when other
is a non-CuPy array, see below:
In [1]: import cupy as cp, dask.array as da
In [2]: a = cp.arange(5)
In [3]: b = da.ones_like(a, shape=(5,))
In [4]: b - a
Out[4]: dask.array<sub, shape=(5,), dtype=int64, chunksize=(5,), chunktype=cupy.ndarray>
In [5]: a - b
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-09bd029d0285> in <module>
----> 1 a - b
cupy/core/core.pyx in cupy.core.core.ndarray.__sub__()
cupy/core/_kernel.pyx in cupy.core._kernel.ufunc.__call__()
cupy/core/_kernel.pyx in cupy.core._kernel._preprocess_args()
TypeError: Unsupported type <class 'dask.array.core.Array'>
It would be useful to instead raise a NotImplemented
exception as it would allow the other
array to try to compute that operation, see NotImplemented
docs for details.
Any thoughts on allowing this in CuPy?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Binary operations — NumPy v1.24 Manual
Compute the bit-wise AND of two arrays element-wise. ... Packs the elements of a binary-valued array into bits in a uint8 array.
Read more >Diagnostic flags - Clang 8 documentation - bcain-llvm
This diagnostic flag exists for GCC compatibility, and has no effect in Clang. -Wchar-subscripts¶. Diagnostic text: warning: array section ...
Read more >Rust Compiler Error Index | Rust Wiki
This error indicates that an empty match expression is invalid because the type it is matching on is non-empty (there exist values of...
Read more >TOPIC1 Python Basics Very Short Answer Type Questions(1 ...
What are the logical operators of Python? Answer: ... What are the differences between arrays and lists? ... Write a program to convert...
Read more >Xerox 4635 Laser Printing System Message Guide
operating system software program description for additional information. ... not being executed synchronically, or a noncopy medium was.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From my perspective, array-priority is more of an artifact of the past. We probably can’t quite do without it yet, but I think we should try.
Normally, the logic in
__add__
is something like:NumPy (and cupy probably) can’t do that easily, because we coerce most python objects agressively. The solution is to use
__array_ufunc__
to decide whether this is a “coercible” type:NumPy continues to check the array priority for historic reasons IMO. And I am not even sure cupy/dask have to worry about it?
In the previous post I thought you may need a 3-way logic (calling the ufunc in theory). I guess that should not be necessary, if
self.__array_ufunc__
is valid,is_known_type()
will succeed since you use the same logic for__array_ufunc__
. Ifother.__array_ufunc__
would be used, thenother.__add__
should succeed as well and deferring is correct.Or am I missing a reason why cupy/dask must rely on
__array_priority__
here?@pentschev @mrocklin @seberg Thanks for your explanations! I fixed cupy.ndarray binary operation logic in #4198.