(np_func, da_func, a, like, **kwargs)
| 442 | |
| 443 | |
| 444 | def _array_like_safe(np_func, da_func, a, like, **kwargs): |
| 445 | from dask.array import Array |
| 446 | |
| 447 | if like is a and hasattr(a, "__array_function__"): |
| 448 | return a |
| 449 | |
| 450 | if isinstance(like, Array): |
| 451 | return da_func(a, **kwargs) |
| 452 | |
| 453 | if isinstance(a, Array) and is_cupy_type(a._meta): |
| 454 | a = a.compute(scheduler="sync") |
| 455 | |
| 456 | if hasattr(like, "__array_function__"): |
| 457 | return np_func(a, like=like, **kwargs) |
| 458 | |
| 459 | if type(like).__module__.startswith("scipy.sparse"): |
| 460 | # e.g. scipy.sparse.csr_matrix |
| 461 | kwargs.pop("order", None) |
| 462 | if np.isscalar(a): |
| 463 | a = np.array([a]) |
| 464 | return type(like)(a, **kwargs) |
| 465 | |
| 466 | # Unknown namespace with no __array_function__ support. |
| 467 | # Quietly disregard like= parameter. |
| 468 | # FIXME is there a use case for this? |
| 469 | return np_func(a, **kwargs) |
| 470 | |
| 471 | |
| 472 | def array_safe(a, like, **kwargs): |
no test coverage detected