Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Choose (and probably more item selection) leaks references with out= #22683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seberg opened this issue Nov 28, 2022 · 0 comments · Fixed by #24188
Closed

BUG: Choose (and probably more item selection) leaks references with out= #22683

seberg opened this issue Nov 28, 2022 · 0 comments · Fixed by #24188
Labels
00 - Bug Priority: low Valid, but not for immediate attention

Comments

@seberg
Copy link
Member

seberg commented Nov 28, 2022

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
# 310281

Error message:

No response

NumPy/Python version information:

NumPy 1.25 and earlier

Context for the issue:

No response

@seberg seberg added 00 - Bug Priority: low Valid, but not for immediate attention labels Nov 28, 2022
tylerjereddy added a commit to tylerjereddy/numpy that referenced this issue Jul 15, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
tylerjereddy added a commit to tylerjereddy/numpy that referenced this issue Jul 15, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
tylerjereddy added a commit to tylerjereddy/numpy that referenced this issue Jul 18, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
seberg pushed a commit to tylerjereddy/numpy that referenced this issue Jul 31, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
charris pushed a commit to charris/numpy that referenced this issue Aug 3, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
charris pushed a commit to charris/numpy that referenced this issue Nov 11, 2023
* Fixes numpy#22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug Priority: low Valid, but not for immediate attention
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant