(A, theta)
return A_filter
Filter each column of A with tol.

    i.e., drop all entries in column k where
        abs(A[i,k]) < tol max( abs(A[:,k]) )

    Parameters
    ----------
    A : sparse_matrix

    theta : float
        In range [0,1) and defines drop-tolerance used to filter the columns
        of A

    Returns
    -------
    A_filter : sparse_matrix
        Each column has been filtered by dropping all entries where
        abs(A[i,k]) < tol max( abs(A[:,k]) )

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg.util.utils import filter_matrix_columns
    >>> from numpy import array
    >>> from scipy.sparse import csr_matrix
    >>> A = csr_matrix( array([[ 0.24,  1.  ,  0.  ],
    ...                        [-0.5 ,  1.  , -0.5 ],
    ...                        [ 0.  ,  0.49,  1.  ],
    ...                        [ 0.  ,  0.  , -0.5 ]]) )
    >>> filter_matrix_columns(A, 0.5).toarray()
    array([[ 0. ,  1. ,  0. ],
           [-0.5,  1. , -0.5],
           [ 0. ,  0. ,  1. ],
           [ 0. ,  0. , -0.5]])
Filter each column of A with tol.
Filter each column of A with tol .
def filter_matrix_columns(A, theta):
    """Filter each column of A with tol.

    i.e., drop all entries in column k where
        abs(A[i,k]) < tol max( abs(A[:,k]) )

    Parameters
    ----------
    A : sparse_matrix

    theta : float
        In range [0,1) and defines drop-tolerance used to filter the columns
        of A

    Returns
    -------
    A_filter : sparse_matrix
        Each column has been filtered by dropping all entries where
        abs(A[i,k]) < tol max( abs(A[:,k]) )

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg.util.utils import filter_matrix_columns
    >>> from numpy import array
    >>> from scipy.sparse import csr_matrix
    >>> A = csr_matrix( array([[ 0.24,  1.  ,  0.  ],
    ...                        [-0.5 ,  1.  , -0.5 ],
    ...                        [ 0.  ,  0.49,  1.  ],
    ...                        [ 0.  ,  0.  , -0.5 ]]) )
    >>> filter_matrix_columns(A, 0.5).toarray()
    array([[ 0. ,  1. ,  0. ],
           [-0.5,  1. , -0.5],
           [ 0. ,  0. ,  1. ],
           [ 0. ,  0. , -0.5]])

    """
    if not isspmatrix(A):
        raise ValueError('Sparse matrix input needed')
    if isspmatrix_bsr(A):
        blocksize = A.blocksize
    Aformat = A.format

    if (theta < 0) or (theta >= 1.0):
        raise ValueError('theta must be in [0,1)')

    # Apply drop-tolerance to each column of A, which is most easily
    # accessed by converting to CSC.  We apply the drop-tolerance with
    # amg_core.classical_strength_of_connection(), which ignores
    # diagonal entries, thus necessitating the trick where we add
    # A.shape[1] to each of the column indices
    A = A.copy().tocsc()
    A_filter = A.copy()
    A.indices += A.shape[1]
    A_filter.indices += A.shape[1]
    # classical_strength_of_connection takes an absolute value internally
    amg_core.classical_strength_of_connection_abs(A.shape[1],
                                                  theta,
                                                  A.indptr,
                                                  A.indices,
                                                  A.data,
                                                  A_filter.indptr,
                                                  A_filter.indices,
                                                  A_filter.data)
    A_filter.indices[:A_filter.indptr[-1]] -= A_filter.shape[1]
    A_filter = csc_matrix((A_filter.data[:A_filter.indptr[-1]],
                           A_filter.indices[:A_filter.indptr[-1]],
                           A_filter.indptr), shape=A_filter.shape)
    del A

    if Aformat == 'bsr':
        A_filter = A_filter.tobsr(blocksize)
    else:
        A_filter = A_filter.asformat(Aformat)

    return A_filter
def filter_matrix_columns ( A , theta ) : if not isspmatrix ( A ) : raise ValueError ( 'Sparse matrix input needed' ) if isspmatrix_bsr ( A ) : blocksize = A . blocksize Aformat = A . format if ( theta < 0 ) or ( theta >= 1.0 ) : raise ValueError ( 'theta must be in [0,1)' ) # Apply drop-tolerance to each column of A, which is most easily # accessed by converting to CSC.  We apply the drop-tolerance with # amg_core.classical_strength_of_connection(), which ignores # diagonal entries, thus necessitating the trick where we add # A.shape[1] to each of the column indices A = A . copy ( ) . tocsc ( ) A_filter = A . copy ( ) A . indices += A . shape [ 1 ] A_filter . indices += A . shape [ 1 ] # classical_strength_of_connection takes an absolute value internally amg_core . classical_strength_of_connection_abs ( A . shape [ 1 ] , theta , A . indptr , A . indices , A . data , A_filter . indptr , A_filter . indices , A_filter . data ) A_filter . indices [ : A_filter . indptr [ - 1 ] ] -= A_filter . shape [ 1 ] A_filter = csc_matrix ( ( A_filter . data [ : A_filter . indptr [ - 1 ] ] , A_filter . indices [ : A_filter . indptr [ - 1 ] ] , A_filter . indptr ) , shape = A_filter . shape ) del A if Aformat == 'bsr' : A_filter = A_filter . tobsr ( blocksize ) else : A_filter = A_filter . asformat ( Aformat ) return A_filter