`cupy.ndarray` cannot be compared with ellipsis
See original GitHub issueNot sure if it’s due to #4198. The __richcmp__
method does not handle trivial comparison with Python objects correctly:
>>> np.empty(3) == ...
array([False, False, False])
>>>
>>> cp.empty(3) == ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cupy/_core/core.pyx", line 1094, in cupy._core.core.ndarray.__richcmp__
return numpy.equal(self, other)
TypeError: operand type(s) all returned NotImplemented from __array_ufunc__(<ufunc 'equal'>, '__call__', array([0., 0., 0.]), Ellipsis): 'ndarray', 'ellipsis'
It seems NumPy internally calls PyObject_RichCompare
to handle this. Perhaps before delegating to numpy.equal()
(and friends) we should handle this edge case first?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
`__eq__` to does not handle common non-ndarray types
A TypeError is raised when comparing ndarrays with unsupported dtypes for comparison ... cupy.ndarray cannot be compared with ellipsis #5715.
Read more >cupy.ndarray
CuPy is an implementation of NumPy-compatible multi-dimensional array on CUDA. CuPy consists of cupy. ndarray, the core multi-dimensional ...
Read more >Differences between CuPy and NumPy
Data type of CuPy arrays cannot be non-numeric like strings or objects. See Overview for details. Universal Functions only work with CuPy array...
Read more >PDF - CuPy Documentation
CuPy is an implementation of NumPy-compatible multi-dimensional array on CUDA. CuPy consists of cupy. ndarray, the core multi-dimensional ...
Read more >v9.1.0 PDF - CuPy Documentation
Data type of CuPy arrays cannot be non-numeric like strings or objects. ... a1 (cupy.ndarray) – Input array to compare.
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 Free
Top 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
#1989 discusses comparison with
None
.As @toslunar mentioned in https://github.com/cupy/cupy/issues/5715#issuecomment-985991356, I think NumPy’s current code works without any problem. But, yes, your diff would be exactly what we want to do there.