summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Welch <erik.n.welch@gmail.com>2020-05-13 11:21:55 -0500
committerGitHub <noreply@github.com>2020-05-13 11:21:55 -0500
commit5f7114ca823736e3f55176cf6a3fbeb77efe0279 (patch)
treea373a49487c7f8e3eb8d857fe40a7af704ce5ec6
parent77410e26dd94bdd07df096be06ee9aa7d5738ce6 (diff)
downloadnumpy-5f7114ca823736e3f55176cf6a3fbeb77efe0279.tar.gz
ENH: correct identity for logaddexp2 ufunc: -inf (gh-16102)
The lack of identity for `logaddexp2` was first identitifed in #4599. The implementation in #8955 added -inf as identity for `logaddexp`, but missed adding it for `logaddexp2`. Co-Authored-By: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
-rw-r--r--doc/release/upcoming_changes/16102.improvement.rst4
-rw-r--r--numpy/core/code_generators/generate_umath.py2
-rw-r--r--numpy/core/tests/test_umath.py6
3 files changed, 11 insertions, 1 deletions
diff --git a/doc/release/upcoming_changes/16102.improvement.rst b/doc/release/upcoming_changes/16102.improvement.rst
new file mode 100644
index 000000000..cf81397f0
--- /dev/null
+++ b/doc/release/upcoming_changes/16102.improvement.rst
@@ -0,0 +1,4 @@
+``np.logaddexp2.identity`` changed to ``-inf``
+----------------------------------------------
+The ufunc `~numpy.logaddexp2` now has an identity of ``-inf``, allowing it to
+be called on empty sequences. This matches the identity of `~numpy.logaddexp`.
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 52ae3cdd7..202912c5f 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -531,7 +531,7 @@ defdict = {
TD(flts, f="logaddexp", astype={'e':'f'})
),
'logaddexp2':
- Ufunc(2, 1, None,
+ Ufunc(2, 1, MinusInfinity,
docstrings.get('numpy.core.umath.logaddexp2'),
None,
TD(flts, f="logaddexp2", astype={'e':'f'})
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 10c652ad4..e7965c0ca 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -639,6 +639,12 @@ class TestLogAddExp2(_FilterInvalids):
assert_(np.isnan(np.logaddexp2(0, np.nan)))
assert_(np.isnan(np.logaddexp2(np.nan, np.nan)))
+ def test_reduce(self):
+ assert_equal(np.logaddexp2.identity, -np.inf)
+ assert_equal(np.logaddexp2.reduce([]), -np.inf)
+ assert_equal(np.logaddexp2.reduce([-np.inf]), -np.inf)
+ assert_equal(np.logaddexp2.reduce([-np.inf, 0]), 0)
+
class TestLog:
def test_log_values(self):