MCPcopy Create free account
hub / github.com/dask/dask / array_safe

Function array_safe

dask/array/utils.py:472–485  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 8

solve_triangularFunction · 0.90
_choleskyFunction · 0.90
chunk_minFunction · 0.90
chunk_maxFunction · 0.90
percentileFunction · 0.90
merge_percentilesFunction · 0.90
bincountFunction · 0.90
searchsortedFunction · 0.90

Calls 1

_array_like_safeFunction · 0.85

Tested by

no test coverage detected