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

Function test_iter_copy

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

Source from the content-addressed store, hash-verified

1345 op_axes=[[0, 1], [1, 0]])
1346
1347def test_iter_copy():
1348 # Check that copying the iterator works correctly
1349 a = arange(24).reshape(2, 3, 4)
1350
1351 # Simple iterator
1352 i = nditer(a)
1353 j = i.copy()
1354 assert_equal([x[()] for x in i], [x[()] for x in j])
1355
1356 i.iterindex = 3
1357 j = i.copy()
1358 assert_equal([x[()] for x in i], [x[()] for x in j])
1359
1360 # Buffered iterator
1361 i = nditer(a, ['buffered', 'ranged'], order='F', buffersize=3)
1362 j = i.copy()
1363 assert_equal([x[()] for x in i], [x[()] for x in j])
1364
1365 i.iterindex = 3
1366 j = i.copy()
1367 assert_equal([x[()] for x in i], [x[()] for x in j])
1368
1369 i.iterrange = (3, 9)
1370 j = i.copy()
1371 assert_equal([x[()] for x in i], [x[()] for x in j])
1372
1373 i.iterrange = (2, 18)
1374 next(i)
1375 next(i)
1376 j = i.copy()
1377 assert_equal([x[()] for x in i], [x[()] for x in j])
1378
1379 # Casting iterator
1380 with nditer(a, ['buffered'], order='F', casting='unsafe',
1381 op_dtypes='f8', buffersize=5) as i:
1382 j = i.copy()
1383 assert_equal([x[()] for x in j], a.ravel(order='F'))
1384
1385 a = arange(24, dtype='<i4').reshape(2, 3, 4)
1386 with nditer(a, ['buffered'], order='F', casting='unsafe',
1387 op_dtypes='>f8', buffersize=5) as i:
1388 j = i.copy()
1389 assert_equal([x[()] for x in j], a.ravel(order='F'))
1390
1391
1392@pytest.mark.parametrize("dtype", np.typecodes["All"])

Callers

nothing calls this directly

Calls 6

arangeFunction · 0.90
assert_equalFunction · 0.90
reshapeMethod · 0.80
nextFunction · 0.50
copyMethod · 0.45
ravelMethod · 0.45

Tested by

no test coverage detected