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

Function array_safe

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

485
486
487def 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
503def 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