def normalize_sequence(value, rank):
    """For scalar input, duplicate it into a sequence of rank length. For
    sequence input, check for correct length.
    """
    try:
        lst = list(value)
    except TypeError:
        lst = [value] * rank
    if len(lst) != rank:
        raise ValueError('Invalid sequence length.')
    return lst
