MCPcopy Create free account
hub / github.com/pydata/xarray / NumpyVIndexAdapter

Class NumpyVIndexAdapter

xarray/core/nputils.py:158–175  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

156
157
158class 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
178def _create_method(name, npmodule=np) -> Callable:

Callers 3

_vindex_getMethod · 0.90
_vindex_setMethod · 0.90
test_vindexFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_vindexFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…