Check that ufuncs don't mishandle refcount of object `1`. Used in a few regression tests.
(op)
| 1410 | |
| 1411 | |
| 1412 | def _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 | |
| 1438 | def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True, |