Skip to content

softplus and inverse_softplus warn about overflow when they should not #270

@han-ol

Description

@han-ol

These functions lead to a warning when expm1/exp overflows, but this overflow is already disarmed by np.where.

 def inverse_softplus(x: np.ndarray, beta: float = 1.0, threshold: float = 20.0) -> np.ndarray:
    """Numerically stabilized inverse softplus function."""
    return np.where(beta * x > threshold, x, np.log(beta * np.expm1(x)) / beta)

...

def softplus(x: np.ndarray, beta: float = 1.0, threshold: float = 20.0) -> np.ndarray:
    """Numerically stabilized softplus function."""
    return np.where(beta * x > threshold, x, np.log1p(np.exp(beta * x)) / beta)

The expected behavior is: Don't warn when such a caught overflow occurs.

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