
    _-Phm
                     <    d Z ddlZddlmZ ddlmZ ddlmZ d Z	dS )zRelaxation-centric utilities.    N)LinearOperator   )MultilevelSolver)
relaxationc                    d }g d}t          j        j                   ||           \  }}t          j                    }|_        ||vrt          d|           	 t          t          j	        d|z             }n%# t          $ r}	t          d|           |	d}	~	ww xY w ||fi |fd}
t          j        |
j                  S )	a  Create a linear operator that applies a relaxation method to a right-hand-side.

    Parameters
    ----------
    methods : {tuple or string}
        Relaxation descriptor: Each tuple must be of the form ('method','opts')
        where 'method' is the name of a supported smoother, e.g., gauss_seidel,
        and 'opts' a dict of keyword arguments to the smoother, e.g., opts =
        {'sweep':symmetric}.  If string, must be that of a supported smoother,
        e.g., gauss_seidel.

    Returns
    -------
    linear operator that applies the relaxation method to a vector for a
    fixed right-hand-side, b.

    Notes
    -----
    This method is primarily used to improve B during the aggregation setup
    phase.  Here b = 0, and each relaxation call can improve the quality of B,
    especially near the boundaries.

    Examples
    --------
    >>> from pyamg.gallery import poisson
    >>> from pyamg.relaxation.utils import relaxation_as_linear_operator
    >>> import numpy as np
    >>> A = poisson((100,100), format='csr')           # matrix
    >>> B = np.ones((A.shape[0],1))                 # Candidate vector
    >>> b = np.zeros((A.shape[0]))                  # RHS
    >>> relax = relaxation_as_linear_operator('gauss_seidel', A, b)
    >>> B = relax*B

    c                 T    t          | t                    r| d         | d         fS | i fS )Nr      )
isinstancetuple)vs    V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyamg/relaxation/utils.py
unpack_argz1relaxation_as_linear_operator.<locals>.unpack_arg-   s/    a 	Q41:"u    )gauss_seidelblock_gauss_seidelsorgauss_seidel_negauss_seidel_nrjacobiblock_jacobi
richardsonschwarzstrength_based_schwarz	jacobi_ne)dtypezinvalid relaxation method: setup_zinvalid presmoother method: Nc                 J    |                                  } |           |S )N)copy)xxcopyAbrelaxs     r   matvecz-relaxation_as_linear_operator.<locals>.matvecI   s)    ar   )nparrayr   r   Levelr!   	NameErrorgetattrr   	smoothingr   shape)methodr!   r"   r   accepted_methodsfnkwargslvlsetup_smootherer$   r#   s    ``        @r   relaxation_as_linear_operatorr3   	   s=   H  ? ? ?
 	!'"""AF##JB

 
"
"CCE 
!!!:b::;;;D !5x"}EE D D D;r;;<<!CD N3))&))E      
 !'69999s   %B 
B%B  B%)
__doc__numpyr%   scipy.sparse.linalgr   
multilevelr    r   r3    r   r   <module>r:      sk    # #     . . . . . . ) ) ) ) ) )      E: E: E: E: E:r   