You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: Choose (and probably more item selection) leaks references with out= #22683
np.choose internally uses raw access to the array data and a final PyArray_INCREF. That somewhat works generally, but if out= is specified, that result array would need to be cleared first.
The short-term solution here is likely that we need to use the element copy function rather than memcpy when necessary (elsewhere, we currently use copyswap if the dtype flags "needs API").
I suspect, we need to keep something like copyswap, but I need to also think about how to evolve that function.
Reproduce the code example:
importsysimportnumpyasnpa=np.ones(10000, dtype=object)
sys.getrefcount(1)
np.choose(np.zeros(10000, dtype=int), [a], out=a)
sys.getrefcount(1)
np.choose(np.zeros(10000, dtype=int), [a], out=a)
sys.getrefcount(1)
# Prints (increasing by 10000 every time):# 290281# 300281# 310281
Activity
BUG: fix choose refcount leak
BUG: fix choose refcount leak
BUG: fix choose refcount leak
BUG: fix choose refcount leak
BUG: fix choose refcount leak
BUG: fix choose refcount leak