Like inverse_permutation, but also handles slices. Parameters ---------- positions : list of ndarray or slice If slice objects, all are assumed to be slices. Returns ------- np.ndarray of indices or None, if no permutation is necessary.
(positions, N: int | None = None)
| 158 | |
| 159 | |
| 160 | def _inverse_permutation_indices(positions, N: int | None = None) -> np.ndarray | None: |
| 161 | """Like inverse_permutation, but also handles slices. |
| 162 | |
| 163 | Parameters |
| 164 | ---------- |
| 165 | positions : list of ndarray or slice |
| 166 | If slice objects, all are assumed to be slices. |
| 167 | |
| 168 | Returns |
| 169 | ------- |
| 170 | np.ndarray of indices or None, if no permutation is necessary. |
| 171 | """ |
| 172 | if not positions: |
| 173 | return None |
| 174 | |
| 175 | if isinstance(positions[0], slice): |
| 176 | positions = _consolidate_slices(positions) |
| 177 | if positions == [slice(None)] or positions == [slice(0, None)]: |
| 178 | return None |
| 179 | positions = [np.arange(sl.start, sl.stop, sl.step) for sl in positions] |
| 180 | newpositions = nputils.inverse_permutation( |
| 181 | np.concatenate(tuple(p for p in positions if len(p) > 0)), N |
| 182 | ) |
| 183 | return newpositions[newpositions != -1] |
| 184 | |
| 185 | |
| 186 | class _DummyGroup(Generic[T_Xarray]): |
no test coverage detected
searching dependent graphs…