MCPcopy Index your code
hub / github.com/numpy/numpy / test_frompyfunc_leaks

Method test_frompyfunc_leaks

numpy/lib/tests/test_function_base.py:2128–2150  ·  view source on GitHub ↗
(self, name, incr)

Source from the content-addressed store, hash-verified

2126 )
2127 @pytest.mark.slow
2128 def test_frompyfunc_leaks(self, name, incr):
2129 # exposed in gh-11867 as np.vectorized, but the problem stems from
2130 # frompyfunc.
2131 # class.attribute = np.frompyfunc(<method>) creates a
2132 # reference cycle if <method> is a bound class method.
2133 # It requires a gc collection cycle to break the cycle.
2134 import gc
2135 A_func = getattr(self.A, name)
2136 gc.disable()
2137 try:
2138 refcount = sys.getrefcount(A_func)
2139 for i in range(self.A.iters):
2140 a = self.A()
2141 a.f = np.frompyfunc(getattr(a, name), 1, 1)
2142 out = a.f(np.arange(10))
2143 a = None
2144 # A.func is part of a reference cycle if incr is non-zero
2145 assert_equal(sys.getrefcount(A_func), refcount + incr)
2146 for i in range(5):
2147 gc.collect()
2148 assert_equal(sys.getrefcount(A_func), refcount)
2149 finally:
2150 gc.enable()
2151
2152
2153class TestDigitize:

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
enableMethod · 0.80
AMethod · 0.45
fMethod · 0.45

Tested by

no test coverage detected