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

Function test_object_iter_cleanup

numpy/_core/tests/test_nditer.py:3252–3272  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3250 assert_equal(vals['d'], 0.5)
3251
3252def test_object_iter_cleanup():
3253 # see gh-18450
3254 # object arrays can raise a python exception in ufunc inner loops using
3255 # nditer, which should cause iteration to stop & cleanup. There were bugs
3256 # in the nditer cleanup when decref'ing object arrays.
3257 # This test would trigger valgrind "uninitialized read" before the bugfix.
3258 assert_raises(TypeError, lambda: np.zeros((17000, 2), dtype='f4') * None)
3259
3260 # this more explicit code also triggers the invalid access
3261 arr = np.arange(ncu.BUFSIZE * 10).reshape(10, -1).astype(str)
3262 oarr = arr.astype(object)
3263 oarr[:, -1] = None
3264 assert_raises(TypeError, lambda: np.add(oarr[:, ::-1], arr[:, ::-1]))
3265
3266 # followup: this tests for a bug introduced in the first pass of gh-18450,
3267 # caused by an incorrect fallthrough of the TypeError
3268 class T:
3269 def __bool__(self):
3270 raise TypeError("Ambiguous")
3271 assert_raises(TypeError, np.logical_or.reduce,
3272 np.array([T(), T()], dtype='O'))
3273
3274def test_object_iter_cleanup_reduce():
3275 # 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…