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

Function test_object_iter_cleanup

numpy/core/tests/test_nditer.py:3001–3021  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2999 assert_equal(vals['d'], 0.5)
3000
3001def test_object_iter_cleanup():
3002 # see gh-18450
3003 # object arrays can raise a python exception in ufunc inner loops using
3004 # nditer, which should cause iteration to stop & cleanup. There were bugs
3005 # in the nditer cleanup when decref'ing object arrays.
3006 # This test would trigger valgrind "uninitialized read" before the bugfix.
3007 assert_raises(TypeError, lambda: np.zeros((17000, 2), dtype='f4') * None)
3008
3009 # this more explicit code also triggers the invalid access
3010 arr = np.arange(np.BUFSIZE * 10).reshape(10, -1).astype(str)
3011 oarr = arr.astype(object)
3012 oarr[:, -1] = None
3013 assert_raises(TypeError, lambda: np.add(oarr[:, ::-1], arr[:, ::-1]))
3014
3015 # followup: this tests for a bug introduced in the first pass of gh-18450,
3016 # caused by an incorrect fallthrough of the TypeError
3017 class T:
3018 def __bool__(self):
3019 raise TypeError("Ambiguous")
3020 assert_raises(TypeError, np.logical_or.reduce,
3021 np.array([T(), T()], dtype='O'))
3022
3023def test_object_iter_cleanup_reduce():
3024 # Similar as above, but a complex reduction case that was previously

Callers

nothing calls this directly

Calls 5

assert_raisesFunction · 0.90
astypeMethod · 0.80
reshapeMethod · 0.80
TClass · 0.70
addMethod · 0.45

Tested by

no test coverage detected