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

Function _outer_to_vectorized_indexer

xarray/core/indexing.py:1027–1061  ·  view source on GitHub ↗

Convert an OuterIndexer into a vectorized indexer. Parameters ---------- indexer : Outer/Basic Indexer An indexer to convert. shape : tuple Shape of the array subject to the indexing. Returns ------- VectorizedIndexer Tuple suitable for use to in

(
    indexer: BasicIndexer | OuterIndexer, shape: _Shape
)

Source from the content-addressed store, hash-verified

1025
1026
1027def _outer_to_vectorized_indexer(
1028 indexer: BasicIndexer | OuterIndexer, shape: _Shape
1029) -> VectorizedIndexer:
1030 """Convert an OuterIndexer into a vectorized indexer.
1031
1032 Parameters
1033 ----------
1034 indexer : Outer/Basic Indexer
1035 An indexer to convert.
1036 shape : tuple
1037 Shape of the array subject to the indexing.
1038
1039 Returns
1040 -------
1041 VectorizedIndexer
1042 Tuple suitable for use to index a NumPy array with vectorized indexing.
1043 Each element is an array: broadcasting them together gives the shape
1044 of the result.
1045 """
1046 key = indexer.tuple
1047
1048 n_dim = len([k for k in key if not isinstance(k, integer_types)])
1049 i_dim = 0
1050 new_key = []
1051 for k, size in zip(key, shape, strict=True):
1052 if isinstance(k, integer_types):
1053 new_key.append(np.array(k).reshape((1,) * n_dim))
1054 else: # np.ndarray or slice
1055 if isinstance(k, slice):
1056 k = np.arange(*k.indices(size))
1057 assert k.dtype.kind in {"i", "u"}
1058 new_shape = [(1,) * i_dim + (k.size,) + (1,) * (n_dim - i_dim - 1)]
1059 new_key.append(k.reshape(*new_shape))
1060 i_dim += 1
1061 return VectorizedIndexer(tuple(new_key))
1062
1063
1064def _outer_to_numpy_indexer(indexer: BasicIndexer | OuterIndexer, shape: _Shape):

Callers 4

__init__Method · 0.85
_outer_to_numpy_indexerFunction · 0.85
_combine_indexersFunction · 0.85
create_maskFunction · 0.85

Calls 2

VectorizedIndexerClass · 0.90
arangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…