(A, x, b, indices, iterations=1, sweep='forward')
Perform indexed Gauss-Seidel iteration on the linear system Ax=b.

    In indexed Gauss-Seidel, the sequence in which unknowns are relaxed is
    specified explicitly.  In contrast, the standard Gauss-Seidel method
    always performs complete sweeps of all variables in increasing or
    decreasing order.  The indexed method may be used to implement
    specialized smoothers, like F-smoothing in Classical AMG.

    Parameters
    ----------
    A : csr_matrix
        Sparse NxN matrix
    x : ndarray
        Approximate solution (length N)
    b : ndarray
        Right-hand side (length N)
    indices : ndarray
        Row indices to relax.
    iterations : int
        Number of iterations to perform
    sweep : {'forward','backward','symmetric'}
        Direction of sweep

    Returns
    -------
    Nothing, x will be modified in place.

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg.relaxation.relaxation import gauss_seidel_indexed
    >>> import numpy as np
    >>> A = poisson((4,), format='csr')
    >>> x = np.array([0.0, 0.0, 0.0, 0.0])
    >>> b = np.array([0.0, 1.0, 2.0, 3.0])
    >>> gauss_seidel_indexed(A, x, b, [0,1,2,3])  # relax all rows in order
    >>> gauss_seidel_indexed(A, x, b, [0,1])      # relax first two rows
    >>> gauss_seidel_indexed(A, x, b, [2,0])      # relax row 2, then row 0
    >>> gauss_seidel_indexed(A, x, b, [2,3], sweep='backward')  # 3, then 2
    >>> gauss_seidel_indexed(A, x, b, [2,0,2])    # relax row 2, 0, 2
Perform indexed Gauss-Seidel iteration on the linear system Ax=b.
Perform indexed Gauss - Seidel iteration on the linear system Ax = b .
def gauss_seidel_indexed(A, x, b, indices, iterations=1, sweep='forward'):
    """Perform indexed Gauss-Seidel iteration on the linear system Ax=b.

    In indexed Gauss-Seidel, the sequence in which unknowns are relaxed is
    specified explicitly.  In contrast, the standard Gauss-Seidel method
    always performs complete sweeps of all variables in increasing or
    decreasing order.  The indexed method may be used to implement
    specialized smoothers, like F-smoothing in Classical AMG.

    Parameters
    ----------
    A : csr_matrix
        Sparse NxN matrix
    x : ndarray
        Approximate solution (length N)
    b : ndarray
        Right-hand side (length N)
    indices : ndarray
        Row indices to relax.
    iterations : int
        Number of iterations to perform
    sweep : {'forward','backward','symmetric'}
        Direction of sweep

    Returns
    -------
    Nothing, x will be modified in place.

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg.relaxation.relaxation import gauss_seidel_indexed
    >>> import numpy as np
    >>> A = poisson((4,), format='csr')
    >>> x = np.array([0.0, 0.0, 0.0, 0.0])
    >>> b = np.array([0.0, 1.0, 2.0, 3.0])
    >>> gauss_seidel_indexed(A, x, b, [0,1,2,3])  # relax all rows in order
    >>> gauss_seidel_indexed(A, x, b, [0,1])      # relax first two rows
    >>> gauss_seidel_indexed(A, x, b, [2,0])      # relax row 2, then row 0
    >>> gauss_seidel_indexed(A, x, b, [2,3], sweep='backward')  # 3, then 2
    >>> gauss_seidel_indexed(A, x, b, [2,0,2])    # relax row 2, 0, 2

    """
    A, x, b = make_system(A, x, b, formats=['csr'])

    indices = np.asarray(indices, dtype='intc')

    # if indices.min() < 0:
    #     raise ValueError('row index (%d) is invalid' % indices.min())
    # if indices.max() >= A.shape[0]
    #     raise ValueError('row index (%d) is invalid' % indices.max())

    if sweep not in ('forward', 'backward', 'symmetric'):
        raise ValueError('valid sweep directions: "forward", "backward", and "symmetric"')

    if sweep == 'forward':
        row_start, row_stop, row_step = 0, len(indices), 1
    elif sweep == 'backward':
        row_start, row_stop, row_step = len(indices)-1, -1, -1
    elif sweep == 'symmetric':
        for _iter in range(iterations):
            gauss_seidel_indexed(A, x, b, indices, iterations=1,
                                 sweep='forward')
            gauss_seidel_indexed(A, x, b, indices, iterations=1,
                                 sweep='backward')
        return

    for _iter in range(iterations):
        amg_core.gauss_seidel_indexed(A.indptr, A.indices, A.data,
                                      x, b, indices,
                                      row_start, row_stop, row_step)
def gauss_seidel_indexed ( A , x , b , indices , iterations = 1 , sweep = 'forward' ) : A , x , b = make_system ( A , x , b , formats = [ 'csr' ] ) indices = np . asarray ( indices , dtype = 'intc' ) # if indices.min() < 0: #     raise ValueError('row index (%d) is invalid' % indices.min()) # if indices.max() >= A.shape[0] #     raise ValueError('row index (%d) is invalid' % indices.max()) if sweep not in ( 'forward' , 'backward' , 'symmetric' ) : raise ValueError ( 'valid sweep directions: "forward", "backward", and "symmetric"' ) if sweep == 'forward' : row_start , row_stop , row_step = 0 , len ( indices ) , 1 elif sweep == 'backward' : row_start , row_stop , row_step = len ( indices ) - 1 , - 1 , - 1 elif sweep == 'symmetric' : for _iter in range ( iterations ) : gauss_seidel_indexed ( A , x , b , indices , iterations = 1 , sweep = 'forward' ) gauss_seidel_indexed ( A , x , b , indices , iterations = 1 , sweep = 'backward' ) return for _iter in range ( iterations ) : amg_core . gauss_seidel_indexed ( A . indptr , A . indices , A . data , x , b , indices , row_start , row_stop , row_step )