MCPcopy
hub / github.com/numpy/numpy / test_iter_c_order

Function test_iter_c_order

numpy/_core/tests/test_nditer.py:116–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114 assert_equal(list(i), a)
115
116def test_iter_c_order():
117 # Test forcing C order
118
119 # Test the ordering for 1-D to 5-D shapes
120 for shape in [(5,), (3, 4), (2, 3, 4), (2, 3, 4, 3), (2, 3, 2, 2, 3)]:
121 a = arange(np.prod(shape))
122 # Test each combination of positive and negative strides
123 for dirs in range(2**len(shape)):
124 dirs_index = [slice(None)] * len(shape)
125 for bit in range(len(shape)):
126 if ((2**bit) & dirs):
127 dirs_index[bit] = slice(None, None, -1)
128 dirs_index = tuple(dirs_index)
129
130 aview = a.reshape(shape)[dirs_index]
131 # C-order
132 i = nditer(aview, order='C')
133 assert_equal(list(i), aview.ravel(order='C'))
134 # Fortran-order
135 i = nditer(aview.T, order='C')
136 assert_equal(list(i), aview.T.ravel(order='C'))
137 # Other order
138 if len(shape) > 2:
139 i = nditer(aview.swapaxes(0, 1), order='C')
140 assert_equal(list(i),
141 aview.swapaxes(0, 1).ravel(order='C'))
142
143def test_iter_f_order():
144 # Test forcing F order

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
sliceFunction · 0.85
reshapeMethod · 0.80
prodMethod · 0.45
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…