def _maybe_repeat(x, n):
    """Utility function for processing arguments that are singletons or lists.

    Args:
      x: either a list of n elements, or not a list.
      n: repeat n times.

    Returns:
      a list of n elements.
    """
    if isinstance(x, list):
        assert len(x) == n
        return x
    else:
        return [x] * n