Skip to content

logsumexp stabilization can make graph fail with zero-sized arrays #603

Description

@ricardoV94

Description

import numpy as np
import pytensor.tensor as pt

x = pt.tensor("x", shape=(0, 2))
pt.logsumexp(x).eval({x: np.zeros((0, 2))})   # ValueError: Input of CAReduce{maximum} has zero-size on axis %d

Interestingly, scipy has the same failure point

import numpy as np
import scipy

scipy.special.logsumexp(np.zeros((0, 2)))  # ValueError: zero-size array to reduction operation maximum which has no identity

This is arguably an edge case. I think a good compromise is to reject the rewrite when the static size is 0, but not otherwise.

Activity

  1. ricardoV94 commented on Apr 20, 2024

    @ricardoV94
    MemberAuthor

    Would the problem go away if we treat max([]) == -inf (at least for logsumexp)?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions