MCPcopy
hub / github.com/dask/dask / array_safe

Function array_safe

dask/array/utils.py:470–483  ·  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

468
469
470def 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
486def 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…