-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Closed
Copy link
Labels
Description
Describe the issue:
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:
import sys
import numpy as np
a = 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
# 310281Error message:
No response
NumPy/Python version information:
NumPy 1.25 and earlier
Context for the issue:
No response