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

Function test_iter_f_order

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

Source from the content-addressed store, hash-verified

132 aview.swapaxes(0, 1).ravel(order='C'))
133
134def test_iter_f_order():
135 # Test forcing F order
136
137 # Test the ordering for 1-D to 5-D shapes
138 for shape in [(5,), (3, 4), (2, 3, 4), (2, 3, 4, 3), (2, 3, 2, 2, 3)]:
139 a = arange(np.prod(shape))
140 # Test each combination of positive and negative strides
141 for dirs in range(2**len(shape)):
142 dirs_index = [slice(None)]*len(shape)
143 for bit in range(len(shape)):
144 if ((2**bit) & dirs):
145 dirs_index[bit] = slice(None, None, -1)
146 dirs_index = tuple(dirs_index)
147
148 aview = a.reshape(shape)[dirs_index]
149 # C-order
150 i = nditer(aview, order='F')
151 assert_equal([x for x in i], aview.ravel(order='F'))
152 # Fortran-order
153 i = nditer(aview.T, order='F')
154 assert_equal([x for x in i], aview.T.ravel(order='F'))
155 # Other order
156 if len(shape) > 2:
157 i = nditer(aview.swapaxes(0, 1), order='F')
158 assert_equal([x for x in i],
159 aview.swapaxes(0, 1).ravel(order='F'))
160
161def test_iter_c_or_f_order():
162 # Test forcing any contiguous (C or F) order

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected