Skip to content

numpy.take fails with int64 dtype on i386 architecture #11696

Closed

Description

@rth

numpy.take fails with int64 dtype on i386 architecture

Reproducing code example:

import numpy as np
x = np.arange(10, dtype='int64')
index = np.arange(3, dtype='int64')
x.take(index)

Expected output:

array([0, 1, 2])

is obtained on 64 bit architecture

Error message:

On 32 bit Debian Linux, I get,

>>> x.take(index)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'

On 32 bit windows, the same result was indirectly illustrated in scikit-learn/scikit-learn#11295 (comment)

Numpy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.14.5 3.6.6 (default, Jun 27 2018, 14:44:17) 
[GCC 8.1.0]

Generally this was run in the debian unstable i386 Docker image, with the following setup,

Dockerfile
FROM i386/debian:unstable

RUN apt-get update && apt-get install -y build-essential git make

RUN apt-get install -y python3 python3-scipy python3-numpy python3-setuptools python3-pkg-resources python3-pip

Activity

  1. eric-wieser commented on Aug 9, 2018

    @eric-wieser
    Member

    Arguably this is by design. If you're indexing with a type bigger than np.intp, then it's possible to overflow, and you don't want that.

    From that, it follows that you should really just use np.intp to store indices. Internally, this may save a bunch of copies in numpy anyway

  2. rth commented on Aug 9, 2018

    @rth
    ContributorAuthor

    OK, makes sense. Thanks @eric-wieser !

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