Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: np.bincount casting uint64 to int64 #28354

@jakirkham

Description

@jakirkham

Describe the issue:

When passing a uint64 array to np.bincount, it appears to try to cast the input (or some internally created array) to int64. This in turn raises an exception.

Reproduce the code example:

import numpy as np

a = np.arange(64, dtype=np.uint64)
np.bincount(a)

Error message:

Traceback (most recent call last):
  File "...", line 4, in <module>
    np.bincount(a)
TypeError: Cannot cast array data from dtype('uint64') to dtype('int64') according to the rule 'safe'

Python and NumPy Versions:

2.2.2
3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:32:50) [Clang 16.0.6 ]

Runtime Environment:

[{'numpy_version': '2.2.2',
  'python': '3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:32:50) '
            '[Clang 16.0.6 ]',
  'uname': uname_result(system='Darwin', node='jkirkham-mlt', release='23.6.0', version='Darwin Kernel Version 23.6.0: Thu Sep 12 23:35:29 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6000', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}},
 {'architecture': 'VORTEX',
  'filepath': '/Users/jkirkham/miniforge/lib/libopenblas.0.dylib',
  'internal_api': 'openblas',
  'num_threads': 10,
  'prefix': 'libopenblas',
  'threading_layer': 'openmp',
  'user_api': 'blas',
  'version': '0.3.28'},
 {'filepath': '/Users/jkirkham/miniforge/lib/libomp.dylib',
  'internal_api': 'openmp',
  'num_threads': 10,
  'prefix': 'libomp',
  'user_api': 'openmp',
  'version': None}]

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions