| 1345 | op_axes=[[0, 1], [1, 0]]) |
| 1346 | |
| 1347 | def 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"]) |