Skip to content
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

Mod on uint64 near max values gives wrong result #4665

Open
miloslen opened this issue Oct 6, 2019 · 3 comments
Open

Mod on uint64 near max values gives wrong result #4665

miloslen opened this issue Oct 6, 2019 · 3 comments
Labels

Comments

@miloslen
Copy link

miloslen commented Oct 6, 2019

Reproducible test case:

import numpy as np
import numba

def test_max_mod():
    return np.mod(np.uint64(np.iinfo(np.uint64).max), np.uint64(16)) 

@numba.jit
def test_max_mod_jit():
    return np.mod(np.uint64(np.iinfo(np.uint64).max), np.uint64(16)) 

test_max_mod(), test_max_mod_jit()

(15, 18446744073709551615)

numba.__version__

'0.45.1'

Took me quite some time to strip down the issue to this, for smaller values of uint64 mod works fine so only a fraction of results were broken.

Any suggestion for a workaround? (any bitwise right rotation or something)?
It was my first usage of numba and the speedup was great (>10x on GBs of data), but this prevents me using it...

@ghost
Copy link

ghost commented Oct 7, 2019

Changing the mod from the numpy mod to the build in % mod produces the correct result as a heads up.

import numpy as np
import numba

def test_max_mod():
return np.uint64(np.iinfo(np.uint64).max)%np.uint64(16)

@numba.jit
def test_max_mod_jit():
return np.uint64(np.iinfo(np.uint64).max)%np.uint64(16)

print(test_max_mod(), test_max_mod_jit())

@miloslen
Copy link
Author

miloslen commented Oct 7, 2019

Changing the mod from the numpy mod to the build in % mod produces the correct result as a heads up.

import numpy as np
import numba

def test_max_mod():
return np.uint64(np.iinfo(np.uint64).max)%np.uint64(16)

@numba.jit
def test_max_mod_jit():
return np.uint64(np.iinfo(np.uint64).max)%np.uint64(16)

print(test_max_mod(), test_max_mod_jit())

Thanks for the (partial) workaround...

@stuartarchibald
Copy link
Contributor

Thanks for the report, I can reproduce. Looks like @guilhermeleobas has a fix in progress in #4667.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants