Reformat the indices for assignment. The aim of this is to convert the indices to a standardised form so that it is easier to ascertain which chunks are touched by the indices. This function is intended to be called by `setitem_array`. A slice object that is decreasing (i.e. w
(indices, shape)
| 1234 | |
| 1235 | |
| 1236 | def parse_assignment_indices(indices, shape): |
| 1237 | """Reformat the indices for assignment. |
| 1238 | |
| 1239 | The aim of this is to convert the indices to a standardised form |
| 1240 | so that it is easier to ascertain which chunks are touched by the |
| 1241 | indices. |
| 1242 | |
| 1243 | This function is intended to be called by `setitem_array`. |
| 1244 | |
| 1245 | A slice object that is decreasing (i.e. with a negative step), is |
| 1246 | recast as an increasing slice (i.e. with a positive step. For |
| 1247 | example ``slice(7,3,-1)`` would be cast as ``slice(4,8,1)``. This |
| 1248 | is to facilitate finding which blocks are touched by the |
| 1249 | index. The dimensions for which this has occurred are returned by |
| 1250 | the function. |
| 1251 | |
| 1252 | Parameters |
| 1253 | ---------- |
| 1254 | indices : numpy-style indices |
| 1255 | Indices to array defining the elements to be assigned. |
| 1256 | shape : sequence of `int` |
| 1257 | The shape of the array. |
| 1258 | |
| 1259 | Returns |
| 1260 | ------- |
| 1261 | parsed_indices : `list` |
| 1262 | The reformatted indices that are equivalent to the input |
| 1263 | indices. |
| 1264 | implied_shape : `list` |
| 1265 | The shape implied by the parsed indices. For instance, indices |
| 1266 | of ``(slice(0,2), 5, [4,1,-1])`` will have implied shape |
| 1267 | ``[2,3]``. |
| 1268 | reverse : `list` |
| 1269 | The positions of the dimensions whose indices in the |
| 1270 | parsed_indices output are reversed slices. |
| 1271 | implied_shape_positions: `list` |
| 1272 | The positions of the dimensions whose indices contribute to |
| 1273 | the implied_shape. For instance, indices of ``(slice(0,2), 5, |
| 1274 | [4,1,-1])`` will have implied_shape ``[2,3]`` and |
| 1275 | implied_shape_positions ``[0,2]``. |
| 1276 | |
| 1277 | Examples |
| 1278 | -------- |
| 1279 | >>> parse_assignment_indices((slice(1, -1),), (8,)) |
| 1280 | ([slice(1, 7, 1)], [6], [], [0]) |
| 1281 | |
| 1282 | >>> parse_assignment_indices(([1, 2, 6, 5],), (8,)) |
| 1283 | ([array([1, 2, 6, 5])], [4], [], [0]) |
| 1284 | |
| 1285 | >>> parse_assignment_indices((3, slice(-1, 2, -1)), (7, 8)) |
| 1286 | ([3, slice(3, 8, 1)], [5], [1], [1]) |
| 1287 | |
| 1288 | >>> parse_assignment_indices((slice(-1, 2, -1), 3, [1, 2]), (7, 8, 9)) |
| 1289 | ([slice(3, 7, 1), 3, array([1, 2])], [4, 2], [0], [0, 2]) |
| 1290 | |
| 1291 | >>> parse_assignment_indices((slice(0, 5), slice(3, None, 2)), (5, 4)) |
| 1292 | ([slice(0, 5, 1), slice(3, 4, 2)], [5, 1], [], [0, 1]) |
| 1293 |
no test coverage detected
searching dependent graphs…