import torch


def cutoff_function(x: torch.Tensor, cutoff: float) -> torch.Tensor:
    """
    Cutoff function that smoothly goes from f(x) = 1 to f(x) = 0 in the interval
    from x = 0 to x = cutoff. For x >= cutoff, f(x) = 0. This function has
    infinitely many smooth derivatives. Only positive x should be used as input.
    """
    zeros = torch.zeros_like(x)
    x_ = torch.where(x < cutoff, x, zeros)  # prevent nan in backprop
    return torch.where(
        x < cutoff, torch.exp(-(x_ ** 2) / ((cutoff - x_) * (cutoff + x_))), zeros
    )