8000 ENH: correct identity for logaddexp2 ufunc: -inf by eriknw · Pull Request #16102 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: correct identity for logaddexp2 ufunc: -inf #16102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/release/upcoming_changes/16102.improvement.rst
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion numpy/core/code_generators/generate_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def english_upper(s):
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'})
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ def test_nan(self):
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):
Expand Down
0