Object that implements indexing like vindex on an np.ndarray. This is a pure Python implementation of (some of) the logic in this NumPy proposal: https://github.com/numpy/numpy/pull/6256
| 156 | |
| 157 | |
| 158 | class NumpyVIndexAdapter: |
| 159 | """Object that implements indexing like vindex on an np.ndarray. |
| 160 | |
| 161 | This is a pure Python implementation of (some of) the logic in this NumPy |
| 162 | proposal: https://github.com/numpy/numpy/pull/6256 |
| 163 | """ |
| 164 | |
| 165 | def __init__(self, array): |
| 166 | self._array = array |
| 167 | |
| 168 | def __getitem__(self, key): |
| 169 | mixed_positions, vindex_positions = _advanced_indexer_subspaces(key) |
| 170 | return np.moveaxis(self._array[key], mixed_positions, vindex_positions) |
| 171 | |
| 172 | def __setitem__(self, key, value): |
| 173 | """Value must have dimensionality matching the key.""" |
| 174 | mixed_positions, vindex_positions = _advanced_indexer_subspaces(key) |
| 175 | self._array[key] = np.moveaxis(value, vindex_positions, mixed_positions) |
| 176 | |
| 177 | |
| 178 | def _create_method(name, npmodule=np) -> Callable: |
no outgoing calls
searching dependent graphs…