-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
shift operator does not work with numpy arrays with dtype=uint64 #5668
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
It seems to be an issue with array scalar, not ndarrays:
|
@jaimefrio wrote:
I disagree... Here are a couple of counter examples: >>> u = np.array([1, 3], dtype=np.int64)
>>> u[0]<<1
2
>>> u = np.array([1, 3], dtype=np.uint8)
>>> u[0]<<1
2 Even more interesting: >>> u = np.array([1, 3], dtype=np.uint64)
>>> u[0]<<np.uint64(1)
2 |
@mcara, - I think your examples confirm what @jaimefrio stated: only for |
Sounds like #8809 to me The killer combination seems to be |
@mhvk I missed that the title already restricted the problem to |
The following example shows that the vice versa holds true: >>> import numpy as np
>>> np.__version__
'1.11.3'
>>> np.int64(1)<<np.uint64(61)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc 'left_shift' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' |
I think the problem in all cases is the promotion to Actually, this is not quite true:
So I suspect the difference is that for the array case, the
Anyway, the conclusion seems to be that for the array scalar case, the cast from python int is done differently than for the array case. |
This is related to NEP 50, which is/will fixed in main/NumPy 2.0, so closing. |
I have tested the following python code on 64 bit Windows 7:
import sys
print "python version is:\n", sys.version
import numpy as np
print "numpy version is:\n", np.version.version
a = np.array([1,3], dtype = np.int64)
print "a[1] is:", a[1]
print "type of a[1] is", type(a[1])
print "a[1] << 1 is:", a[1] << 1 # works fine for dtype = int64
u = np.array([1,3], dtype = np.uint64)
print "u[1] is:",u[1]
print "type of u[1] is", type(u[1])
print "u[1] << 1 is:", u[1] << 1 # but for dtype = uint64 there is a problem
This script produces the following output:
python version is:
2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
numpy version is:
1.8.1
a[1] is: 3
type of a[1] is <type 'numpy.int64'>
a[1] << 1 is: 6
u[1] is: 3
type of u[1] is <type 'numpy.uint64'>
u[1] << 1 is:
Traceback (most recent call last):
File "test_uint64_array.py", line 12, in
print "u[1] << 1 is:", u[1] << 1
TypeError: ufunc 'left_shift' not supported for the input types, and the inputs
could not be safely coerced to any supported types according to the casting rule ''safe''
I can do my job with int64 instead of uint64. I just want to report this problem.
The text was updated successfully, but these errors were encountered: