MCPcopy
hub / github.com/dask/dask / __array_ufunc__

Method __array_ufunc__

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

Source from the content-addressed store, hash-verified

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

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