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

Method __array_ufunc__

dask/array/core.py:1565–1602  ·  view source on GitHub ↗
(self, numpy_ufunc, method, *inputs, **kwargs)

Source from the content-addressed store, hash-verified

1563 return int(sum(self.chunks[0]))
1564
1565 def __array_ufunc__(self, numpy_ufunc, method, *inputs, **kwargs):
1566 out = kwargs.get("out", ())
1567 for x in inputs + out:
1568 if _should_delegate(self, x):
1569 return NotImplemented
1570
1571 if method == "__call__":
1572 if numpy_ufunc is np.matmul:
1573 from dask.array.routines import matmul
1574
1575 # special case until apply_gufunc handles optional dimensions
1576 return matmul(*inputs, **kwargs)
1577 if numpy_ufunc.signature is not None:
1578 from dask.array.gufunc import apply_gufunc
1579
1580 return apply_gufunc(
1581 numpy_ufunc, numpy_ufunc.signature, *inputs, **kwargs
1582 )
1583 if numpy_ufunc.nout > 1:
1584 from dask.array import ufunc
1585
1586 try:
1587 da_ufunc = getattr(ufunc, numpy_ufunc.__name__)
1588 except AttributeError:
1589 return NotImplemented
1590 return da_ufunc(*inputs, **kwargs)
1591 else:
1592 return elemwise(numpy_ufunc, *inputs, **kwargs)
1593 elif method == "outer":
1594 from dask.array import ufunc
1595
1596 try:
1597 da_ufunc = getattr(ufunc, numpy_ufunc.__name__)
1598 except AttributeError:
1599 return NotImplemented
1600 return da_ufunc.outer(*inputs, **kwargs)
1601 else:
1602 return NotImplemented
1603
1604 def __repr__(self):
1605 """

Callers

nothing calls this directly

Calls 6

matmulFunction · 0.90
apply_gufuncFunction · 0.90
_should_delegateFunction · 0.85
elemwiseFunction · 0.70
getMethod · 0.45
outerMethod · 0.45

Tested by

no test coverage detected