import torch
import math


def cauchy_icdf(p, loc, scale):
    """
        Compute the componentwise inverse cdf of a cauchy with mean as loc and variance as scale.

        Parameters
        ----------
        p:  float(s)
            Probability value in [0,1]
        loc: float(s)
            The mean of the distribution
        scale: float(s) > 0
            The variance of the distribution

        Returns
        -------
            float(s): quartile of p
    """

    return torch.tan(math.pi * (p - 0.5)) * scale + loc