def pairs(n):
    """
    Generate index pairs for triangular packed matrices up to n
    """
    ij = 0
    for i in range(n):
        for j in range(i + 1):
            yield ij, i, j
            ij += 1
