Skip to content

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

Open
@ricardoV94

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.

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