MCPcopy Create free account
hub / github.com/dask/dask / _vindex

Method _vindex

dask/array/core.py:2042–2071  ·  view source on GitHub ↗
(self, key)

Source from the content-addressed store, hash-verified

2040 return Array(graph, out, chunks, meta=meta)
2041
2042 def _vindex(self, key):
2043 if not isinstance(key, tuple):
2044 key = (key,)
2045 if any(k is None for k in key):
2046 raise IndexError(
2047 f"vindex does not support indexing with None (np.newaxis), got {key}"
2048 )
2049 if all(isinstance(k, slice) for k in key):
2050 if all(
2051 k.indices(d) == slice(0, d).indices(d) for k, d in zip(key, self.shape)
2052 ):
2053 return self
2054 raise IndexError(
2055 "vindex requires at least one non-slice to vectorize over "
2056 "when the slices are not over the entire array (i.e, x[:]). "
2057 f"Use normal slicing instead when only using slices. Got: {key}"
2058 )
2059 elif any(is_dask_collection(k) for k in key):
2060 if math.prod(self.numblocks) == 1 and len(key) == 1 and self.ndim == 1:
2061 idxr = key[0]
2062 # we can broadcast in this case
2063 return idxr.map_blocks(
2064 _numpy_vindex, self, dtype=self.dtype, chunks=idxr.chunks
2065 )
2066 else:
2067 raise IndexError(
2068 "vindex does not support indexing with dask objects. Call compute "
2069 f"on the indexer first to get an evalurated array. Got: {key}"
2070 )
2071 return _vindex(self, *key)
2072
2073 @property
2074 def vindex(self):

Callers 1

test_vindexFunction · 0.80

Calls 6

anyFunction · 0.90
allFunction · 0.90
is_dask_collectionFunction · 0.90
_vindexFunction · 0.85
prodMethod · 0.45
map_blocksMethod · 0.45

Tested by 1

test_vindexFunction · 0.64