-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: reference cycle in np.vectorize #11977
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
Changes from 1 commit
0267264
f73d96d
a3b9f75
7474a71
82419c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1505,11 +1505,11 @@ class A(object): | |
iters = 20 | ||
|
||
def bound(self, *args): | ||
return np.int(0) | ||
return 0 | ||
|
||
@staticmethod | ||
def unbound(*args): | ||
return np.int(0) | ||
return 0 | ||
|
||
def npy_bound(self, a): | ||
return types.MethodType(np.frompyfunc(self.bound, 1, 1), a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm very confused by what exactly we're trying to test here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR looks good to me, if nobody complains will merge in a bit probably. The test couldbe a bit more obvious to read, or maybe add a trivial one: def func(a):
return 0
func.vectorized = np.frompyfunc(func) giving a minimal cycle. The other part would probably be simpler by making it a realistic use case: class A(object):
def __init__(self):
# Wrap bound_method into a ufunc with `np.frompyfunc`. This creates
# a reference cycle:
# self.method -> self # since it is a bound method (knows "self")
# self -> self.wrapped_method # Set here
# self.wrapped_method -> self.method # Stores self.method to call it
self.wrapped_method = np.frompyfunc(self.method)
def method(self):
return 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I guess that breaks the parameterization. Although, I do not think you need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not following. Where would I add that line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think what confuses me is that I believe you do not need this at all. You can simply remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adopted |
||
|
@@ -1527,8 +1527,8 @@ def test_frompyfunc_leaks(self, func, npy_func, incr): | |
# exposed in gh-11867 as np.vectorized, but the problem stems from | ||
# frompyfunc. | ||
# class.attribute = np.frompyfunc(<method>) creates a | ||
# reference cycle that requires a gc collection cycle to break | ||
# (on CPython 3) | ||
# reference cycle if <method> is a bound class method that requires a | ||
# gc collection cycle to break (on CPython 3) | ||
import gc | ||
|
||
gc.disable() | ||
|
Uh oh!
There was an error while loading. Please reload this page.