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

Function elemwise

dask/array/core.py:5088–5208  ·  view source on GitHub ↗

Apply an elementwise ufunc-like function blockwise across arguments. Like numpy ufuncs, broadcasting rules are respected. Parameters ---------- op : callable The function to apply. Should be numpy ufunc-like in the parameters that it accepts. *args : Any

(op, *args, out=None, where=True, dtype=None, name=None, **kwargs)

Source from the content-addressed store, hash-verified

5086
5087
5088def elemwise(op, *args, out=None, where=True, dtype=None, name=None, **kwargs):
5089 """Apply an elementwise ufunc-like function blockwise across arguments.
5090
5091 Like numpy ufuncs, broadcasting rules are respected.
5092
5093 Parameters
5094 ----------
5095 op : callable
5096 The function to apply. Should be numpy ufunc-like in the parameters
5097 that it accepts.
5098 *args : Any
5099 Arguments to pass to `op`. Non-dask array-like objects are first
5100 converted to dask arrays, then all arrays are broadcast together before
5101 applying the function blockwise across all arguments. Any scalar
5102 arguments are passed as-is following normal numpy ufunc behavior.
5103 out : dask array, optional
5104 If out is a dask.array then this overwrites the contents of that array
5105 with the result.
5106 where : array_like, optional
5107 An optional boolean mask marking locations where the ufunc should be
5108 applied. Can be a scalar, dask array, or any other array-like object.
5109 Mirrors the ``where`` argument to numpy ufuncs, see e.g. ``numpy.add``
5110 for more information.
5111 dtype : dtype, optional
5112 If provided, overrides the output array dtype.
5113 name : str, optional
5114 A unique key name to use when building the backing dask graph. If not
5115 provided, one will be automatically generated based on the input
5116 arguments.
5117
5118 Examples
5119 --------
5120 >>> elemwise(add, x, y) # doctest: +SKIP
5121 >>> elemwise(sin, x) # doctest: +SKIP
5122 >>> elemwise(sin, x, out=dask_array) # doctest: +SKIP
5123
5124 See Also
5125 --------
5126 blockwise
5127 """
5128 if kwargs:
5129 raise TypeError(
5130 f"{op.__name__} does not take the following keyword arguments "
5131 f"{sorted(kwargs)}"
5132 )
5133
5134 out = _elemwise_normalize_out(out)
5135 where = _elemwise_normalize_where(where)
5136 args = [np.asarray(a) if isinstance(a, (list, tuple)) else a for a in args]
5137
5138 shapes = []
5139 for arg in args:
5140 shape = getattr(arg, "shape", ())
5141 if any(is_dask_collection(x) for x in shape):
5142 # Want to exclude Delayed shapes and dd.Scalar
5143 shape = ()
5144 shapes.append(shape)
5145 if isinstance(where, Array):

Callers 15

whereFunction · 0.90
isnullFunction · 0.90
iscloseFunction · 0.90
chooseFunction · 0.90
whereFunction · 0.90
frexpFunction · 0.90
modfFunction · 0.90
__array_ufunc__Method · 0.70
__abs__Method · 0.70
__add__Method · 0.70
__radd__Method · 0.70

Calls 14

anyFunction · 0.90
is_dask_collectionFunction · 0.90
maxFunction · 0.90
funcnameFunction · 0.90
blockwiseFunction · 0.90
_elemwise_normalize_outFunction · 0.85
broadcast_shapesFunction · 0.85
is_scalar_for_elemwiseFunction · 0.85
apply_infer_dtypeFunction · 0.85
handle_outFunction · 0.70
tokenizeFunction · 0.50

Tested by

no test coverage detected