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

Function _assert_valid_refcount

numpy/testing/_private/utils.py:1645–1668  ·  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

1643
1644
1645def _assert_valid_refcount(op):
1646 """
1647 Check that ufuncs don't mishandle refcount of object `1`.
1648 Used in a few regression tests.
1649 """
1650 if not HAS_REFCOUNT:
1651 return True
1652
1653 import gc
1654
1655 import numpy as np
1656
1657 b = np.arange(100 * 100).reshape(100, 100)
1658 c = b
1659 i = 1
1660
1661 gc.disable()
1662 try:
1663 rc = sys.getrefcount(i)
1664 for j in range(15):
1665 d = op(b, c)
1666 assert_(sys.getrefcount(i) >= rc)
1667 finally:
1668 gc.enable()
1669
1670
1671def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,

Callers 2

test_refcount_vdotMethod · 0.90

Calls 3

assert_Function · 0.85
reshapeMethod · 0.80
enableMethod · 0.80

Tested by 2

test_refcount_vdotMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…