Skip to content

Missing identity for logaddexp #4599

Closed
Closed

Description

@chebee7i

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.

Activity

  1. chebee7i commented on Apr 8, 2014

    @chebee7i
    ContributorAuthor

    Also, reduce doesn't seem to work on integer arrays. Should it automatically cast to float?

    In [6]: np.logaddexp.reduce(np.arange(5))
    TypeError: No loop matching the specified signature was found for ufunc logaddexp
    
  2. roger- commented on Nov 26, 2014

    @roger-

    Also, reduce doesn't seem to work on integer arrays. Should it automatically cast to float?

    Just noticed this myself, it really should.

  3. juliantaylor commented on Nov 26, 2014

    @juliantaylor
    Contributor

    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.

  4. chebee7i commented on Nov 26, 2014

    @chebee7i
    ContributorAuthor

    @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:

    'logaddexp':
        Ufunc(2, 1, None,
              docstrings.get('numpy.core.umath.logaddexp'),
              None,
              TD(flts, f="logaddexp", astype={'e':'f'}),
              ),
    

    could change how reduce behaved (besides explicitly making ints a valid input type). Though I admit, I know very little about the NumPy internals.

  5. chebee7i commented on Nov 26, 2014

    @chebee7i
    ContributorAuthor

    This reduction issue also affects hypot, atan2, etc.

  6. souravsingh commented on Nov 20, 2016

    @souravsingh

    I would like to work on the issue. How do I start?

  7. elllot commented on May 4, 2017

    @elllot

    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.

  8. eric-wieser commented on May 4, 2017

    @eric-wieser
    Member

    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...

  9. arogozhnikov commented on Aug 6, 2018

    @arogozhnikov
    Contributor

    Just faced this.

    In [6]: np.logaddexp.reduce(np.arange(5))
    TypeError: No loop matching the specified signature was found for ufunc logaddexp
    

    Very confusing behavior. Is there any progress with this issue?

  10. ron819 commented on Nov 5, 2018

    @ron819

    If someone can solve this please do also facing it.

  11. mattip commented on Nov 12, 2018

    @mattip
    Member

    Fixed by #8955

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions