summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):