(A, B=None, verb=True)
return config
Generate a dictionary of SA parameters for an arbitray matrix A.

    Parameters
    ----------
    A : array, matrix, csr_matrix, bsr_matrix
        (n x n) matrix to invert, CSR or BSR format preferred for efficiency
    B : None, array
        Near null-space modes used to construct the smoothed aggregation solver
        If None, the constant vector is used
        If (n x m) array, then B is passed to smoothed_aggregation_solver
    verb : bool
        If True, print verbose output during runtime

    Returns
    -------
    config : dict
        A dictionary of solver configuration parameters that one uses to
        generate a smoothed aggregation solver

    Notes
    -----
    The config dictionary contains the following parameter entries: symmetry,
    smooth, presmoother, postsmoother, B, strength, max_levels, max_coarse,
    coarse_solver, aggregate, keep.  See smoothed_aggregtion_solver for each
    parameter's description.

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg import solver_configuration
    >>> A = poisson((40,40),format='csr')
    >>> solver_config = solver_configuration(A,verb=False)
Generate a dictionary of SA parameters for an arbitray matrix A.
Generate a dictionary of SA parameters for an arbitray matrix A .
def solver_configuration(A, B=None, verb=True):
    """Generate a dictionary of SA parameters for an arbitray matrix A.

    Parameters
    ----------
    A : array, matrix, csr_matrix, bsr_matrix
        (n x n) matrix to invert, CSR or BSR format preferred for efficiency
    B : None, array
        Near null-space modes used to construct the smoothed aggregation solver
        If None, the constant vector is used
        If (n x m) array, then B is passed to smoothed_aggregation_solver
    verb : bool
        If True, print verbose output during runtime

    Returns
    -------
    config : dict
        A dictionary of solver configuration parameters that one uses to
        generate a smoothed aggregation solver

    Notes
    -----
    The config dictionary contains the following parameter entries: symmetry,
    smooth, presmoother, postsmoother, B, strength, max_levels, max_coarse,
    coarse_solver, aggregate, keep.  See smoothed_aggregtion_solver for each
    parameter's description.

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg import solver_configuration
    >>> A = poisson((40,40),format='csr')
    >>> solver_config = solver_configuration(A,verb=False)

    """
    # Ensure acceptable format of A
    A = make_csr(A)
    config = {}

    # Detect symmetry
    if ishermitian(A, fast_check=True):
        config['symmetry'] = 'hermitian'
        if verb:
            print('  Detected a Hermitian matrix')
    else:
        config['symmetry'] = 'nonsymmetric'
        if verb:
            print('  Detected a non-Hermitian matrix')

    # Symmetry dependent parameters
    if config['symmetry'] == 'hermitian':
        config['smooth'] = ('energy', {'krylov': 'cg', 'maxiter': 3,
                                       'degree': 2, 'weighting': 'local'})
        config['presmoother'] = ('block_gauss_seidel',
                                 {'sweep': 'symmetric', 'iterations': 1})
        config['postsmoother'] = ('block_gauss_seidel',
                                  {'sweep': 'symmetric', 'iterations': 1})
    else:
        config['smooth'] = ('energy', {'krylov': 'gmres', 'maxiter': 3,
                                       'degree': 2, 'weighting': 'local'})
        config['presmoother'] = ('gauss_seidel_nr',
                                 {'sweep': 'symmetric', 'iterations': 2})
        config['postsmoother'] = ('gauss_seidel_nr',
                                  {'sweep': 'symmetric', 'iterations': 2})

    # Determine near null-space modes B
    if B is None:
        # B is the constant for each variable in a node
        if isspmatrix_bsr(A) and A.blocksize[0] > 1:
            bsize = A.blocksize[0]
            config['B'] = np.kron(np.ones((int(A.shape[0] / bsize), 1),
                                          dtype=A.dtype), np.eye(bsize))
        else:
            config['B'] = np.ones((A.shape[0], 1), dtype=A.dtype)
    elif isinstance(B, np.ndarray):
        if len(B.shape) == 1:
            B = B.reshape(-1, 1)

        if (B.shape[0] != A.shape[0]) or (B.shape[1] == 0):
            raise TypeError('Invalid dimensions of B, B.shape[0] must equal A.shape[0]')

        config['B'] = np.array(B, dtype=A.dtype)
    else:
        raise TypeError('Invalid B')

    if config['symmetry'] == 'hermitian':
        config['BH'] = None
    else:
        config['BH'] = config['B'].copy()

    # Set non-symmetry related parameters
    config['strength'] = ('evolution', {'k': 2, 'proj_type': 'l2',
                                        'epsilon': 3.0})
    config['max_levels'] = 15
    config['max_coarse'] = 500
    config['coarse_solver'] = 'pinv'
    config['aggregate'] = 'standard'
    config['keep'] = False

    return config
