import torch


def decompress_cIRM(mask, K=10, limit=9.9):
    """
    Uncompress cIRM from [-K ~ K] to [-inf, +inf]
    Args:
        mask: cIRM mask
        K: default 10
        limit: default 0.1
    References:
        https://ieeexplore.ieee.org/document/7364200
    """
    mask = limit * (mask >= limit) - limit * (mask <= -limit) + mask * (torch.abs(mask) < limit)
    mask = -K * torch.log((K - mask) / (K + mask))
    return mask