import torch


def atanh(x: torch.Tensor) -> torch.Tensor:
    """
    Return atanh of the input. Modified torch.atanh in case the output is nan.

    Parameters
    ----------
    x: torch.Tensor
        input

    Returns
    -------
    y: torch.Tensor
        atanh(x)
    """
    return 0.5 * (torch.log(1 + x + 1e-6) - torch.log(1 - x + 1e-6))