def solver_configuration ( A , B = None , verb = True ) : # Ensure acceptable format of A A = make_csr ( A ) config = { } # Detect symmetry if ishermitian ( A , fast_check = True ) : config [ 'symmetry' ] = 'hermitian' if verb : print ( '  Detected a Hermitian matrix' ) else : config [ 'symmetry' ] = 'nonsymmetric' if verb : print ( '  Detected a non-Hermitian matrix' ) # Symmetry dependent parameters if config [ 'symmetry' ] == 'hermitian' : config [ 'smooth' ] = ( 'energy' , { 'krylov' : 'cg' , 'maxiter' : 3 , 'degree' : 2 , 'weighting' : 'local' } ) config [ 'presmoother' ] = ( 'block_gauss_seidel' , { 'sweep' : 'symmetric' , 'iterations' : 1 } ) config [ 'postsmoother' ] = ( 'block_gauss_seidel' , { 'sweep' : 'symmetric' , 'iterations' : 1 } ) else : config [ 'smooth' ] = ( 'energy' , { 'krylov' : 'gmres' , 'maxiter' : 3 , 'degree' : 2 , 'weighting' : 'local' } ) config [ 'presmoother' ] = ( 'gauss_seidel_nr' , { 'sweep' : 'symmetric' , 'iterations' : 2 } ) config [ 'postsmoother' ] = ( 'gauss_seidel_nr' , { 'sweep' : 'symmetric' , 'iterations' : 2 } ) # Determine near null-space modes B if B is None : # B is the constant for each variable in a node if isspmatrix_bsr ( A ) and A . blocksize [ 0 ] > 1 : bsize = A . blocksize [ 0 ] config [ 'B' ] = np . kron ( np . ones ( ( int ( A . shape [ 0 ] / bsize ) , 1 ) , dtype = A . dtype ) , np . eye ( bsize ) ) else : config [ 'B' ] = np . ones ( ( A . shape [ 0 ] , 1 ) , dtype = A . dtype ) elif isinstance ( B , np . ndarray ) : if len ( B . shape ) == 1 : B = B . reshape ( - 1 , 1 ) if ( B . shape [ 0 ] != A . shape [ 0 ] ) or ( B . shape [ 1 ] == 0 ) : raise TypeError ( 'Invalid dimensions of B, B.shape[0] must equal A.shape[0]' ) config [ 'B' ] = np . array ( B , dtype = A . dtype ) else : raise TypeError ( 'Invalid B' ) if config [ 'symmetry' ] == 'hermitian' : config [ 'BH' ] = None else : config [ 'BH' ] = config [ 'B' ] . copy ( ) # Set non-symmetry related parameters config [ 'strength' ] = ( 'evolution' , { 'k' : 2 , 'proj_type' : 'l2' , 'epsilon' : 3.0 } ) config [ 'max_levels' ] = 15 config [ 'max_coarse' ] = 500 config [ 'coarse_solver' ] = 'pinv' config [ 'aggregate' ] = 'standard' config [ 'keep' ] = False return config