Skip to content

np.longlong and np.int64 are inconsistent on Linux x64 #12264

@wkcn

Description

@wkcn

It's confusing that np.longlong and np.int64 are inconsistent on Linux x64, however their str are both <type 'numpy.int64'>.

np.int64 == np.longlong is True on Windows, False on Linux.
np.dtype(np.longlong).char is 'q' on Windows x64 and Linux x64.
np.dtype(np.int64).char is 'q' on Windows x64, 'l' on Linux x64.

I think the reason is that the C type long is 32 bits on Windows x64, but 64 bits on Linux x64.

In the file numpy/core/include/numpy/npy_common.h,

On Linux x64,
sizeof(long) == 64, so #define NPY_INT64 NPY_LONG  

On Windows x64,
sizeof(long) == 32, so #define NPY_INT64 NPY_LONGLONG

Reproducing code example:

import numpy as np
print ('np.int64', 'np.longlong')
print (np.int64)
print (np.longlong)
print (np.int64 == np.longlong)
print (str(np.int64) == str(np.longlong))

print ('np.dtype(np.int64).type', 'np.dtype(np.longlong).type')
print (np.dtype(np.int64).type, np.dtype(np.longlong).type)
print (np.dtype(np.int64).type == np.dtype(np.longlong).type)

print ('np.dtype(np.int64).char', 'np.dtype(np.longlong).char')
print (np.dtype(np.int64).char, np.dtype(np.longlong).char)
print (np.dtype(np.int64).char == np.dtype(np.longlong).char)

print ('np.dtype(np.int64).name', 'np.dtype(np.longlong).name')
print (np.dtype(np.int64).name, np.dtype(np.longlong).name)
print (np.dtype(np.int64).name == np.dtype(np.longlong).name)

Output on Arch Linux x64, python2 and python3

('np.int64', 'np.longlong')
<type 'numpy.int64'>
<type 'numpy.int64'>
False
True
('np.dtype(np.int64).type', 'np.dtype(np.longlong).type')
(<type 'numpy.int64'>, <type 'numpy.int64'>)
False
('np.dtype(np.int64).char', 'np.dtype(np.longlong).char')
('l', 'q')
False
('np.dtype(np.int64).name', 'np.dtype(np.longlong).name')
('int64', 'int64')
True

Output on Windows 7 x64, python3

np.int64 np.longlong
<class 'numpy.int64'>
<class 'numpy.int64'>
True
True
np.dtype(np.int64).type np.dtype(np.longlong).type
<class 'numpy.int64'> <class 'numpy.int64'>
True
np.dtype(np.int64).char np.dtype(np.longlong).char
q q
True
np.dtype(np.int64).name np.dtype(np.longlong).name
int64 int64
True

Error message:

Numpy/Python version information:

On Linux x64,
Python2: ('1.15.2', '2.7.15 (default, Jun 27 2018, 13:05:28) \n[GCC 8.1.1 20180531]')
Python3: 1.15.2 3.7.1 (default, Oct 22 2018, 10:41:28) [GCC 8.2.1 20180831]

On Windows x64, 1.14.5 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions