| 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): |