
    (phE              	           S SK r S SKrS SKJr  SSKJr  S SKJr  / SQr	SS	 jr
SSSSSSS
.S jjrSSSSSSS
.S jjrSSSSSSS
.S jjrSSSSSSS
.S jjrSSSSSSSSS.S jjrSSSSSSSS.S jjrg)    N)LinearOperator   )make_system)get_lapack_funcs)bicgbicgstabcgcgsgmresqmr        h㈵>c                     US:X  d	  Ub  US:  a  SU  SU S3n[        U5      e[        [        U5      [        U5      [        U5      -  5      nX#4$ )z5
A helper function to handle tolerance normalization
legacyr   z'scipy.sparse.linalg.z' called with invalid `atol`=z5; if set, `atol` must be a real, non-negative number.)
ValueErrormaxfloat)nameb_normatolrtolmsgs        X/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/linalg/_isolve/iterative.py_get_atol_rtolr   
   sb     x4<4!8&tf,I$ PE EouT{E$K%-78D:    )r   r   maxiterMcallbackc                   [        XX!5      u  ppn	[        R                  R                  U5      n
[	        SXU5      u  pKU
S:X  a
  U	" U5      S4$ [        U5      n[        R                  " U5      (       a  [        R                  O[        R                  nUc  US-  nU R                  U R                  pUR                  UR                  nn[        R                  " UR                  R                  5      R                  S-  nSu  nnnUR                  5       (       a
  X" U5      -
  OUR!                  5       nUR!                  5       n[#        U5       GH$  n[        R                  R                  U5      U:  a  U	" U5      S4s  $ U" U5      nU" U5      nU" UU5      n[        R$                  " U5      U:  a  U	S4s  $ US:  a(  UU-  nUU-  nUU-  nUUR'                  5       -  nUU-  nO UR!                  5       nUR!                  5       nU" U5      nU" U5      nU" UU5      nUS:X  a  U	" U5      S4s  $ UU-  n UU U-  -  nUU U-  -  nUU R'                  5       U-  -  nUnU(       d  GM  U" U5        GM'     U	" U5      U4$ )a  Use BIConjugate Gradient iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real or complex N-by-N matrix of the linear system.
    Alternatively, `A` can be a linear operator which can
    produce ``Ax`` and ``A^T x`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution.
rtol, atol : float, optional
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
maxiter : integer
    Maximum number of iterations.  Iteration will stop after maxiter
    steps even if the specified tolerance has not been achieved.
M : {sparse array, ndarray, LinearOperator}
    Preconditioner for `A`. It should approximate the
    inverse of `A` (see Notes). Effective preconditioning dramatically improves the
    rate of convergence, which implies that fewer iterations are needed
    to reach a given error tolerance.
callback : function
    User-supplied function to call after each iteration.  It is called
    as ``callback(xk)``, where ``xk`` is the current solution vector.

Returns
-------
x : ndarray
    The converged solution.
info : integer
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations
        <0 : parameter breakdown

Notes
-----
The preconditioner `M` should be a matrix such that ``M @ A`` has a smaller
condition number than `A`, see [1]_ .

References
----------
.. [1] "Preconditioner", Wikipedia, 
       https://en.wikipedia.org/wiki/Preconditioner
.. [2] "Biconjugate gradient method", Wikipedia, 
       https://en.wikipedia.org/wiki/Biconjugate_gradient_method

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import bicg
>>> A = csc_array([[3, 2, 0], [1, -1, 0], [0, 5, 1.]])
>>> b = np.array([2., 4., -1.])
>>> x, exitCode = bicg(A, b, atol=1e-5)
>>> print(exitCode)  # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
r   r   
      )NNN)r   nplinalgnormr   leniscomplexobjvdotdotmatvecrmatvecfinfodtypecharepsanycopyrangeabsconj)!Abx0r   r   r   r   r   xpostprocessbnrm2_ndotprodr+   r,   psolverpsolverhotolrho_prevpptilderrtilde	iterationzztilderho_curbetaqqtildervalphas!                                    r   r   r      sK   B *!6A!IINN1EVU$7GDz1~q  AA++bggGB$hh		Ghh		GFXXaggll#''*F +HaF1IaffhAVVXF7^	99>>!t#q>1$$1I&!$66'?V###q=X%DIAFAdiik!FfFA[[]F1IVQ7q>3&&"	U1W	U1W%**,v%%8QKI $P 1~w&&r   c                   [        XX!5      u  ppn	[        R                  R                  U5      n
[	        SXU5      u  pKU
S:X  a
  U	" U5      S4$ [        U5      n[        R                  " U5      (       a  [        R                  O[        R                  nUc  US-  nU R                  nUR                  n[        R                  " UR                  R                  5      R                  S-  nUnSu  nnnnnUR                  5       (       a
  X" U5      -
  OUR                  5       nUR                  5       n[!        U5       GH  n[        R                  R                  U5      U:  a  U	" U5      S4s  $ U" UU5      n[        R"                  " U5      U:  a  U	" U5      S4s  $ US:  aD  [        R"                  " U5      U:  a  U	" U5      S4s  $ UU-  UU-  -  nUUU-  -  nUU-  nUU-  nO&[        R$                  " U5      nUR                  5       nU" U5      nU" U5      nU" UU5      nUS:X  a  U	" U5      S4s  $ UU-  nUUU-  -  nUSS WSS& [        R                  R                  U5      U:  a  UUU-  -  nU	" U5      S4s  $ U" U5      nU" U5      n U" U U5      U" U U 5      -  nUUU-  -  nUUU-  -  nUUU -  -  nUnU(       d  GM  U" U5        GM     U	" U5      U4$ )	a6	  Use BIConjugate Gradient STABilized iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real or complex N-by-N matrix of the linear system.
    Alternatively, `A` can be a linear operator which can
    produce ``Ax`` and ``A^T x`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution.
rtol, atol : float, optional
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
maxiter : integer
    Maximum number of iterations.  Iteration will stop after maxiter
    steps even if the specified tolerance has not been achieved.
M : {sparse array, ndarray, LinearOperator}
    Preconditioner for `A`. It should approximate the
    inverse of `A` (see Notes). Effective preconditioning dramatically improves the
    rate of convergence, which implies that fewer iterations are needed
    to reach a given error tolerance.
callback : function
    User-supplied function to call after each iteration.  It is called
    as ``callback(xk)``, where ``xk`` is the current solution vector.

Returns
-------
x : ndarray
    The converged solution.
info : integer
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations
        <0 : parameter breakdown

Notes
-----
The preconditioner `M` should be a matrix such that ``M @ A`` has a smaller
condition number than `A`, see [1]_ .

References
----------
.. [1] "Preconditioner", Wikipedia, 
       https://en.wikipedia.org/wiki/Preconditioner
.. [2] "Biconjugate gradient stabilized method", 
       Wikipedia, https://en.wikipedia.org/wiki/Biconjugate_gradient_stabilized_method

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import bicgstab
>>> R = np.array([[4, 2, 0, 1],
...               [3, 0, 0, 2],
...               [0, 1, 1, 1],
...               [0, 2, 1, 0]])
>>> A = csc_array(R)
>>> b = np.array([-1, -0.5, -1, 2])
>>> x, exit_code = bicgstab(A, b, atol=1e-5)
>>> print(exit_code)  # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
r   r   Nr    r!   NNNNNr"   r#   r   r$   r%   r&   r   r'   r(   r)   r*   r+   r-   r.   r/   r0   r1   r2   r3   r4   
empty_like)!r6   r7   r8   r   r   r   r   r   r9   r:   r;   r<   r=   r>   r+   r?   rA   omegatolrB   omegarO   rC   vrE   rF   rG   rhorK   sphatrN   shatts!                                    r   r   r      s   L *!6A!IINN1EZd;GDz1~q  AA++bggGB$XXFXXF XXaggll#''*FH $@ HeUAqF1IaffhAVVXF7^	99>>!t#q>1$$fa 66#;q>3&&q=vve}x'"1~s**(Nuu}5DqLAIAFAa AAay4LVQ7q>3&&b	U1Wt!99>>!t#tOAq>1$$ay4L11-	U4Z	U4Z	U1W8QKU $\ 1~w&&r   c                `   [        XX!5      u  ppn	[        R                  R                  U5      n
[	        SXU5      u  pKU
S:X  a
  U	" U5      S4$ [        U5      nUc  US-  n[        R                  " U5      (       a  [        R                  O[        R                  nU R                  nUR                  nUR                  5       (       a
  X" U5      -
  OUR                  5       nSu  nn[        U5       H  n[        R                  R                  U5      U:  a  U	" U5      S4s  $ U" U5      nU" UU5      nUS:  a  UU-  nUU-  nUU-  nO[        R                  " U5      nUSS USS& U" U5      nUU" UU5      -  nUUU-  -  nUUU-  -  nUnU(       d  M  U" U5        M     U	" U5      U4$ )aP	  Use Conjugate Gradient iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real or complex N-by-N matrix of the linear system.
    `A` must represent a hermitian, positive definite matrix.
    Alternatively, `A` can be a linear operator which can
    produce ``Ax`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution.
rtol, atol : float, optional
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
maxiter : integer
    Maximum number of iterations.  Iteration will stop after maxiter
    steps even if the specified tolerance has not been achieved.
M : {sparse array, ndarray, LinearOperator}
    Preconditioner for `A`. `M` must represent a hermitian, positive definite
    matrix. It should approximate the inverse of `A` (see Notes).
    Effective preconditioning dramatically improves the
    rate of convergence, which implies that fewer iterations are needed
    to reach a given error tolerance.
callback : function
    User-supplied function to call after each iteration.  It is called
    as ``callback(xk)``, where ``xk`` is the current solution vector.

Returns
-------
x : ndarray
    The converged solution.
info : integer
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations

Notes
-----
The preconditioner `M` should be a matrix such that ``M @ A`` has a smaller
condition number than `A`, see [2]_.

References
----------
.. [1] "Conjugate Gradient Method, Wikipedia, 
       https://en.wikipedia.org/wiki/Conjugate_gradient_method
.. [2] "Preconditioner", 
       Wikipedia, https://en.wikipedia.org/wiki/Preconditioner

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import cg
>>> P = np.array([[4, 0, 1, 0],
...               [0, 5, 0, 0],
...               [1, 0, 3, 2],
...               [0, 0, 2, 4]])
>>> A = csc_array(P)
>>> b = np.array([-1, -0.5, -1, 2])
>>> x, exit_code = cg(A, b, atol=1e-5)
>>> print(exit_code)    # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
r	   r   Nr    )NN)r   r$   r%   r&   r   r'   r(   r)   r*   r+   r1   r2   r3   rS   )r6   r7   r8   r   r   r   r   r   r9   r:   r;   r<   r=   r>   r+   r?   rE   rB   rC   rG   rH   rJ   rK   rL   rO   s                            r   r	   r	   1  s   L *!6A!IINN1ET55GDz1~q  AAB$++bggGXXFXXFF1IaffhA KHa7^	99>>!t#q>1$$1I!Q-q=X%DIAFAa AQ4AaD1I'!Q-'	U1W	U1W8QK+ $2 1~w&&r   c                P   [        XX!5      u  ppn	[        R                  R                  U5      n
[	        SXU5      u  pKU
S:X  a
  U	" U5      S4$ [        U5      n[        R                  " U5      (       a  [        R                  O[        R                  nUc  US-  nU R                  nUR                  n[        R                  " UR                  R                  5      R                  S-  nUR                  5       (       a
  X" U5      -
  OUR                  5       nUR                  5       n[        R                  R                  U5      nUS:X  a  SnSu  nnnn[!        U5       GH5  n[        R                  R                  U5      nUU:  a  U	" U5      S4s  $ U" UU5      n[        R"                  " U5      U:  a  U	S4s  $ US:  a*  UU-  nUSS USS& UUU-  -  nUU-  nUU-  nUU-  nUU-  nO6UR                  5       nUR                  5       n[        R$                  " U5      nU" U5      nU" U5      nU" UU5      nUS:X  a  U	" U5      S	4s  $ UU-  nUSS USS& UUU-  -  nU" UU-   5      n UUU -  -  nX" U5      -
  nUnU(       d  GM-  U" U5        GM8     U	" U5      U4$ )
a  Use Conjugate Gradient Squared iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real-valued N-by-N matrix of the linear system.
    Alternatively, `A` can be a linear operator which can
    produce ``Ax`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution.
rtol, atol : float, optional
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
maxiter : integer
    Maximum number of iterations.  Iteration will stop after maxiter
    steps even if the specified tolerance has not been achieved.
M : {sparse array, ndarray, LinearOperator}
    Preconditioner for ``A``. It should approximate the
    inverse of `A` (see Notes). Effective preconditioning dramatically improves the
    rate of convergence, which implies that fewer iterations are needed
    to reach a given error tolerance.
callback : function
    User-supplied function to call after each iteration.  It is called
    as ``callback(xk)``, where ``xk`` is the current solution vector.

Returns
-------
x : ndarray
    The converged solution.
info : integer
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations
        <0 : parameter breakdown

Notes
-----
The preconditioner `M` should be a matrix such that ``M @ A`` has a smaller
condition number than `A`, see [1]_.

References
----------
.. [1] "Preconditioner", Wikipedia, 
       https://en.wikipedia.org/wiki/Preconditioner
.. [2] "Conjugate gradient squared", Wikipedia,
       https://en.wikipedia.org/wiki/Conjugate_gradient_squared_method

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import cgs
>>> R = np.array([[4, 2, 0, 1],
...               [3, 0, 0, 2],
...               [0, 1, 1, 1],
...               [0, 2, 1, 0]])
>>> A = csc_array(R)
>>> b = np.array([-1, -0.5, -1, 2])
>>> x, exit_code = cgs(A, b)
>>> print(exit_code)  # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
r
   r   Nr    r!   r   )NNNNr"   r#   rR   )!r6   r7   r8   r   r   r   r   r   r9   r:   r;   r<   r=   r>   r+   r?   rA   rE   rF   bnormrB   rC   urL   rG   rnormrJ   rK   rY   vhatrN   rO   uhats!                                    r   r
   r
     s   J *!6A!IINN1EUE6GDz1~q  AA++bggGB$XXFXXFXXaggll#''*FF1IaffhAVVXFIINN1Ez /HaA7^			q!4<q>1$$&!$66'?V###q=X%D Q4AaDaKAIAFAIAFA AAa Aayd|VT"7q>3&&"t!	U4Za!e}	U4Z q	M8QKg $n 1~w&&r   )r   r   restartr   r   r   callback_typec                   Ub  U	c  Sn
[         R                  " U
[        SS9  U	c  Sn	U	S;  a  [        SU	< 35      eUc  Sn	[	        XX!5      u  ppnU R
                  nUR
                  n[        U5      n[        R                  R                  U5      n[        SUXC5      u  nnUS	:X  a
  U" U5      S	4$ [        R                  " UR                  R                  5      R                  n[        R                  " U5      (       a  [        R                   O[        R"                  nUc  US
-  nUc  Sn[%        X_5      n[        R                  R                  U" U5      5      nSnU[%        UUU-  5      -  nSn['        SUR                  S9n[        R(                  " US-   U/UR                  S9n[        R*                  " XUS-   /UR                  S9n[        R*                  " US/UR                  S9nS	n[-        U5       GH(  nUS	:X  a^  UR/                  5       (       a
  X" U5      -
  OUR1                  5       n[        R                  R                  U5      U:  a  U" U5      S	4s  $ U" W5      US	SS24'   [        R                  R                  US	SS24   5      nUS	SS24==   SU-  -  ss'   [        R*                  " US-   UR                  S9n UU S	'   Sn![-        U5       GH  n"U" UU"SS24   5      n#U" U#5      n$[        R                  R                  U$5      n%[-        U"S-   5       H)  n&U" UU&SS24   U$5      nUUU"U&4'   U$UUU&SS24   -  -  n$M+     [        R                  R                  U$5      n'U'UU"U"S-   4'   U$SS UU"S-   SS24'   U'UU%-  ::  a  S	UU"U"S-   4'   Sn!OUU"S-   SS24==   SU'-  -  ss'   [-        U"5       HO  n&UU&S	4   UU&S4   n)n(UU"U&U&S-   /4   u  n*n+U(U*-  U)U+-  -   U)R3                  5       * U*-  U(U+-  -   /UU"U&U&S-   /4'   MQ     U" UU"U"4   UU"U"S-   4   5      u  n(n)n,U(U)/UU"SS24'   U,S	4UU"U"U"S-   /4'   [        R4                  " U)5      * U U"   -  nU(U U"   -  U/U U"U"S-   /'   [        R6                  " U5      nUS-  nU	S;   a  U" UU-  5        U	S:X  a  UU:X  a    OUU::  d
  U!(       d  GM    O   UW"U"4   S	:X  a  S	U U"'   [        R*                  " U"S-   /UR                  S9n-U SU"S-    U-SS& [-        U"S	S5       H=  n&U-U&   S	:w  d  M  U-U&==   UU&U&4   -  ss'   U-U&   nU-SU&=== UUU&SU&24   -  -  sss& M?     U-S	   S	:w  a  U-S	==   US   -  ss'   UU-USU"S-   2SS24   -  -  nX" U5      -
  n[        R                  R                  U5      n.U	S:X  a  UU:X  a  U" U5      U.U::  a  S	4s  $ U4s  $ U	S:X  a  U" U5        U.U::  a    OEU!(       a    O<UU::  a  [9        USU-  5      nO[%        SSU-  5      nU[%        UUU.-  5      -  nGM+     W.U::  a  S	OUn/U" U5      U/4$ )a)  
Use Generalized Minimal RESidual iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real or complex N-by-N matrix of the linear system.
    Alternatively, `A` can be a linear operator which can
    produce ``Ax`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution (a vector of zeros by default).
atol, rtol : float
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
restart : int, optional
    Number of iterations between restarts. Larger values increase
    iteration cost, but may be necessary for convergence.
    If omitted, ``min(20, n)`` is used.
maxiter : int, optional
    Maximum number of iterations (restart cycles).  Iteration will stop
    after maxiter steps even if the specified tolerance has not been
    achieved. See `callback_type`.
M : {sparse array, ndarray, LinearOperator}
    Inverse of the preconditioner of `A`.  `M` should approximate the
    inverse of `A` and be easy to solve for (see Notes).  Effective
    preconditioning dramatically improves the rate of convergence,
    which implies that fewer iterations are needed to reach a given
    error tolerance.  By default, no preconditioner is used.
    In this implementation, left preconditioning is used,
    and the preconditioned residual is minimized. However, the final
    convergence is tested with respect to the ``b - A @ x`` residual.
callback : function
    User-supplied function to call after each iteration.  It is called
    as ``callback(args)``, where ``args`` are selected by `callback_type`.
callback_type : {'x', 'pr_norm', 'legacy'}, optional
    Callback function argument requested:
      - ``x``: current iterate (ndarray), called on every restart
      - ``pr_norm``: relative (preconditioned) residual norm (float),
        called on every inner iteration
      - ``legacy`` (default): same as ``pr_norm``, but also changes the
        meaning of `maxiter` to count inner iterations instead of restart
        cycles.

    This keyword has no effect if `callback` is not set.

Returns
-------
x : ndarray
    The converged solution.
info : int
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations

See Also
--------
LinearOperator

Notes
-----
A preconditioner, P, is chosen such that P is close to A but easy to solve
for. The preconditioner parameter required by this routine is
``M = P^-1``. The inverse should preferably not be calculated
explicitly.  Rather, use the following template to produce M::

  # Construct a linear operator that computes P^-1 @ x.
  import scipy.sparse.linalg as spla
  M_x = lambda x: spla.spsolve(P, x)
  M = spla.LinearOperator((n, n), M_x)

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import gmres
>>> A = csc_array([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float)
>>> b = np.array([2, 4, -1], dtype=float)
>>> x, exitCode = gmres(A, b, atol=1e-5)
>>> print(exitCode)            # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
Na2  scipy.sparse.linalg.gmres called without specifying `callback_type`. The default value will be changed in a future release. For compatibility, specify a value for `callback_type` explicitly, e.g., ``gmres(..., callback_type='pr_norm')``, or to retain the old behavior ``gmres(..., callback_type='legacy')``   )category
stacklevelr   )r9   pr_normr   zUnknown callback_type: r   r   r       g      ?r   lartg)r.   r   r!   FT)r   ri   )r   r   r9   g      ?g      ?)warningswarnDeprecationWarningr   r   r+   r'   r$   r%   r&   r   r-   r.   r/   r0   r(   r)   r*   minr   emptyzerosr3   r1   r2   r5   	conjugater4   r   )0r6   r7   r8   r   r   rc   r   r   r   rd   r   r9   r:   r+   r?   r=   r;   r<   r0   r>   Mb_nrm2ptol_max_factorptolpresidrk   rV   hgivens
inner_iterrG   rE   tmpS	breakdowncolavwh0kh1crX   n0n1magyr`   infos0                                                   r   r   r   F  s   r  5E 	c$61E 662=2CDEE)!6A!XXFXXFAAIINN1EWeT8GD!z1~q  
((177<<
 
$
$C++bggGB$'oGiinnVAY'G OS$,77DFWAGG4E 	'!)Qqww/A
'19%QWW5AXXwl!''2F J7^	>!"F1IaffhAyy~~a 4'"1~q(()!Q$iinnQq!tW%	!Q$AGHHWQYagg.!	>C#q&	"Br
A "B3q5\a1gq)#q&	S1a4[  "
 "B Ac37lOaDAcAgqjM SV|"##sQw, 	#'1*!b&) 3Zad|VAqD\13AaC=)B&'dQrTkAFFH9R<!B$3F%G#1q5z/"   aSk1S#a%Z=9IAq#VF36N#&6AcCQ<  <<?"1S6)C!"1S63AsC!GnVVC[F!OJ 55%((Z7-B~[ "f S#X;!AcFHHc!eWAGG,#a%y!sAr"Atqy!!Q$d"1Qq"1"uX%	 #
 Q419aDAdGOD	Q6CE619q	M		q! H$w)>q>1BB7BBCQKD= t^!#to'=>O!#s_'<=OOTE\::M $P $1WDq>4r   )r   r   r   M1M2r   c                  ^5 U m5[        U SX!5      u  p	pn[        R                  R                  U5      n[	        SXU5      u  pMUS:X  a
  U" U5      S4$ Uc  Uc  [        T5S5      (       aC  U54S jnU54S jnU54S jnU54S jn[        U R                  UUS	9n[        U R                  UUS	9nO-S
 n[        U R                  UUS	9n[        U R                  UUS	9n[        U5      nUc  US-  n[        R                  " U
5      (       a  [        R                  O[        R                  n[        R                  " U
R                  R                  5      R                  nUnUnUnUnUnU
R!                  5       (       a  XR#                  U
5      -
  OUR%                  5       nUR%                  5       nUR#                  U5      n[        R                  R                  U5      nUR%                  5       nUR'                  U5      n [        R                  R                  U 5      n!Su  n"n#n$[        R(                  " U5      n%[        R(                  " U5      n&Su  n'n(n)n*n+[+        U5       GHX  n,[        R                  R                  U5      U:  a  U" U
5      S4s  $ [        R,                  " U5      U:  a  U" U
5      S4s  $ [        R,                  " U!5      U:  a  U" U
5      S4s  $ USS U%SS& U%SU-  -  n%USU-  -  nUSS U&SS& U&SU!-  -  n&U SU!-  -  n U" U U5      n-[        R,                  " U-5      U:  a  U" U
5      S4s  $ UR#                  U5      n.UR'                  U 5      n/U,S:  a;  U.U!U--  U'-  U*-  -  n.U.SS U*SS& U/UU-U'-  R/                  5       -  U(-  -  n/U/SS U(SS& O U.R%                  5       n*U/R%                  5       n(U R#                  U*5      n0U" U(U05      n'[        R,                  " U'5      U:  a  U" U
5      S4s  $ U'U--  n1[        R,                  " U15      U:  a  U" U
5      S4s  $ U0SS USS& UU1U%-  -  nUR#                  U5      nUn2[        R                  R                  U5      nU&SS USS& UU1R/                  5       * -  nUU R'                  U(5      -  nUR'                  U5      n [        R                  R                  U 5      n!U"n3U$n4UU3[        R,                  " U15      -  -  n$S[        R0                  " SU$S-  -   5      -  n"[        R,                  " U"5      U:  a  U" U
5      S4s  $ U#U2U1-  * U"U3-  S-  -  -  n#U,S:  a'  U)U4U"-  S-  -  n)U)U#U*-  -  n)U+U4U"-  S-  -  n+U+U#U0-  -  n+O*U*R%                  5       n)U)U#-  n)U0R%                  5       n+U+U#-  n+U
U)-  n
UU+-  nU(       d  GMP  U" U
5        GM[     U" U
5      U4$ )a]  Use Quasi-Minimal Residual iteration to solve ``Ax = b``.

Parameters
----------
A : {sparse array, ndarray, LinearOperator}
    The real-valued N-by-N matrix of the linear system.
    Alternatively, ``A`` can be a linear operator which can
    produce ``Ax`` and ``A^T x`` using, e.g.,
    ``scipy.sparse.linalg.LinearOperator``.
b : ndarray
    Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : ndarray
    Starting guess for the solution.
atol, rtol : float, optional
    Parameters for the convergence test. For convergence,
    ``norm(b - A @ x) <= max(rtol*norm(b), atol)`` should be satisfied.
    The default is ``atol=0.`` and ``rtol=1e-5``.
maxiter : integer
    Maximum number of iterations.  Iteration will stop after maxiter
    steps even if the specified tolerance has not been achieved.
M1 : {sparse array, ndarray, LinearOperator}
    Left preconditioner for A.
M2 : {sparse array, ndarray, LinearOperator}
    Right preconditioner for A. Used together with the left
    preconditioner M1.  The matrix M1@A@M2 should have better
    conditioned than A alone.
callback : function
    User-supplied function to call after each iteration.  It is called
    as callback(xk), where xk is the current solution vector.

Returns
-------
x : ndarray
    The converged solution.
info : integer
    Provides convergence information:
        0  : successful exit
        >0 : convergence to tolerance not achieved, number of iterations
        <0 : parameter breakdown

See Also
--------
LinearOperator

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import csc_array
>>> from scipy.sparse.linalg import qmr
>>> A = csc_array([[3., 2., 0.], [1., -1., 0.], [0., 5., 1.]])
>>> b = np.array([2., 4., -1.])
>>> x, exitCode = qmr(A, b, atol=1e-5)
>>> print(exitCode)            # 0 indicates successful convergence
0
>>> np.allclose(A.dot(x), b)
True
Nr   r   r?   c                 (   > TR                  U S5      $ Nleftr?   r7   A_s    r   left_psolveqmr.<locals>.left_psolve  s    yyF++r   c                 (   > TR                  U S5      $ Nrightr   r   s    r   right_psolveqmr.<locals>.right_psolve  s    yyG,,r   c                 (   > TR                  U S5      $ r   r@   r   s    r   left_rpsolveqmr.<locals>.left_rpsolve  s    zz!V,,r   c                 (   > TR                  U S5      $ r   r   r   s    r   right_rpsolveqmr.<locals>.right_rpsolve  s    zz!W--r   )r+   r,   c                     U $ N )r7   s    r   idqmr.<locals>.id  s    r   r    )r   rl   r   rQ   r"   ir   iir#   r!   i)r   r$   r%   r&   r   hasattrr   shaper'   r(   r)   r*   r-   r.   r/   r0   r1   r+   r2   r,   rS   r3   r4   r5   sqrt)6r6   r7   r8   r   r   r   r   r   r   r   r9   r:   r;   r<   r   r   r   r   r   r=   r>   rA   betatolgammatoldeltatol
epsilontolxitolrE   vtilder   rW   wtilderH   xigammaetathetarV   r   epsilonrL   drC   rX   rG   deltaytilderI   rD   rK   rB   
gamma_prev
theta_prevr   s6                                                        @r   r   r   L  ss   v 
B)!T29A!IINN1EUE6GDz1~q  	zbj2x  ,--.'2(46B  '3(57BB?BB?BAAB$++bggGXXaggll#''FGHHJE5577HHQKAVVXF
		&A
))..
CVVXF


6A		B E3
fA
fA 7GQ1a7^	99>>!t#q>1$$66#;q>3&&66":q>3&&ay!	a#g	a#gay!	a"f	a"f166%=8#q>3&&1Aq=rEzG+q00F!9AaDsego3355::F!9AaDAA!!V$66'?Z'q>3&&66$<'!q>3&&1Iq	$q&IIfiinnQaDq	DIIK-!))A,JJvYY^^A

zBFF4L01BGGAqL))66%=8#q>3&&D!UZ%7!$;;;q=*u$**AQJA*u$**AVOAAHAAHA	Q	Q8QKY $` 1~w&&r   )r   r   r   )rm   numpyr$   scipy.sparse.linalg._interfacer   utilsr   scipy.linalgr   __all__r   r   r   r	   r
   r   r   r   r   r   <module>r      s      9  )
;B'2ttd B'JQ'Dr44Q'hu'dTTD u'pZ't"ddT Z'zC BddtC LI't"dtI'r   