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