Skip to content

Ops

Pure functions used by the layers, including the signed-log transform.

polyweave.ops

Low-level, reusable mathematical operations (pure functions).

signed_log1p

signed_log1p(x: Tensor) -> torch.Tensor

sign(x) * log1p(|x|) — epsilon-free, exactly zero at the origin.

Parameters:

Name Type Description Default
x Tensor

input tensor.

required

Returns:

Type Description
Tensor

Tensor of the same shape as x.

Source code in polyweave/ops/signed_log.py
def signed_log1p(x: torch.Tensor) -> torch.Tensor:
    """`sign(x) * log1p(|x|)` — epsilon-free, exactly zero at the origin.

    Args:
        x: input tensor.

    Returns:
        Tensor of the same shape as ``x``.
    """
    return torch.sign(x) * torch.log1p(torch.abs(x))