-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Einsum indexing very fragile, because it tests for int (and int64 is not int) #15961
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
Comments
We ought to be calling |
Relevant lines are here: numpy/numpy/core/src/multiarray/multiarraymodule.c Lines 2462 to 2501 in b489287
Logic ought to be the C equivalent of: try:
s = operator.index(item)
except TypeError as e:
raise TypeError("each subscript must be either an integer "
"or an ellipsis") from e
# do stuff with s |
I will take this one. |
@guilhermeleobas you working on this ? If not I would like to take this up. Thanks |
Hi @tinaoberoi, it was on my plans but you can go ahead and work on it :) |
Thanks @guilhermeleobas , I new here, any previous findings and help is appreciated. :-) |
I'm also a first time contributor. I might try fixing this. I don't really mind if someone else contribute first. In any case, the experience is good for me. |
* Using PyArray_PyIntAsIntp helper function instead * TST: add tests for einsum numpy int and bool list subscripts Added tests to check that einsum accepts numpy int64 types and rejects bool. Rejecting bools is new behaviour in subscript lists. I changed ValueError to TypeError on line 2496 in multiarraymodule.c as it is more appropriate. I also modified einsumfunc.py to have the same behaviour as in the C file when checking subscript list. (Reject bools but accept anything else from operator.index()) Closes gh-15961
The index arrays for einsum do not accept the output of any numpy array, because these datatypes cannot be ints (see #2951; #12322). The test should be modified to accept numpy ints, because converting the datatype to 'int' explicitly is counter-intuitive and unnecessary.
Though easy to circumvent, this will incur a lot of unnecessary debugging time, as it appears to break abstraction boundaries, has strange interactions with
tolist
, and indices that work in test environments fail when constructed programatically.Reproducing code example:
Error message:
ValueError: each subscript must be either an integer or an ellipsis
Full error message if
optimize_arg
isFalse
:Full error message when
optimize_arg
isTrue
:Numpy/Python version information:
1.17.3 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]
The text was updated successfully, but these errors were encountered: