MCPcopy Create free account
hub / github.com/numpy/numpy / _assert_valid_refcount

Function _assert_valid_refcount

numpy/testing/_private/utils.py:1412–1435  ·  view source on GitHub ↗

Check that ufuncs don't mishandle refcount of object `1`. Used in a few regression tests.

(op)

Source from the content-addressed store, hash-verified

1410
1411
1412def _assert_valid_refcount(op):
1413 """
1414 Check that ufuncs don't mishandle refcount of object `1`.
1415 Used in a few regression tests.
1416 """
1417 if not HAS_REFCOUNT:
1418 return True
1419
1420 import gc
1421 import numpy as np
1422
1423 b = np.arange(100*100).reshape(100, 100)
1424 c = b
1425 i = 1
1426
1427 gc.disable()
1428 try:
1429 rc = sys.getrefcount(i)
1430 for j in range(15):
1431 d = op(b, c)
1432 assert_(sys.getrefcount(i) >= rc)
1433 finally:
1434 gc.enable()
1435 del d # for pyflakes
1436
1437
1438def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,

Callers 2

test_refcount_vdotMethod · 0.90

Calls 3

reshapeMethod · 0.80
enableMethod · 0.80
assert_Function · 0.70

Tested by 2

test_refcount_vdotMethod · 0.72