import torch


def sanitize_infinity(x):
    """
    Returns largest possible value for the dtype of the input array.

    Parameters:
    -----------
    x: `DNDarray` or `torch.Tensor`

    Returns:
    --------
    largest: largest possible value for the given dtype
    """
    dtype = x.dtype if isinstance(x, torch.Tensor) else x.larray.dtype
    try:
        largest = torch.finfo(dtype).max
    except TypeError:
        largest = torch.iinfo(dtype).max

    return largest