8000 randint over all of uint64 raises OverflowError if high=... is uint64 but not if it is int · Issue #9256 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
randint over all of uint64 raises OverflowError if high=... is uint64 but not if it is int #9256
Closed
@vrtsig

Description

@vrtsig

Stumbled over this earlier today:

from numpy import uint64, iinfo
from numpy.random import RandomState

uint64_max = iinfo(uint64).max
RandomState(0).randint(uint64_max, dtype=uint64)
# returns 10123822223749065263

RandomState(0).randint(uint64(uint64_max), dtype=uint64)
# raises OverflowError

Traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mtrand.pyx", line 979, in mtrand.RandomState.randint (numpy/random/mtrand/mtrand.c:16422)
  File "mtrand.pyx", line 980, in mtrand.RandomState.randint (numpy/random/mtrand/mtrand.c:16227)
  File "randint_helpers.pxi", line 450, in mtrand._rand_uint64 (numpy/random/mtrand/mtrand.c:5637)
OverflowError: Python int too large to convert to C unsigned long

conda 4.3.21
Python 3.5.3.final.0
numpy 1.12.1
osx-64 (El Capitan)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0