mr2.utils.to_tuple

mr2.utils.to_tuple(length: int, arg: Sequence[T] | T) tuple[T, ...][source]

Standardize an argument to a fixed-length tuple.

If the argument is a sequence, it checks if its length matches the specified dimension. If it’s a single value, it replicates it dim times.

Parameters:
  • length (int) – The expected length of the sequence.

  • arg (Union[Sequence[TypeVar(T)], TypeVar(T)]) – The argument to check. Can be a single value of type T or a sequence of T.

Returns:

A tuple of length dim containing elements of type T.

Raises:

ValueError – If arg is a sequence and its length does not match length.