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

Function test_iter_buffered_reduce_reuse

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

Source from the content-addressed store, hash-verified

2308
2309@pytest.mark.slow
2310def test_iter_buffered_reduce_reuse():
2311 # large enough array for all views, including negative strides.
2312 a = np.arange(2*3**5)[3**5:3**5+1]
2313 flags = ['buffered', 'delay_bufalloc', 'multi_index', 'reduce_ok', 'refs_ok']
2314 op_flags = [('readonly',), ('readwrite', 'allocate')]
2315 op_axes_list = [[(0, 1, 2), (0, 1, -1)], [(0, 1, 2), (0, -1, -1)]]
2316 # wrong dtype to force buffering
2317 op_dtypes = [float, a.dtype]
2318
2319 def get_params():
2320 for xs in range(-3**2, 3**2 + 1):
2321 for ys in range(xs, 3**2 + 1):
2322 for op_axes in op_axes_list:
2323 # last stride is reduced and because of that not
2324 # important for this test, as it is the inner stride.
2325 strides = (xs * a.itemsize, ys * a.itemsize, a.itemsize)
2326 arr = np.lib.stride_tricks.as_strided(a, (3, 3, 3), strides)
2327
2328 for skip in [0, 1]:
2329 yield arr, op_axes, skip
2330
2331 for arr, op_axes, skip in get_params():
2332 nditer2 = np.nditer([arr.copy(), None],
2333 op_axes=op_axes, flags=flags, op_flags=op_flags,
2334 op_dtypes=op_dtypes)
2335 with nditer2:
2336 nditer2.operands[-1][...] = 0
2337 nditer2.reset()
2338 nditer2.iterindex = skip
2339
2340 for (a2_in, b2_in) in nditer2:
2341 b2_in += a2_in.astype(np.int_)
2342
2343 comp_res = nditer2.operands[-1]
2344
2345 for bufsize in range(0, 3**3):
2346 nditer1 = np.nditer([arr, None],
2347 op_axes=op_axes, flags=flags, op_flags=op_flags,
2348 buffersize=bufsize, op_dtypes=op_dtypes)
2349 with nditer1:
2350 nditer1.operands[-1][...] = 0
2351 nditer1.reset()
2352 nditer1.iterindex = skip
2353
2354 for (a1_in, b1_in) in nditer1:
2355 b1_in += a1_in.astype(np.int_)
2356
2357 res = nditer1.operands[-1]
2358 assert_array_equal(res, comp_res)
2359
2360
2361def test_iter_no_broadcast():

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
get_paramsFunction · 0.85
astypeMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected