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

Function test_partial_iteration_cleanup

numpy/core/tests/test_nditer.py:3211–3235  ·  view source on GitHub ↗

Checks for reference counting leaks during cleanup. Using explicit reference counts lead to occasional false positives (at least in parallel test setups). This test now should still test leaks correctly when run e.g. with pytest-valgrind or pytest-leaks

(in_dtype, buf_dtype, steps)

Source from the content-addressed store, hash-verified

3209 ])
3210@pytest.mark.parametrize("steps", [1, 2, 3])
3211def test_partial_iteration_cleanup(in_dtype, buf_dtype, steps):
3212 """
3213 Checks for reference counting leaks during cleanup. Using explicit
3214 reference counts lead to occasional false positives (at least in parallel
3215 test setups). This test now should still test leaks correctly when
3216 run e.g. with pytest-valgrind or pytest-leaks
3217 """
3218 value = 2**30 + 1 # just a random value that Python won't intern
3219 arr = np.full(int(np.BUFSIZE * 2.5), value).astype(in_dtype)
3220
3221 it = np.nditer(arr, op_dtypes=[np.dtype(buf_dtype)],
3222 flags=["buffered", "external_loop", "refs_ok"], casting="unsafe")
3223 for step in range(steps):
3224 # The iteration finishes in 3 steps, the first two are partial
3225 next(it)
3226
3227 del it # not necessary, but we test the cleanup
3228
3229 # Repeat the test with `iternext`
3230 it = np.nditer(arr, op_dtypes=[np.dtype(buf_dtype)],
3231 flags=["buffered", "external_loop", "refs_ok"], casting="unsafe")
3232 for step in range(steps):
3233 it.iternext()
3234
3235 del it # not necessary, but we test the cleanup
3236
3237@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
3238@pytest.mark.parametrize(["in_dtype", "buf_dtype"],

Callers

nothing calls this directly

Calls 3

astypeMethod · 0.80
nextFunction · 0.50
dtypeMethod · 0.45

Tested by

no test coverage detected