r"""
    TODO: generalize to more than 2 dimensions to be more like
    itertools.product.

    CommandLine:
        python -m utool.util_alg --exec-diagonalized_iter
        python -m utool.util_alg --exec-diagonalized_iter --size=5

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_alg import *  # NOQA
        >>> import utool as ut
        >>> size = ut.get_argval('--size', default=4)
        >>> iter_ = diagonalized_iter(size)
        >>> mat = [[None] * size for _ in range(size)]
        >>> for count, (r, c) in enumerate(iter_):
        >>>     mat[r][c] = count
        >>> result = ut.repr2(mat, nl=1, packed=True)
        >>> print(result)
        [[0, 2, 5, 9],
         [1, 4, 8, 12],
         [3, 7, 11, 14],
         [6, 10, 13, 15],]

def diagonalized_iter(size):
    r"""
    TODO: generalize to more than 2 dimensions to be more like
    itertools.product.

    CommandLine:
        python -m utool.util_alg --exec-diagonalized_iter
        python -m utool.util_alg --exec-diagonalized_iter --size=5

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_alg import *  # NOQA
        >>> import utool as ut
        >>> size = ut.get_argval('--size', default=4)
        >>> iter_ = diagonalized_iter(size)
        >>> mat = [[None] * size for _ in range(size)]
        >>> for count, (r, c) in enumerate(iter_):
        >>>     mat[r][c] = count
        >>> result = ut.repr2(mat, nl=1, packed=True)
        >>> print(result)
        [[0, 2, 5, 9],
         [1, 4, 8, 12],
         [3, 7, 11, 14],
         [6, 10, 13, 15],]
    """
    for i in range(0, size + 1):
        for r, c in zip(reversed(range(i)), (range(i))):
            yield (r, c)
    for i in range(1, size):
        for r, c in zip(reversed(range(i, size)), (range(i, size))):
            yield (r, c)