Skip to content

BUG: temporary elision heuristics are broken on Python 3.14 #28681

@ngoldbaum

Description

@ngoldbaum

Describe the issue:

This was originally found by @vfdev-5 working on the Jax CI.

For whatever reason, simple indexing operations seem to return garbage data leading to breakage.

Reproduce the code example:

import math
import numpy as np


shape = (8, 4000, 1000)
x = np.arange(math.prod(shape)).reshape(shape)
np.testing.assert_allclose(x, x)

Error message:

ValueError:
error during assertion:

Traceback (most recent call last):
  File "/Users/goldbaum/.pyenv/versions/3.14-dev/lib/python3.14/site-packages/numpy/testing/_private/utils.py", line 850, in assert_array_compare
    val = comparison(x, y)
  File "/Users/goldbaum/.pyenv/versions/3.14-dev/lib/python3.14/site-packages/numpy/testing/_private/utils.py", line 1706, in compare
    return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                   equal_nan=equal_nan)
                                   ^^^^^^^^^^^^^^^^^^^^
  File "/Users/goldbaum/.pyenv/versions/3.14-dev/lib/python3.14/site-packages/numpy/_core/numeric.py", line 2447, in isclose
    result = (less_equal(abs(x - y), atol + rtol * abs(y))
                             ~~^~~
ValueError: operands could not be broadcast together with shapes (32000000,) (0,)


Not equal to tolerance rtol=1e-07, atol=0
 ACTUAL: array([       0,        1,        2, ..., 31999997, 31999998, 31999999],
      shape=(32000000,))
 DESIRED: array([], dtype=int64)

Context for the issue:

Ultimately this comes down to an operation inside of assert_array_compare that does two boolean indexing operations on the same line:

(Pdb) p x.shape, y.shape
((8, 4000, 1000), (8, 4000, 1000))
(Pdb) n
> /Users/goldbaum/.pyenv/versions/3.14t-dev/lib/python3.14t/site-packages/numpy/testing/_private/utils.py(842)assert_array_compare()
-> x, y = x[~flagged], y[~flagged]
(Pdb) n
> /Users/goldbaum/.pyenv/versions/3.14t-dev/lib/python3.14t/site-packages/numpy/testing/_private/utils.py(844)assert_array_compare()
-> if x.size == 0:
(Pdb) p x.shape, y.shape
((32000000,), (0,))
(Pdb) p np.any(flagged)
np.False_

y.shape should definitely not be (0,) here.

See below for an explanation of what's going on: #28681 (comment)

Python and NumPy Versions:

Python 3.14, compiled from source today.

Python 3.14.0a7+ (heads/main:a214db0, Apr 10 2025, 10:22:26) [Clang 17.0.0 (clang-1700.0.13.3)]

Runtime Environment:

WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information
[{'numpy_version': '2.3.0.dev0+git20250409.734e2cd',
  'python': '3.14.0a7+ (heads/main:a214db0, Apr 10 2025, 10:22:26) [Clang '
            '17.0.0 (clang-1700.0.13.3)]',
  'uname': uname_result(system='Darwin', node='Nathans-MBP', release='24.4.0', version='Darwin Kernel Version 24.4.0: Wed Mar 19 21:17:32 PDT 2025; root:xnu-11417.101.15~1/RELEASE_ARM64_T6030', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM', 'SVE']}}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions