Ring-order of a height x width mesh. For example, in a 4x4 mesh, this returns the following order. 0 -- 1 -- 2 -- 3 | | | | 15-- 6 -- 5 -- 4 | | | | 14-- 7 -- 8 -- 9 | | | | 13-- 12-- 11-- 10 Args: height: An integer represents the hei
(height, width)
| 176 | |
| 177 | |
| 178 | def _ring_2d(height, width): |
| 179 | """Ring-order of a height x width mesh. |
| 180 | |
| 181 | For example, in a 4x4 mesh, this returns the following order. |
| 182 | 0 -- 1 -- 2 -- 3 |
| 183 | | | | | |
| 184 | 15-- 6 -- 5 -- 4 |
| 185 | | | | | |
| 186 | 14-- 7 -- 8 -- 9 |
| 187 | | | | | |
| 188 | 13-- 12-- 11-- 10 |
| 189 | |
| 190 | Args: |
| 191 | height: An integer represents the height. |
| 192 | width: An integer represents the width. |
| 193 | |
| 194 | Returns: |
| 195 | A list of [y, x] pairs with ring order. |
| 196 | """ |
| 197 | if height == 1: |
| 198 | return [(0, i) for i in range(width)] |
| 199 | if width == 1: |
| 200 | return [(i, 0) for i in range(height)] |
| 201 | if height % 2 != 0: |
| 202 | logging.warning("Odd dimension") |
| 203 | return [(i % height, i // height) for i in range(width * height)] |
| 204 | ret = [(0, 0)] |
| 205 | for i in range(height // 2): |
| 206 | for j in range(1, width): |
| 207 | ret.append((2 * i, j)) |
| 208 | for j in range(width - 1, 0, -1): |
| 209 | ret.append((2 * i + 1, j)) |
| 210 | for i in range(height - 1, 0, -1): |
| 211 | ret.append((i, 0)) |
| 212 | return ret |
| 213 | |
| 214 | |
| 215 | def device_assignment(topology, |
no test coverage detected