-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Closed as not planned
Labels
Description
Describe the issue:
Since numpy 2.3, np.power
provides a different result than np.float_power
.
I'm aware of issues #26002 and #23523. But using NPY_DISABLE_CPU_FEATURES
does not seem to change the result.
Reproduce the code example:
import numpy as np
result = np.power(np.float64(141322), np.float64(-1.0))
# np.float64(7.0760391163442356e-06)
# View the result bit representation
np.binary_repr(result.view(np.uint64), width=64)
# '0011111011011101101011011101011011010010010111101000001000000000'
result = np.float_power(np.float64(141322), np.float64(-1.0))
# np.float64(7.076039116344235e-06)
# View the result bit representation
np.binary_repr(result.view(np.uint64), width=64)
# '0011111011011101101011011101011011010010010111101000000111111111'
# Compare with python arithmetic
result = 141322 ** -1.0
# 7.076039116344235e-06
# View the result bit representation
import struct
''.join('{:0>8b}'.format(c) for c in struct.pack('!d', result))
# '0011111011011101101011011101011011010010010111101000000111111111'
numpy 2.2.6
does not have this behaviour change. All results are like the Python result.
Python and NumPy Versions:
3.11.13 (main, Jun 4 2025, 08:57:30) [GCC 13.3.0]
2.3.2
Runtime Environment:
[{'numpy_version': '2.3.2',
'python': '3.11.13 (main, Jun 4 2025, 08:57:30) [GCC 13.3.0]',
'uname': uname_result(system='Linux', node='F0251-linux', release='6.8.0-78-generic', version='#78-Ubuntu SMP PREEMPT_DYNAMIC Tue Aug 12 11:34:18 UTC 2025', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'architecture': 'Haswell',
'filepath': '/home/gille02d/src/environments/fds-311/lib/python3.11/site-packages/numpy.libs/libscipy_openblas64_-8fb3d286.so',
'internal_api': 'openblas',
'num_threads': 8,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.30'}]
Context for the issue:
I'm processing time series, where I need to apply simple mathematical operations such as 1/x
. The result should be exactly the same for reproducibility. We hash the resulting array, which is how we found that only a few elements had a different bit representation.
My original code uses something more like my_array ** -1.0
but I tried to come up with the smallest example that allow to reproduce the issue.
SumitkCodesSumitkCodes