MCPcopy
hub / github.com/dask/dask / _vindex

Method _vindex

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

Source from the content-addressed store, hash-verified

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