If `a` is `dask.array`, return `dask.array.asarray(a, **kwargs)`, otherwise return `np.asarray(a, like=like, **kwargs)`, dispatching the call to the library that implements the like array. Note that when `a` is a `dask.Array` backed by `cupy.ndarray` but `like` isn't, this funct
(a, like, **kwargs)
| 485 | |
| 486 | |
| 487 | def array_safe(a, like, **kwargs): |
| 488 | """ |
| 489 | If `a` is `dask.array`, return `dask.array.asarray(a, **kwargs)`, |
| 490 | otherwise return `np.asarray(a, like=like, **kwargs)`, dispatching |
| 491 | the call to the library that implements the like array. Note that |
| 492 | when `a` is a `dask.Array` backed by `cupy.ndarray` but `like` |
| 493 | isn't, this function will call `a.compute(scheduler="sync")` |
| 494 | before `np.array`, as downstream libraries are unlikely to know how |
| 495 | to convert a `dask.Array` and CuPy doesn't implement `__array__` to |
| 496 | prevent implicit copies to host. |
| 497 | """ |
| 498 | from dask.array.routines import array |
| 499 | |
| 500 | return _array_like_safe(np.array, array, a, like, **kwargs) |
| 501 | |
| 502 | |
| 503 | def asarray_safe(a, like, **kwargs): |
no test coverage detected