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

Function test_iter_c_order

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

Source from the content-addressed store, hash-verified

105 assert_equal([x for x in i], a)
106
107def test_iter_c_order():
108 # Test forcing C order
109
110 # Test the ordering for 1-D to 5-D shapes
111 for shape in [(5,), (3, 4), (2, 3, 4), (2, 3, 4, 3), (2, 3, 2, 2, 3)]:
112 a = arange(np.prod(shape))
113 # Test each combination of positive and negative strides
114 for dirs in range(2**len(shape)):
115 dirs_index = [slice(None)]*len(shape)
116 for bit in range(len(shape)):
117 if ((2**bit) & dirs):
118 dirs_index[bit] = slice(None, None, -1)
119 dirs_index = tuple(dirs_index)
120
121 aview = a.reshape(shape)[dirs_index]
122 # C-order
123 i = nditer(aview, order='C')
124 assert_equal([x for x in i], aview.ravel(order='C'))
125 # Fortran-order
126 i = nditer(aview.T, order='C')
127 assert_equal([x for x in i], aview.T.ravel(order='C'))
128 # Other order
129 if len(shape) > 2:
130 i = nditer(aview.swapaxes(0, 1), order='C')
131 assert_equal([x for x in i],
132 aview.swapaxes(0, 1).ravel(order='C'))
133
134def test_iter_f_order():
135 # Test forcing 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