def weighted_bfs_matching(A):
    '\n    Returns an array of row permutations that attempts to maximize\n    the product of the ABS values of the diagonal elements in \n    a nonsingular square CSC sparse matrix. Such a permutation is \n    always possible provided that the matrix is nonsingular.\n    \n    This function looks at both the structure and ABS values of the \n    underlying matrix.\n    \n    Parameters\n    ----------\n    A : csc_matrix\n        Input matrix\n    \n    Returns\n    -------\n    perm : array\n        Array of row permutations.\n    \n    Notes\n    -----\n    This function uses a weighted maximum cardinality bipartite matching \n    algorithm based on breadth-first search (BFS).  The columns are weighted\n    according to the element of max ABS value in the associated rows and \n    are traversed in descending order by weight.  When performing the BFS \n    traversal, the row associated to a given column is the one with maximum \n    weight. Unlike other techniques[1]_, this algorithm does not guarantee the \n    product of the diagonal is maximized.  However, this limitation is offset\n    by the substantially faster runtime of this method. \n    \n    References\n    ----------\n    .. [1] I. S. Duff and J. Koster, "The design and use of algorithms for \n    permuting large entries to the diagonal of sparse matrices", SIAM J. \n    Matrix Anal. and Applics. 20, no. 4, 889 (1997).\n    \n    '
    nrows = A.shape[0]
    if (A.shape[0] != A.shape[1]):
        raise ValueError('weighted_bfs_matching requires a square matrix.')
    if (A.__class__.__name__ == 'Qobj'):
        A = A.data.tocsc()
    elif (not sp.isspmatrix_csc(A)):
        A = sp.csc_matrix(A)
        warn('weighted_bfs_matching requires CSC matrix format', sp.SparseEfficiencyWarning)
    perm = _weighted_bfs_matching(np.asarray(np.abs(A.data), dtype=float), A.indices, A.indptr, nrows)
    if np.any((perm == (- 1))):
        raise Exception('Possibly singular input matrix.')
    return perm
Returns an array of row permutations that attempts to maximize
the product of the ABS values of the diagonal elements in 
a nonsingular square CSC sparse matrix. Such a permutation is 
always possible provided that the matrix is nonsingular.

This function looks at both the structure and ABS values of the 
underlying matrix.

Parameters
----------
A : csc_matrix
    Input matrix

Returns
-------
perm : array
    Array of row permutations.

Notes
-----
This function uses a weighted maximum cardinality bipartite matching 
algorithm based on breadth-first search (BFS).  The columns are weighted
according to the element of max ABS value in the associated rows and 
are traversed in descending order by weight.  When performing the BFS 
traversal, the row associated to a given column is the one with maximum 
weight. Unlike other techniques[1]_, this algorithm does not guarantee the 
product of the diagonal is maximized.  However, this limitation is offset
by the substantially faster runtime of this method. 

References
----------
.. [1] I. S. Duff and J. Koster, "The design and use of algorithms for 
permuting large entries to the diagonal of sparse matrices", SIAM J. 
Matrix Anal. and Applics. 20, no. 4, 889 (1997).
def weighted_bfs_matching(A):
    '\n    Returns an array of row permutations that attempts to maximize\n    the product of the ABS values of the diagonal elements in \n    a nonsingular square CSC sparse matrix. Such a permutation is \n    always possible provided that the matrix is nonsingular.\n    \n    This function looks at both the structure and ABS values of the \n    underlying matrix.\n    \n    Parameters\n    ----------\n    A : csc_matrix\n        Input matrix\n    \n    Returns\n    -------\n    perm : array\n        Array of row permutations.\n    \n    Notes\n    -----\n    This function uses a weighted maximum cardinality bipartite matching \n    algorithm based on breadth-first search (BFS).  The columns are weighted\n    according to the element of max ABS value in the associated rows and \n    are traversed in descending order by weight.  When performing the BFS \n    traversal, the row associated to a given column is the one with maximum \n    weight. Unlike other techniques[1]_, this algorithm does not guarantee the \n    product of the diagonal is maximized.  However, this limitation is offset\n    by the substantially faster runtime of this method. \n    \n    References\n    ----------\n    .. [1] I. S. Duff and J. Koster, "The design and use of algorithms for \n    permuting large entries to the diagonal of sparse matrices", SIAM J. \n    Matrix Anal. and Applics. 20, no. 4, 889 (1997).\n    \n    '
    nrows = A.shape[0]
    if (A.shape[0] != A.shape[1]):
        raise ValueError('weighted_bfs_matching requires a square matrix.')
    if (A.__class__.__name__ == 'Qobj'):
        A = A.data.tocsc()
    elif (not sp.isspmatrix_csc(A)):
        A = sp.csc_matrix(A)
        warn('weighted_bfs_matching requires CSC matrix format', sp.SparseEfficiencyWarning)
    perm = _weighted_bfs_matching(np.asarray(np.abs(A.data), dtype=float), A.indices, A.indptr, nrows)
    if np.any((perm == (- 1))):
        raise Exception('Possibly singular input matrix.')
    return perm