8000 bitshift typing on unsigned operands is tedious to work with · Issue #8002 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

bitshift typing on unsigned operands is tedious to work with #8002

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

Closed
pitrou opened this issue Sep 1, 2016 · 4 comments
Closed

bitshift typing on unsigned operands is tedious to work with #8002

pitrou opened this issue Sep 1, 2016 · 4 comments

Comments

@pitrou
Copy link
Member
pitrou commented Sep 1, 2016
>>> np.uint64(18446744073709551615) >> 2
Traceback (most recent call last):
  File "<ipython-input-10-988f6401a88f>", line 1, in <module>
    np.uint64(18446744073709551615) >> 2
TypeError: ufunc 'right_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''
@pitrou
Copy link
Member Author
pitrou commented Sep 1, 2016

In Numba we are considering typing based only on the first operand, see numba/numba#2072

@sklam
Copy link
sklam commented Sep 1, 2016

Numpy is probably casting (unsigned, signed) to (float64, float64), which is not defined. Then, it tries to downcast it back to integer, but it is unsafe.

@ahaldane
Copy link
Member
ahaldane commented Sep 22, 2016

I've hit the same problem. I have thought it would have been better to copy C typing as closely as possible. Then for an algorithm already written in C I can just paste it into python, and not have to worry about wrapping all the constants in uint64.

Here's something I had to write last week that demonstrates the annoyance:

    assert(type(crc) is uint16 and type(onech) is uint8)

    ans = uint32(crc ^ onech << uint16(8))
    for ind in range(8):
        if ans & uint32(0x8000):
          ans <<= uint32(1)
          ans = ans ^ uint32(4129)
        else:
          ans <<= uint32(1)

@seberg
Copy link
Member
seberg commented Jan 28, 2024

Effectively fixed by NEP 50 in main/NumPy 2.0. Closing.

@seberg seberg closed this as completed Jan 28, 2024
@mataton mataton mentioned this issue May 14, 2024
< 575D div class="flex-shrink-0 my-1 my-md-0 ml-md-3"> Merged
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0