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

Function select

dask/array/routines.py:2232–2262  ·  view source on GitHub ↗
(condlist, choicelist, default=0)

Source from the content-addressed store, hash-verified

2230
2231@derived_from(np)
2232def select(condlist, choicelist, default=0):
2233 # Making the same checks that np.select
2234 # Check the size of condlist and choicelist are the same, or abort.
2235 if len(condlist) != len(choicelist):
2236 raise ValueError("list of cases must be same length as list of conditions")
2237
2238 if len(condlist) == 0:
2239 raise ValueError("select with an empty condition list is not possible")
2240
2241 choicelist = [asarray(choice) for choice in choicelist]
2242
2243 try:
2244 intermediate_dtype = result_type(*choicelist)
2245 except TypeError as e:
2246 msg = "Choicelist elements do not have a common dtype."
2247 raise TypeError(msg) from e
2248
2249 blockwise_shape = tuple(range(choicelist[0].ndim))
2250
2251 condargs = [arg for elem in condlist for arg in (elem, blockwise_shape)]
2252 choiceargs = [arg for elem in choicelist for arg in (elem, blockwise_shape)]
2253
2254 return blockwise(
2255 _select,
2256 blockwise_shape,
2257 *condargs,
2258 *choiceargs,
2259 dtype=intermediate_dtype,
2260 name="select",
2261 default=default,
2262 )
2263
2264
2265def _partition(total: int, divisor: int) -> tuple[tuple[int, ...], tuple[int, ...]]:

Callers

nothing calls this directly

Calls 3

asarrayFunction · 0.90
result_typeFunction · 0.85
blockwiseFunction · 0.70

Tested by

no test coverage detected