Ejemplo n.º 1
0
def reverse_cuthill_mckee(A, sym=False):
    """
    Returns the permutation array that orders a sparse CSR or CSC matrix
    in Reverse-Cuthill McKee ordering. Since the input matrix must be
    symmetric, this routine works on the matrix A+Trans(A) if the sym flag is
    set to False (Default).

    It is assumed by default (*sym=False*) that the input matrix is not
    symmetric. This is because it is faster to do A+Trans(A) than it is to
    check for symmetry for a generic matrix. If you are guaranteed that the
    matrix is symmetric in structure (values of matrix element do not matter)
    then set *sym=True*

    Parameters
    ----------
    A : csc_matrix, csr_matrix
        Input sparse CSC or CSR sparse matrix format.
    sym : bool {False, True}
        Flag to set whether input matrix is symmetric.

    Returns
    -------
    perm : array
        Array of permuted row and column indices.

    Notes
    -----
    This routine is used primarily for internal reordering of Lindblad
    superoperators for use in iterative solver routines.

    References
    ----------
    E. Cuthill and J. McKee, "Reducing the Bandwidth of Sparse Symmetric
    Matrices", ACM '69 Proceedings of the 1969 24th national conference,
    (1969).
    
    """
    if not (sp.isspmatrix_csc(A) or sp.isspmatrix_csr(A)):
        raise TypeError('Input must be CSC or CSR sparse matrix.')

    nrows = A.shape[0]

    if not sym:
        A = A + A.transpose()

    return _reverse_cuthill_mckee(A.indices, A.indptr, nrows)
Ejemplo n.º 2
0
def reverse_cuthill_mckee(A, sym=False):
    """
    Returns the permutation array that orders a sparse CSR or CSC matrix
    in Reverse-Cuthill McKee ordering. Since the input matrix must be
    symmetric, this routine works on the matrix A+Trans(A) if the sym flag is
    set to False (Default).

    It is assumed by default (*sym=False*) that the input matrix is not
    symmetric. This is because it is faster to do A+Trans(A) than it is to
    check for symmetry for a generic matrix. If you are guaranteed that the
    matrix is symmetric in structure (values of matrix element do not matter)
    then set *sym=True*

    Parameters
    ----------
    A : csc_matrix, csr_matrix
        Input sparse CSC or CSR sparse matrix format.
    sym : bool {False, True}
        Flag to set whether input matrix is symmetric.

    Returns
    -------
    perm : array
        Array of permuted row and column indices.

    Notes
    -----
    This routine is used primarily for internal reordering of Lindblad
    superoperators for use in iterative solver routines.

    References
    ----------
    E. Cuthill and J. McKee, "Reducing the Bandwidth of Sparse Symmetric
    Matrices", ACM '69 Proceedings of the 1969 24th national conference,
    (1969).
    
    """
    if not (sp.isspmatrix_csc(A) or sp.isspmatrix_csr(A)):
        raise TypeError('Input must be CSC or CSR sparse matrix.')

    nrows = A.shape[0]

    if not sym:
        A = A + A.transpose()

    return _reverse_cuthill_mckee(A.indices, A.indptr, nrows)