MCPcopy Index your code
hub / github.com/numpy/numpy / test_iter_best_order

Function test_iter_best_order

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

Source from the content-addressed store, hash-verified

87 assert_equal(sys.getrefcount(dt), rc_dt)
88
89def test_iter_best_order():
90 # The iterator should always find the iteration order
91 # with increasing memory addresses
92
93 # Test the ordering for 1-D to 5-D shapes
94 for shape in [(5,), (3, 4), (2, 3, 4), (2, 3, 4, 3), (2, 3, 2, 2, 3)]:
95 a = arange(np.prod(shape))
96 # Test each combination of positive and negative strides
97 for dirs in range(2**len(shape)):
98 dirs_index = [slice(None)] * len(shape)
99 for bit in range(len(shape)):
100 if ((2**bit) & dirs):
101 dirs_index[bit] = slice(None, None, -1)
102 dirs_index = tuple(dirs_index)
103
104 aview = a.reshape(shape)[dirs_index]
105 # C-order
106 i = nditer(aview, [], [['readonly']])
107 assert_equal(list(i), a)
108 # Fortran-order
109 i = nditer(aview.T, [], [['readonly']])
110 assert_equal(list(i), a)
111 # Other order
112 if len(shape) > 2:
113 i = nditer(aview.swapaxes(0, 1), [], [['readonly']])
114 assert_equal(list(i), a)
115
116def test_iter_c_order():
117 # Test forcing C order

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…