code: def safe_logit(p: Union[float, int]) -> Optional[float]:
      r
      if p > 1 or p < 0:
          return None  # can't take log of negative number
      if p == 1:
          return float("inf")
      if p == 0:
          return float("-inf")
      return math.log(p / (1 - p))
docs: r"""
      Returns the logit (log odds) of its input probability
  
      .. math::
  
          \alpha = logit(p) = log(x / (1 - x))
  
      Args:
          p: :math:`p`
  
      Returns:
          :math:`\alpha`, or ``None`` if ``x`` is not in the range [0, 1].