MCPcopy
hub / github.com/dask/dask / _array_like_safe

Function _array_like_safe

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

Source from the content-addressed store, hash-verified

440
441
442def _array_like_safe(np_func, da_func, a, like, **kwargs):
443 from dask.array import Array
444
445 if like is a and hasattr(a, "__array_function__"):
446 return a
447
448 if isinstance(like, Array):
449 return da_func(a, **kwargs)
450
451 if isinstance(a, Array) and is_cupy_type(a._meta):
452 a = a.compute(scheduler="sync")
453
454 if hasattr(like, "__array_function__"):
455 return np_func(a, like=like, **kwargs)
456
457 if type(like).__module__.startswith("scipy.sparse"):
458 # e.g. scipy.sparse.csr_matrix
459 kwargs.pop("order", None)
460 if np.isscalar(a):
461 a = np.array([[a]])
462 return type(like)(a, **kwargs)
463
464 # Unknown namespace with no __array_function__ support.
465 # Quietly disregard like= parameter.
466 # FIXME is there a use case for this?
467 return np_func(a, **kwargs)
468
469
470def array_safe(a, like, **kwargs):

Callers 3

array_safeFunction · 0.85
asarray_safeFunction · 0.85
asanyarray_safeFunction · 0.85

Calls 3

is_cupy_typeFunction · 0.90
popMethod · 0.80
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…