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

Method __array_ufunc__

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

Source from the content-addressed store, hash-verified

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

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