Apply a generalized ufunc or similar python function to arrays. ``signature`` determines if the function consumes or produces core dimensions. The remaining dimensions in given input arrays (``*args``) are considered loop dimensions and are required to broadcast naturally again
(
func,
signature,
*args,
axes=None,
axis=None,
keepdims=False,
output_dtypes=None,
output_sizes=None,
vectorize=None,
allow_rechunk=False,
meta=None,
**kwargs,
)
| 170 | |
| 171 | |
| 172 | def apply_gufunc( |
| 173 | func, |
| 174 | signature, |
| 175 | *args, |
| 176 | axes=None, |
| 177 | axis=None, |
| 178 | keepdims=False, |
| 179 | output_dtypes=None, |
| 180 | output_sizes=None, |
| 181 | vectorize=None, |
| 182 | allow_rechunk=False, |
| 183 | meta=None, |
| 184 | **kwargs, |
| 185 | ): |
| 186 | """ |
| 187 | Apply a generalized ufunc or similar python function to arrays. |
| 188 | |
| 189 | ``signature`` determines if the function consumes or produces core |
| 190 | dimensions. The remaining dimensions in given input arrays (``*args``) |
| 191 | are considered loop dimensions and are required to broadcast |
| 192 | naturally against each other. |
| 193 | |
| 194 | In other terms, this function is like ``np.vectorize``, but for |
| 195 | the blocks of dask arrays. If the function itself shall also |
| 196 | be vectorized use ``vectorize=True`` for convenience. |
| 197 | |
| 198 | Parameters |
| 199 | ---------- |
| 200 | func : callable |
| 201 | Function to call like ``func(*args, **kwargs)`` on input arrays |
| 202 | (``*args``) that returns an array or tuple of arrays. If multiple |
| 203 | arguments with non-matching dimensions are supplied, this function is |
| 204 | expected to vectorize (broadcast) over axes of positional arguments in |
| 205 | the style of NumPy universal functions [1]_ (if this is not the case, |
| 206 | set ``vectorize=True``). If this function returns multiple outputs, |
| 207 | ``output_core_dims`` has to be set as well. |
| 208 | signature: string |
| 209 | Specifies what core dimensions are consumed and produced by ``func``. |
| 210 | According to the specification of numpy.gufunc signature [2]_ |
| 211 | *args : numeric |
| 212 | Input arrays or scalars to the callable function. |
| 213 | axes: List of tuples, optional, keyword only |
| 214 | A list of tuples with indices of axes a generalized ufunc should operate on. |
| 215 | For instance, for a signature of ``"(i,j),(j,k)->(i,k)"`` appropriate for |
| 216 | matrix multiplication, the base elements are two-dimensional matrices |
| 217 | and these are taken to be stored in the two last axes of each argument. The |
| 218 | corresponding axes keyword would be ``[(-2, -1), (-2, -1), (-2, -1)]``. |
| 219 | For simplicity, for generalized ufuncs that operate on 1-dimensional arrays |
| 220 | (vectors), a single integer is accepted instead of a single-element tuple, |
| 221 | and for generalized ufuncs for which all outputs are scalars, the output |
| 222 | tuples can be omitted. |
| 223 | axis: int, optional, keyword only |
| 224 | A single axis over which a generalized ufunc should operate. This is a short-cut |
| 225 | for ufuncs that operate over a single, shared core dimension, equivalent to passing |
| 226 | in axes with entries of (axis,) for each single-core-dimension argument and ``()`` for |
| 227 | all others. For instance, for a signature ``"(i),(i)->()"``, it is equivalent to passing |
| 228 | in ``axes=[(axis,), (axis,), ()]``. |
| 229 | keepdims: bool, optional, keyword only |
no test coverage detected
searching dependent graphs…