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

Function test_iter_copy_casts_structured2

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

Source from the content-addressed store, hash-verified

1458
1459
1460def test_iter_copy_casts_structured2():
1461 # Similar to the above, this is a fairly arcane test to cover internals
1462 in_dtype = np.dtype([("a", np.dtype("O,O")),
1463 ("b", np.dtype("(5)O,(3)O,(1,)O,(1,)i,(1,)O"))])
1464 out_dtype = np.dtype([("a", np.dtype("O")),
1465 ("b", np.dtype("O,(3)i,(4)O,(4)O,(4)i"))])
1466
1467 arr = np.ones(1, dtype=in_dtype)
1468 it = np.nditer((arr,), ["buffered", "external_loop", "refs_ok"],
1469 op_dtypes=[out_dtype], casting="unsafe")
1470 it_copy = it.copy()
1471
1472 res1 = next(it)
1473 del it
1474 res2 = next(it_copy)
1475 del it_copy
1476
1477 # Array of two structured scalars:
1478 for res in res1, res2:
1479 # Cast to tuple by getitem, which may be weird and changable?:
1480 assert type(res["a"][0]) == tuple
1481 assert res["a"][0] == (1, 1)
1482
1483 for res in res1, res2:
1484 assert_array_equal(res["b"]["f0"][0], np.ones(5, dtype=object))
1485 assert_array_equal(res["b"]["f1"], np.ones((1, 3), dtype="i"))
1486 assert res["b"]["f2"].shape == (1, 4)
1487 assert_array_equal(res["b"]["f2"][0], np.ones(4, dtype=object))
1488 assert_array_equal(res["b"]["f3"][0], np.ones(4, dtype=object))
1489 assert_array_equal(res["b"]["f3"][0], np.ones(4, dtype="i"))
1490
1491
1492def test_iter_allocate_output_simple():

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
nextFunction · 0.50
dtypeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected