def check_axis_range(axis, rank):
    """Check axis range."""
    if not -rank <= axis < rank:
        raise ValueError('The axis should be in range [{}, {}), but got {}.'
            .format(-rank, rank, axis))
