I expected that numexpr.evaluate(xxx, out=array) should write data to array, and eventually it like a fast version of array[:] = xxx, so it should not change the reference count. However, in the following case I expect that del B in the second case should decrease the reference count by 1, but it's not changed. Why does it happen and how to fix it?
import sys
import numpy as np
import numexpr
A = np.zeros(10000)
B = A.reshape((100, 100))
B[:] = 1
print(sys.getrefcount(A), np.sum(A))
del B
print(sys.getrefcount(A), np.sum(A))
r = np.random.random((100, 100))
A = np.zeros(10000)
B = A.reshape((100, 100))
numexpr.evaluate("r + 1", local_dict={'r': r}, global_dict={}, out=B)
print(sys.getrefcount(A), np.sum(A))
del B
print(sys.getrefcount(A), np.sum(A))
The output is
3 10000.0
2 10000.0
3 14951.218372702608
3 14951.218372702608
versions:
numexpr: 2.11.0
numpy: 2.2.0
python: 3.11
I expected that
numexpr.evaluate(xxx, out=array)should write data to array, and eventually it like a fast version ofarray[:] = xxx, so it should not change the reference count. However, in the following case I expect thatdel Bin the second case should decrease the reference count by 1, but it's not changed. Why does it happen and how to fix it?The output is
versions:
numexpr: 2.11.0
numpy: 2.2.0
python: 3.11