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)
| 468 | |
| 469 | |
| 470 | def array_safe(a, like, **kwargs): |
| 471 | """ |
| 472 | If `a` is `dask.array`, return `dask.array.asarray(a, **kwargs)`, |
| 473 | otherwise return `np.asarray(a, like=like, **kwargs)`, dispatching |
| 474 | the call to the library that implements the like array. Note that |
| 475 | when `a` is a `dask.Array` backed by `cupy.ndarray` but `like` |
| 476 | isn't, this function will call `a.compute(scheduler="sync")` |
| 477 | before `np.array`, as downstream libraries are unlikely to know how |
| 478 | to convert a `dask.Array` and CuPy doesn't implement `__array__` to |
| 479 | prevent implicit copies to host. |
| 480 | """ |
| 481 | from dask.array.routines import array |
| 482 | |
| 483 | return _array_like_safe(np.array, array, a, like, **kwargs) |
| 484 | |
| 485 | |
| 486 | def asarray_safe(a, like, **kwargs): |
no test coverage detected
searching dependent graphs…