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

Function _array_like_safe

dask/array/utils.py:460–484  ·  view source on GitHub ↗
(np_func, da_func, a, like, **kwargs)

Source from the content-addressed store, hash-verified

458
459
460def _array_like_safe(np_func, da_func, a, like, **kwargs):
461 from dask.array import Array
462
463 if like is a and hasattr(a, "__array_function__"):
464 return a
465
466 if isinstance(like, Array):
467 return da_func(a, **kwargs)
468
469 if isinstance(a, Array) and is_cupy_type(a._meta):
470 a = a.compute(scheduler="sync")
471
472 if hasattr(like, "__array_function__"):
473 return np_func(a, like=like, **kwargs)
474
475 if _is_sparse_container(like):
476 kwargs.pop("order", None)
477 if np.isscalar(a):
478 a = np.array([[a]])
479 return type(like)(a, **kwargs)
480
481 # Unknown namespace with no __array_function__ support.
482 # Quietly disregard like= parameter.
483 # FIXME is there a use case for this?
484 return np_func(a, **kwargs)
485
486
487def array_safe(a, like, **kwargs):

Callers 3

array_safeFunction · 0.85
asarray_safeFunction · 0.85
asanyarray_safeFunction · 0.85

Calls 4

is_cupy_typeFunction · 0.90
_is_sparse_containerFunction · 0.85
popMethod · 0.80
computeMethod · 0.45

Tested by

no test coverage detected