def reduce_ufunc(*args, **kwargs):
"""
Streaming reduction generator function from a binary NumPy ufunc. Essentially the
function equivalent to `ireduce_ufunc`.
``ufunc`` must be a NumPy binary Ufunc (i.e. it takes two arguments). Moreover,
for performance reasons, ufunc must have the same return types as input types.
This precludes the use of ``numpy.greater``, for example.
Note that performance is much better for the default ``axis = -1``. In such a case,
reduction operations can occur in-place. This also allows to operate in constant-memory.
Parameters
----------
arrays : iterable
Arrays to be reduced.
ufunc : numpy.ufunc
Binary universal function.
axis : int or None, optional
Reduction axis. Default is to reduce the arrays in the stream as if
they had been stacked along a new axis, then reduce along this new axis.
If None, arrays are flattened before reduction. If `axis` is an int larger that
the number of dimensions in the arrays of the stream, arrays are reduced
along the new axis. Note that not all of NumPy Ufuncs support
``axis = None``, e.g. ``numpy.subtract``.
dtype : numpy.dtype or None, optional
Overrides the dtype of the calculation and output arrays.
ignore_nan : bool, optional
If True and ufunc has an identity value (e.g. ``numpy.add.identity`` is 0), then NaNs
are replaced with this identity. An error is raised if ``ufunc`` has no identity (e.g. ``numpy.maximum.identity`` is ``None``).
kwargs
Keyword arguments are passed to ``ufunc``. Note that some valid ufunc keyword arguments
(e.g. ``keepdims``) are not valid for all streaming functions. Note that
contrary to NumPy v. 1.10+, ``casting = 'unsafe`` is the default in npstreams.
Yields
------
reduced : ndarray or scalar
Raises
------
TypeError : if ``ufunc`` is not NumPy ufunc.
ValueError : if ``ignore_nan`` is True but ``ufunc`` has no identity
ValueError: if ``ufunc`` is not a binary ufunc
ValueError: if ``ufunc`` does not have the same input type as output type
"""
return last(ireduce_ufunc(*args, **kwargs))
评论列表
文章目录