-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
cupy.ndarray
cannot be compared with ellipsis
#5715
Comments
Note: this relates to the |
#1989 discusses comparison with |
Can you post the traceback from the test failure? We should probably make the array API tests not use == for comparing arrays and use |
This line brings the error, where cupy/cupy/array_api/_array_object.py Line 330 in 0955ad9
|
To be precise, each array index in cupy/cupy/array_api/_array_object.py Lines 346 to 351 in 0955ad9
|
Do you know if this code leads to a problem in the NumPY implementation? I think something like this would be more robust. diff --git a/numpy/array_api/_array_object.py b/numpy/array_api/_array_object.py
index ead061882d..e7ddcf033b 100644
--- a/numpy/array_api/_array_object.py
+++ b/numpy/array_api/_array_object.py
@@ -325,10 +325,13 @@ def _validate_index(key, shape):
if shape is None:
return key
- n_ellipsis = key.count(...)
+ # Use 'is' to compare against ellipsis to avoid performing == on
+ # an array.
+ ellipses = [i for i, k in enumerate(key) if k is ...]
+ n_ellipsis = len(ellipses)
if n_ellipsis > 1:
return key
- ellipsis_i = key.index(...) if n_ellipsis else len(key)
+ ellipsis_i = ellipses[0] if ellipses else len(key)
for idx, size in list(zip(key[:ellipsis_i], shape)) + list(
zip(key[:ellipsis_i:-1], shape[:ellipsis_i:-1]) |
As @toslunar mentioned in #5715 (comment), I think NumPy's current code works without any problem. But, yes, your diff would be exactly what we want to do there. |
Not sure if it's due to #4198. The
__richcmp__
method does not handle trivial comparison with Python objects correctly:It seems NumPy internally calls
PyObject_RichCompare
to handle this. Perhaps before delegating tonumpy.equal()
(and friends) we should handle this edge case first?The text was updated successfully, but these errors were encountered: