def _permute_aux_by_matrix(K, Pkeep):
    """
    This function updates a sparse matrix by removing all references
    to indices contained in remove_index and rotating the remaining
    indices from their old position to their new position.

    PARAMETERS
    ----------
    1. K : sparse matrix
           the matrix to permute
    2. Pkeep : sparse matrix
               the permutation matrix

    RETURNS
    -------
    1. Ktmp : sparse matrix
              the permuted sparse matrix
    """
    # Multiplication to remove indices
    Ktmp = Pkeep @ K @ Pkeep.transpose()
    Ktmp.eliminate_zeros()
    return Ktmp