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

Function test_iter_best_order

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

Source from the content-addressed store, hash-verified

78 del it2 # avoid pyflakes unused variable warning
79
80def test_iter_best_order():
81 # The iterator should always find the iteration order
82 # with increasing memory addresses
83
84 # Test the ordering for 1-D to 5-D shapes
85 for shape in [(5,), (3, 4), (2, 3, 4), (2, 3, 4, 3), (2, 3, 2, 2, 3)]:
86 a = arange(np.prod(shape))
87 # Test each combination of positive and negative strides
88 for dirs in range(2**len(shape)):
89 dirs_index = [slice(None)]*len(shape)
90 for bit in range(len(shape)):
91 if ((2**bit) & dirs):
92 dirs_index[bit] = slice(None, None, -1)
93 dirs_index = tuple(dirs_index)
94
95 aview = a.reshape(shape)[dirs_index]
96 # C-order
97 i = nditer(aview, [], [['readonly']])
98 assert_equal([x for x in i], a)
99 # Fortran-order
100 i = nditer(aview.T, [], [['readonly']])
101 assert_equal([x for x in i], a)
102 # Other order
103 if len(shape) > 2:
104 i = nditer(aview.swapaxes(0, 1), [], [['readonly']])
105 assert_equal([x for x in i], a)
106
107def test_iter_c_order():
108 # Test forcing C order

Callers

nothing calls this directly

Calls 4

arangeFunction · 0.90
assert_equalFunction · 0.90
reshapeMethod · 0.80
prodMethod · 0.45

Tested by

no test coverage detected