Skip to content

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

Closed as not planned
Closed as not planned

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)]

Activity

  1. leokolezhuk commented on Sep 7, 2021

    @leokolezhuk

    Issue still occurs with numpy 1.19.

    I have 2 test arrays:
    test_array_1 = np.ones((7, 8, 9), np.int64)
    test_array_2 = test_array_1 * (4294967295 + 1)
    test_array_1.dtype is dtype('int64')
    test_array_2.dtype is dtype('int64')
    (Note: 4294967295 + 1 is just outside the uint32 range and is needed for my test)

    np.issubdtype(test_array_1.dtype, np.int64) returns True in Windows and True in Ubuntu
    np.issubdtype(test_array_2.dtype, np.int64) returns True in Windows and False in Ubuntu

    In Ubuntu the types of the elements in the arrays are different, but it is not reflected by the 'dtype' of the array:
    type(test_array_1[0,0,0]) is np.int64
    type(test_array_2[0,0,0]) is np.longlong

  2. seberg commented on Nov 3, 2023

    @seberg
    Member

    Going to close this, please make a new issue if you really think the repr needs to change. I would lean to saying that for most users int64 is clearer and longlong just confusing, so hiding the detail that they are different in principle is something for power users. Since usage is not going to be consistent everywhere unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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