MCPcopy Index your code
hub / github.com/pydata/xarray / ArrayApiIndexingAdapter

Class ArrayApiIndexingAdapter

xarray/core/indexing.py:1761–1801  ·  view source on GitHub ↗

Wrap an array API array to use explicit indexing.

Source from the content-addressed store, hash-verified

1759
1760
1761class ArrayApiIndexingAdapter(IndexingAdapter):
1762 """Wrap an array API array to use explicit indexing."""
1763
1764 __slots__ = ("array",)
1765
1766 def __init__(self, array):
1767 if not hasattr(array, "__array_namespace__"):
1768 raise TypeError(
1769 "ArrayApiIndexingAdapter must wrap an object that "
1770 "implements the __array_namespace__ protocol"
1771 )
1772 self.array = array
1773
1774 def _oindex_get(self, indexer: OuterIndexer):
1775 # manual orthogonal indexing (implemented like DaskIndexingAdapter)
1776 key = indexer.tuple
1777 value = self.array
1778 for axis, subkey in reversed(list(enumerate(key))):
1779 value = value[(slice(None),) * axis + (subkey, Ellipsis)]
1780 return value
1781
1782 def _vindex_get(self, indexer: VectorizedIndexer):
1783 raise TypeError("Vectorized indexing is not supported")
1784
1785 def __getitem__(self, indexer: ExplicitIndexer):
1786 self._check_and_raise_if_non_basic_indexer(indexer)
1787 return self.array[indexer.tuple]
1788
1789 def _oindex_set(self, indexer: OuterIndexer, value: Any) -> None:
1790 self.array[indexer.tuple] = value
1791
1792 def _vindex_set(self, indexer: VectorizedIndexer, value: Any) -> None:
1793 raise TypeError("Vectorized indexing is not supported")
1794
1795 def __setitem__(self, indexer: ExplicitIndexer, value: Any) -> None:
1796 self._check_and_raise_if_non_basic_indexer(indexer)
1797 self.array[indexer.tuple] = value
1798
1799 def transpose(self, order):
1800 xp = self.array.__array_namespace__()
1801 return xp.permute_dims(self.array, order)
1802
1803
1804def _apply_vectorized_indexer_dask_wrapper(indices, coord):

Callers 1

as_indexableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…