numpy / numpy

The fundamental package for scientific computing with Python.
https://numpy.org
Other
27.53k stars 9.84k forks source link

test_iter_refcount fails with numpy 2.0.0 local build with python 3.13 #26955

Closed pajarrige closed 1 month ago

pajarrige commented 1 month ago

I compiled numpy 2.0.0 for python 3.13 (32 and 64 bits) (v3.13.0b3:7b41395) on Windows 11 using Visual Studio 2019 Pro and Intel OneAPI 2024.2. With both (32 and 64 bits) numpy.test() raise a failure for test_iter_refcount:

_________________________________________________ test_iter_refcount __________________________________________________

    @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
    def test_iter_refcount():
        # Make sure the iterator doesn't leak

        # Basic
        a = arange(6)
        dt = np.dtype('f4').newbyteorder()
        rc_a = sys.getrefcount(a)
        rc_dt = sys.getrefcount(dt)
        with nditer(a, [],
                    [['readwrite', 'updateifcopy']],
                    casting='unsafe',
                    op_dtypes=[dt]) as it:
            assert_(not it.iterationneedsapi)
            assert_(sys.getrefcount(a) > rc_a)
            assert_(sys.getrefcount(dt) > rc_dt)
        # del 'it'
        it = None
        assert_equal(sys.getrefcount(a), rc_a)
        assert_equal(sys.getrefcount(dt), rc_dt)

        # With a copy
        a = arange(6, dtype='f4')
        dt = np.dtype('f4')
        rc_a = sys.getrefcount(a)
        rc_dt = sys.getrefcount(dt)
        it = nditer(a, [],
                    [['readwrite']],
                    op_dtypes=[dt])
        rc2_a = sys.getrefcount(a)
        rc2_dt = sys.getrefcount(dt)
        it2 = it.copy()
        assert_(sys.getrefcount(a) > rc2_a)
>       assert_(sys.getrefcount(dt) > rc2_dt)
E       AssertionError

a          = array([0., 1., 2., 3., 4., 5.], dtype=float32)
dt         = dtype('float32')
it         = <numpy.nditer object at 0x0000018F40D60810>
it2        = <numpy.nditer object at 0x0000018F40D60E30>
rc2_a      = 3
rc2_dt     = 4294967295
rc_a       = 2
rc_dt      = 4294967295

..\..\..\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\tests\test_nditer.py:71: AssertionError

numpy.show_runtime():

[{'numpy_version': '2.0.0',
  'python': '3.13.0b3 (tags/v3.13.0b3:7b41395, Jun 27 2024, 16:08:48) [MSC '
            'v.1940 64 bit (AMD64)]',
  'uname': uname_result(system='Windows', node='W0010SL00083278', release='11', version='10.0.22631', machine='AMD64')},
 {'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}}]
rgommers commented 1 month ago

Thanks for the report @pajarrige. The problem you're seeing is fixed in main. NumPy 2.0.0 does not support Python 3.13, as noted in the release notes. Please build from main instead, or use a nightly wheel from https://anaconda.org/scientific-python-nightly-wheels/numpy/.

I'll note that this is pretty much always true for NumPy - a release on PyPI does not support a pre-release of the next CPython before the first NumPy release after 3.xx.0rc1. It may work, or it may not. Installing from main is always better.