You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should logaddexp and logaddexp2 have identities defined for reduce?
In [1]: x = np.array([-1,-1,-1], dtype=float)
In [2]: np.logaddexp2.reduce(x)
Out[2]: 0.58496250072115619
In [3]: np.logaddexp2.reduce(x[:2]) # matches np.logaddexp2(*x[:2])
Out[3]: 0.0
In [4]: np.logaddexp2.reduce(x[:1])
Out[4]: -1.0
In [5]: np.logaddexp2.reduce(x[:0])
ValueError: zero-size array to reduction operation logaddexp2 which has no identity
I was expecting -inf when reducing an empty array.
@juliantaylor Note that np.logaddexp([1,2,3], [2,3,4]) works just fine. So integers are only invalid when np.logaddexp.reduce is called. I looked at generate_umath.py, but I couldn't figure out how its definition:
Usually yes, but in this case there's already a patch awaiting review at #8955. That doesn't mean you can't submit a different patch, if you think you can do it better...
Activity
chebee7i commentedon Apr 8, 2014
Also,
reducedoesn't seem to work on integer arrays. Should it automatically cast to float?roger- commentedon Nov 26, 2014
Just noticed this myself, it really should.
juliantaylor commentedon Nov 26, 2014
automatic cast should be easily fixable by adding something similar to true_divide to logaddexp in generate_umath.py
the identity is not so easy as currently numpy only supports 0 or 1 as identities.
chebee7i commentedon Nov 26, 2014
@juliantaylor Note that
np.logaddexp([1,2,3], [2,3,4])works just fine. So integers are only invalid whennp.logaddexp.reduceis called. I looked atgenerate_umath.py, but I couldn't figure out how its definition:could change how
reducebehaved (besides explicitly making ints a valid input type). Though I admit, I know very little about the NumPy internals.chebee7i commentedon Nov 26, 2014
This reduction issue also affects
hypot,atan2, etc.souravsingh commentedon Nov 20, 2016
I would like to work on the issue. How do I start?
elllot commentedon May 4, 2017
Is this still open for someone to pick up? I'm new to this and wasn't sure if "Open" status means open for anyone... Thanks.
eric-wieser commentedon May 4, 2017
Usually yes, but in this case there's already a patch awaiting review at #8955. That doesn't mean you can't submit a different patch, if you think you can do it better...
arogozhnikov commentedon Aug 6, 2018
Just faced this.
Very confusing behavior. Is there any progress with this issue?
ron819 commentedon Nov 5, 2018
If someone can solve this please do also facing it.
mattip commentedon Nov 12, 2018
Fixed by #8955
Add -inf as identity for `logaddexp2.
ENH: correct identity for logaddexp2 ufunc: -inf
ENH: correct identity for logaddexp2 ufunc: -inf (gh-16102)