MCPcopy
hub / github.com/dask/dask / __array_function__

Method __array_function__

dask/array/core.py:1730–1782  ·  view source on GitHub ↗
(self, func, types, args, kwargs)

Source from the content-addressed store, hash-verified

1728 return np.asarray(x, dtype=dtype)
1729
1730 def __array_function__(self, func, types, args, kwargs):
1731 import dask.array as module
1732
1733 def handle_nonmatching_names(func, args, kwargs):
1734 if func not in _HANDLED_FUNCTIONS:
1735 warnings.warn(
1736 f"The `{func.__module__}.{func.__name__}` function "
1737 "is not implemented by Dask array. "
1738 "You may want to use the da.map_blocks function "
1739 "or something similar to silence this warning. "
1740 "Your code may stop working in a future release.",
1741 FutureWarning,
1742 )
1743 # Need to convert to array object (e.g. numpy.ndarray or
1744 # cupy.ndarray) as needed, so we can call the NumPy function
1745 # again and it gets the chance to dispatch to the right
1746 # implementation.
1747 args, kwargs = compute(args, kwargs)
1748 return func(*args, **kwargs)
1749
1750 return _HANDLED_FUNCTIONS[func](*args, **kwargs)
1751
1752 # First, verify that all types are handled by Dask. Otherwise, return NotImplemented.
1753 if not all(
1754 # Accept our own superclasses as recommended by NEP-13
1755 # (https://numpy.org/neps/nep-0013-ufunc-overrides.html#subclass-hierarchies)
1756 issubclass(type(self), type_) or is_valid_chunk_type(type_)
1757 for type_ in types
1758 ):
1759 return NotImplemented
1760
1761 # Now try to find a matching function name. If that doesn't work, we may
1762 # be dealing with an alias or a function that's simply not in the Dask API.
1763 # Handle aliases via the _HANDLED_FUNCTIONS dict mapping, and warn otherwise.
1764 for submodule in func.__module__.split(".")[1:]:
1765 try:
1766 module = getattr(module, submodule)
1767 except AttributeError:
1768 return handle_nonmatching_names(func, args, kwargs)
1769
1770 if not hasattr(module, func.__name__):
1771 return handle_nonmatching_names(func, args, kwargs)
1772
1773 da_func = getattr(module, func.__name__)
1774 if da_func is func:
1775 return handle_nonmatching_names(func, args, kwargs)
1776
1777 # If ``like`` is contained in ``da_func``'s signature, add ``like=self``
1778 # to the kwargs dictionary.
1779 if has_keyword(da_func, "like"):
1780 kwargs["like"] = self
1781
1782 return da_func(*args, **kwargs)
1783
1784 @property
1785 def _elemwise(self):

Callers

nothing calls this directly

Calls 4

allFunction · 0.90
is_valid_chunk_typeFunction · 0.90
has_keywordFunction · 0.90
splitMethod · 0.80

Tested by

no test coverage detected