Ë
    ½Gìj  ã                   ó"   — d dl Z	 	 	 	 	 	 	 dd„Zy)é    Nc	           	      ó  ‡— ‰€d„ }	nt        ‰«      r‰}	nˆfd„}	|€t        j                  |«      n|j                  «       }
t        j                  j                  |«      }t        | «      r| | |
«      z
  }n|| j                  |
«      z
  }t        j                  j                  |«      }||k  s|||z  k  r|
S  |	|«      }|j                  «       }t        j                  ||«      }t        |«      D �]  }|j                  «       }t        | «      r	 | |«      }n| j                  |«      }|t        j                  ||«      z  }|
||z  z  }
|||z  z  }t        j                  j                  |«      }|� || |
||||«       ||k  s|||z  k  r|
c S  |	|«      }|r3t        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.])
    c                 ó   — | S ©N© )Úxs    úWC:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\pymatting/solver/cg.pyÚpreconditionzcg.<locals>.precondition6   s   € ØˆHó    c                 ó&   •— ‰j                  | «      S r   )Údot)r   ÚMs    €r   r	   zcg.<locals>.precondition=   s   ø€ Ø—5‘5˜“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*      sæ  ø€ ð` 	€yó	ô 
�!ŒØ‰ô	ð ˜JŒ�‰�aÔ¨B¯G©G«I€Aä�Y‰Y�^‰^˜AÓ€Fä�„{Ø‘�!“‰H‰à�—‘�a“‰Lˆä�Y‰Y�^‰^˜AÓ€Fà�‚}˜ ¨¡Ò.Øˆá�Q‹€AØ	�‰‹€AÜ	�‰�!�Q‹€Bä˜7—^ˆ	Ø—‘“ˆä�AŒ;Ù�1“‰Bà—‘�q“ˆBà”R—X‘X˜a “_Ñ$ˆØ	ˆU�Q‰Y‰ˆØ	ˆU�R‰Z‰ˆä—‘—‘ Ó"ˆàÐÙ�Q˜˜1˜f a¨Ô0à�DŠ=˜F T¨F¡]Ò2ØŠHá˜‹OˆáÜ—8‘8˜A ™I qÓ)¨BÑ.ˆDÜ—‘˜!˜Q“‰Bà˜‘8ˆDÜ—‘˜!˜Q“ˆBØ�B‰JˆDà	ˆT‰	ˆØ	ˆQ‰Šð? $ôB ØJÈWÑTóð r
   )Ng        gH¯¼šò×z>i'  NNF)Únumpyr   r*   r   r
   r   Ú<module>r,      s%   ðÛ ð Ø	Ø	ØØØ
Øôqr
   