szha commented on a change in pull request #15857: [Numpy] Added operator
logaddexp; added support for zero-size tensor in BinaryBroadcastBackwardUseIn
URL: https://github.com/apache/incubator-mxnet/pull/15857#discussion_r331834348
##########
File path: python/mxnet/ndarray/numpy/_op.py
##########
@@ -2537,3 +2537,51 @@ def ravel(x, order='C'):
return _npi.reshape(x, -1)
else:
raise TypeError('type {} not supported'.format(str(type(x))))
+
+
+@set_module('mxnet.ndarray.numpy')
+def logaddexp(x1, x2, out=None):
+ """Logarithm of the sum of exponentiations of the inputs.
+ logaddexp(x1, x2, out=None)
+ Calculates ``log(exp(x1) + exp(x2))``. This function is useful in
+ statistics where the calculated probabilities of events may be so small
+ as to exceed the range of normal floating point numbers. In such cases
+ the logarithm of the calculated probability is stored. This function
+ allows adding probabilities stored in such a fashion.
+ Parameters
+ ----------
+ x1, x2 : ndarray or scalar
+ Input values.
+ out : ndarray, None, or tuple of ndarray and None, optional
+ A location into which the result is stored. If provided, it must have
+ a shape and dtype as the expected output. If not provided or `None`,
+ a freshly-allocated array is returned.
+ Returns
+ -------
+ result : ndarray or scalar
+ Logarithm of ``exp(x1) + exp(x2)``.
+ This is a scalar if both `x1` and `x2` are scalars.
+ See Also
+ --------
+ logaddexp2: Logarithm of the sum of exponentiations of inputs in base 2.
+ Notes
+ -----
+ This function differs from the original `numpy.logaddexp
+
<https://docs.scipy.org/doc/numpy/reference/generated/numpy.logaddexp.html>`_ in
+ the following aspects:
+ - Input type does not support Python native iterables(list, tuple, ...).
Only ndarray is supported.
+ - ``out`` param: cannot perform auto broadcasting. ``out`` ndarray's shape
must be the same as the expected output.
+ - ``out`` param: cannot perform auto type cast. ``out`` ndarray's dtype
must be the same as the expected output.
+ - ``out`` param does not support scalar input case.
+ Examples
Review comment:
same as above
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services