def _get_axis(array, axis, fname):
    """
    axis = _get_axis(array, axis, fname)
    Checks that ``axis`` is a valid axis of ``array`` and normalises it.
    Parameters
    ----------
    array : Tensor
    axis : int
    fname : str
        Function name. Used in error messages
    Returns
    -------
    axis : int
        The positive index of the axis to use
    """
    if axis < 0:
        axis += len(array.shape)

    if not (0 <= axis < len(array.shape)):
        raise ValueError(f"caer.{fname}: `axis` is out of bounds (maximum was {array.ndim}, got {axis})")

    return axis