(np_func, da_func, a, like, **kwargs)
| 458 | |
| 459 | |
| 460 | def _array_like_safe(np_func, da_func, a, like, **kwargs): |
| 461 | from dask.array import Array |
| 462 | |
| 463 | if like is a and hasattr(a, "__array_function__"): |
| 464 | return a |
| 465 | |
| 466 | if isinstance(like, Array): |
| 467 | return da_func(a, **kwargs) |
| 468 | |
| 469 | if isinstance(a, Array) and is_cupy_type(a._meta): |
| 470 | a = a.compute(scheduler="sync") |
| 471 | |
| 472 | if hasattr(like, "__array_function__"): |
| 473 | return np_func(a, like=like, **kwargs) |
| 474 | |
| 475 | if _is_sparse_container(like): |
| 476 | kwargs.pop("order", None) |
| 477 | if np.isscalar(a): |
| 478 | a = np.array([[a]]) |
| 479 | return type(like)(a, **kwargs) |
| 480 | |
| 481 | # Unknown namespace with no __array_function__ support. |
| 482 | # Quietly disregard like= parameter. |
| 483 | # FIXME is there a use case for this? |
| 484 | return np_func(a, **kwargs) |
| 485 | |
| 486 | |
| 487 | def array_safe(a, like, **kwargs): |
no test coverage detected