You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
randint output have different dtype on Linux and Windows #10317
Windows-10-10.0.14393-SP0
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 15:10:56) [MSC v.1900 64 bit (AMD64)]
NumPy 1.13.3
This is due to the fact that the default input parameter is dtype='l'. I saw that there was a lot of related discussion leading to #6910 but I was wondering if there were reasons that prevented setting dtype=np.int64 by default there.
The current behaviour is problematic with any typed code (e.g. Cython / GPU related), and, for instance led to maciejkula/spotlight#82
A much simpler reproduction is np.dtype(int).itemsize, which is 4 on windows, and 8 elsewhere. Having the dtype default to int is reasonable, but we might want to change the meaning of np.dtype(int)
np.array(1) also falls afoul of these different dtypes.
There is no fundamental reason but the requirement for same inputs = same outputs (conditional on platform, compiler, etc.) means that this cannot be changed in the current RandomState implementation. It is just legacy. This pattern of int32 on Windows and int64 otherwise is related for virtually all integer generators. Ideally all integer-based generators would default to int64.
The default was chosen for backwards compatibility, although it is already somewhat broken as it is OS dependent. The simplest solution is to explicitly specify the dtype.
Note that these problems with the long C type are inherited from early Python before it became fully 64 bit compatible with Python 2.5. We were still supporting Python 2.4 as recently as 1.7 (2013).
Activity
eric-wieser commentedon Jan 3, 2018
A much simpler reproduction is
np.dtype(int).itemsize, which is 4 on windows, and 8 elsewhere. Having the dtype default tointis reasonable, but we might want to change the meaning ofnp.dtype(int)np.array(1)also falls afoul of these different dtypes.pv commentedon Jan 3, 2018
bashtage commentedon Jan 3, 2018
There is no fundamental reason but the requirement for same inputs = same outputs (conditional on platform, compiler, etc.) means that this cannot be changed in the current
RandomStateimplementation. It is just legacy. This pattern of int32 on Windows and int64 otherwise is related for virtually all integer generators. Ideally all integer-based generators would default to int64.charris commentedon Jan 3, 2018
The default was chosen for backwards compatibility, although it is already somewhat broken as it is OS dependent. The simplest solution is to explicitly specify the dtype.
charris commentedon Jan 3, 2018
Note that these problems with the long C type are inherited from early Python before it became fully 64 bit compatible with Python 2.5. We were still supporting Python 2.4 as recently as 1.7 (2013).
rth commentedon Jan 4, 2018
I understand, thank you for the explanations.
mattip commentedon Jun 13, 2018
Closing, please reopen if you wish to pursue changing this