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