§
    +Áôg  ã                   ó$   — d dl Z	 	 	 	 	 	 	 dd„ZdS )é    Nç        çH¯¼šò×z>é'  Fc	           	      ó~  ‡— ‰€d„ }	nt          ‰¦  «        r‰}	nˆfd„}	|€t          j        |¦  «        n|                     ¦   «         }
t          j                             |¦  «        }t          | ¦  «        r| | |
¦  «        z
  }n||                      |
¦  «        z
  }t          j                             |¦  «        }||k     s	|||z  k     r|
S  |	|¦  «        }|                     ¦   «         }t          j        ||¦  «        }t          |¦  «        D �]}|                     ¦   «         }t          | ¦  «        r | |¦  «        }n|                      |¦  «        }|t          j        ||¦  «        z  }|
||z  z  }
|||z  z  }t          j                             |¦  «        }|� || |
||||¦  «         ||k     s	|||z  k     r|
c S  |	|¦  «        }|r1t          j        ||z
  |¦  «        |z  }t          j        ||¦  «        }nd|z  }t          j        ||¦  «        }||z  }||z  }||z  }�Œt          d|z  ¦  «        ‚)a¤  Solves a system of linear equations :math:`Ax=b` using conjugate gradient descent :cite:`hestenes1952methods`

    Parameters
    ----------
    A: scipy.sparse.csr_matrix
       Square matrix
    b: numpy.ndarray
       Vector describing the right-hand side of the system
    x0: numpy.ndarray
       Initialization, if `None` then :code:`x=np.zeros_like(b)`
    atol: float
       Absolute tolerance. The loop terminates if the :math:`||r||` is smaller than `atol`, where :math:`r` denotes the residual of the current iterate.
    rtol: float
       Relative tolerance. The loop terminates if :math:`{||r||}/{||b||}` is smaller than `rtol`, where :math:`r` denotes the residual of the current iterate.
    callback: function
       Function :code:`callback(A, x, b, norm_b, r, norm_r)` called after each iteration, defaults to `None`
    M: function or scipy.sparse.csr_matrix
       Function that applies the preconditioner to a vector. Alternatively, `M` can be a matrix describing the precondioner.
    reorthogonalize: boolean
        Whether to apply reorthogonalization of the residuals after each update, defaults to `False`


    Returns
    -------
    x: numpy.ndarray
        Solution of the system

    Example
    -------
    >>> from pymatting import *
    >>> import numpy as np
    >>> A = np.array([[3.0, 1.0], [1.0, 2.0]])
    >>> M = jacobi(A)
    >>> b = np.array([4.0, 3.0])
    >>> cg(A, b, M=M)
    array([1., 1.])
    Nc                 ó   — | S ©N© )Úxs    ú\/var/www/html/bac/bac_backend/python/env/lib/python3.11/site-packages/pymatting/solver/cg.pyÚpreconditionzcg.<locals>.precondition6   s   € ØˆHó    c                 ó.   •— ‰                      | ¦  «        S r   )Údot)r
   ÚMs    €r   r   zcg.<locals>.precondition=   s   ø€ Ø—5’5˜‘8”8ˆOr   g      ð?z@Conjugate gradient descent did not converge within %d iterations)
ÚcallableÚnpÚ
zeros_likeÚcopyÚlinalgÚnormr   ÚinnerÚrangeÚ
ValueError)ÚAÚbÚx0ÚatolÚrtolÚmaxiterÚcallbackr   Úreorthogonalizer   r
   Únorm_bÚrÚnorm_rÚzÚpÚrzÚ	iterationÚr_oldÚApÚalphaÚbetas          `              r   Úcgr-      sn  ø€ ð` 	€yð	ð 	ð 	ð 	õ 
�!‰Œð Øˆˆð	ð 	ð 	ð 	ð 	ð ˜J�Œ�aÑÔÐ¨B¯GªG©I¬I€AåŒY�^Š^˜AÑÔ€Få��{„{ð Ø���!‘”‰Hˆˆà�—’�a‘”‰LˆåŒY�^Š^˜AÑÔ€Fà�‚}€}˜ ¨¡Ò.Ð.Øˆàˆ�Q‰Œ€AØ	�Š‰Œ€AÝ	Œ�!�Q‰Œ€Bå˜7‘^”^ð ñ ˆ	Ø—’‘”ˆå�A‰;Œ;ð 	Ø��1‘”ˆBˆBà—’�q‘”ˆBà•R”X˜a ‘_”_Ñ$ˆØ	ˆU�Q‰Y‰ˆØ	ˆU�R‰Z‰ˆå”—’ Ñ"Ô"ˆàÐØˆH�Q˜˜1˜f a¨Ñ0Ô0Ð0à�DŠ=ˆ=˜F T¨F¡]Ò2Ð2ØˆHˆHˆHàˆL˜‰OŒOˆàð 	Ý”8˜A ™I qÑ)Ô)¨BÑ.ˆDÝ”˜!˜Q‘”ˆBˆBà˜‘8ˆDÝ”˜!˜Q‘”ˆBØ�B‰JˆDà	ˆT‰	ˆØ	ˆQ‰ˆ‰å
ØJÈWÑTñô ð r   )Nr   r   r   NNF)Únumpyr   r-   r	   r   r   ú<module>r/      sL   ðØ Ð Ð Ð ð Ø	Ø	ØØØ
Øðqð qð qð qð qð qr   