def vector_index(row_idx, col_idx, matrix_size):
    """
    Return vector index (vector of Cls in healpy diagonal-major order) corresponding to matrix indices (of Wishart
    scale matrix).

    Args:
        row_idx (int): Row index for matrix.
        col_idx (int): Column index for matrix.
        matrix_size (int): Size along one axis of the square matrix that input indices are for.

    Returns:
        int: Vector index corresponding to the input matrix indices.
    """

    # Only consider the upper triangle of the matrix by requiring that col >= row
    col = max(row_idx, col_idx)
    row = min(row_idx, col_idx)

    # Formula comes from standard sum over n
    diag = col - row
    return int(row + diag * (matrix_size - 0.5 * (diag - 1)))