(condlist, choicelist, default=0)
| 2278 | |
| 2279 | @derived_from(np) |
| 2280 | def select(condlist, choicelist, default=0): |
| 2281 | # Making the same checks that np.select |
| 2282 | # Check the size of condlist and choicelist are the same, or abort. |
| 2283 | if len(condlist) != len(choicelist): |
| 2284 | raise ValueError("list of cases must be same length as list of conditions") |
| 2285 | |
| 2286 | if len(condlist) == 0: |
| 2287 | raise ValueError("select with an empty condition list is not possible") |
| 2288 | |
| 2289 | choicelist = [asarray(choice) for choice in choicelist] |
| 2290 | |
| 2291 | try: |
| 2292 | intermediate_dtype = result_type(*choicelist) |
| 2293 | except TypeError as e: |
| 2294 | msg = "Choicelist elements do not have a common dtype." |
| 2295 | raise TypeError(msg) from e |
| 2296 | |
| 2297 | blockwise_shape = tuple(range(choicelist[0].ndim)) |
| 2298 | |
| 2299 | condargs = [arg for elem in condlist for arg in (elem, blockwise_shape)] |
| 2300 | choiceargs = [arg for elem in choicelist for arg in (elem, blockwise_shape)] |
| 2301 | |
| 2302 | return blockwise( |
| 2303 | _select, |
| 2304 | blockwise_shape, |
| 2305 | *condargs, |
| 2306 | *choiceargs, |
| 2307 | dtype=intermediate_dtype, |
| 2308 | name="select", |
| 2309 | default=default, |
| 2310 | ) |
| 2311 | |
| 2312 | |
| 2313 | def _partition(total: int, divisor: int) -> tuple[tuple[int, ...], tuple[int, ...]]: |
nothing calls this directly
no test coverage detected
searching dependent graphs…