import torch


def get_inverse(tensor, damping=None, symmetric=True):
    """Compute inverse of tensor.

    Args:
      tensor: block of shape (x, x) to invert
      damping (float, optional): optionally add `identity * damping` to 
          `tensor` before inverting.
      symmetric (bool, optional): if True, `tensor` is symmetric and Cholesky
          decomposition will be used for computing the inverse. (default: True)

    Returns:
      The inverse of tensor
    """
    if damping is not None:
        d = tensor.new(tensor.shape[0]).fill_(damping)
        tensor = tensor + torch.diag(d)

    if symmetric:
        return torch.cholesky_inverse(torch.cholesky(tensor))
    else:
        return torch.inverse(tensor)