o
    lÇhNi  ã                   @   s0   d Z ddlmZ ddlmZ G dd„ deƒZdS )a¸  
Linear algebra
--------------

Linear equations
................

Basic linear algebra is implemented; you can for example solve the linear
equation system::

      x + 2*y = -10
    3*x + 4*y =  10

using ``lu_solve``::

    >>> from mpmath import *
    >>> mp.pretty = False
    >>> A = matrix([[1, 2], [3, 4]])
    >>> b = matrix([-10, 10])
    >>> x = lu_solve(A, b)
    >>> x
    matrix(
    [['30.0'],
     ['-20.0']])

If you don't trust the result, use ``residual`` to calculate the residual ||A*x-b||::

    >>> residual(A, x, b)
    matrix(
    [['3.46944695195361e-18'],
     ['3.46944695195361e-18']])
    >>> str(eps)
    '2.22044604925031e-16'

As you can see, the solution is quite accurate. The error is caused by the
inaccuracy of the internal floating point arithmetic. Though, it's even smaller
than the current machine epsilon, which basically means you can trust the
result.

If you need more speed, use NumPy, or ``fp.lu_solve`` for a floating-point computation.

    >>> fp.lu_solve(A, b)   # doctest: +ELLIPSIS
    matrix(...)

``lu_solve`` accepts overdetermined systems. It is usually not possible to solve
such systems, so the residual is minimized instead. Internally this is done
using Cholesky decomposition to compute a least squares approximation. This means
that that ``lu_solve`` will square the errors. If you can't afford this, use
``qr_solve`` instead. It is twice as slow but more accurate, and it calculates
the residual automatically.


Matrix factorization
....................

The function ``lu`` computes an explicit LU factorization of a matrix::

    >>> P, L, U = lu(matrix([[0,2,3],[4,5,6],[7,8,9]]))
    >>> print(P)
    [0.0  0.0  1.0]
    [1.0  0.0  0.0]
    [0.0  1.0  0.0]
    >>> print(L)
    [              1.0                0.0  0.0]
    [              0.0                1.0  0.0]
    [0.571428571428571  0.214285714285714  1.0]
    >>> print(U)
    [7.0  8.0                9.0]
    [0.0  2.0                3.0]
    [0.0  0.0  0.214285714285714]
    >>> print(P.T*L*U)
    [0.0  2.0  3.0]
    [4.0  5.0  6.0]
    [7.0  8.0  9.0]

Interval matrices
-----------------

Matrices may contain interval elements. This allows one to perform
basic linear algebra operations such as matrix multiplication
and equation solving with rigorous error bounds::

    >>> a = iv.matrix([['0.1','0.3','1.0'],
    ...             ['7.1','5.5','4.8'],
    ...             ['3.2','4.4','5.6']])
    >>>
    >>> b = iv.matrix(['4','0.6','0.5'])
    >>> c = iv.lu_solve(a, b)
    >>> print(c)
    [   [5.2582327113062568605927528666, 5.25823271130625686059275702219]]
    [[-13.1550493962678375411635581388, -13.1550493962678375411635540152]]
    [  [7.42069154774972557628979076189, 7.42069154774972557628979190734]]
    >>> print(a*c)
    [  [3.99999999999999999999999844904, 4.00000000000000000000000155096]]
    [[0.599999999999999999999968898009, 0.600000000000000000000031763736]]
    [[0.499999999999999999999979320485, 0.500000000000000000000020679515]]
é    )Úcopyé   )Úxrangec                   @   s¢   e Zd Zd)dd„Zd*dd„Zdd	„ Zd
d„ Zd+dd„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zd*dd„Zd*dd„Zdd„ Zdd „ Zd*d!d"„Zd#d$„ Zd,d'd(„ZdS )-ÚLinearAlgebraMethodsFTc              
      sÜ  ˆ j ˆ jks
tdƒ‚|rtˆ ˆjƒrˆ jrˆ jS |s ˆ }ˆ  ¡ ‰ ˆ ˆ ˆ d¡ˆj	 ¡}ˆ j }dg|d  }t
|d ƒD ]}d}	t
||ƒD ]5‰ˆ ‡ ‡‡fdd„t
||ƒD ƒ¡}
ˆ |
¡|krctdƒ‚d|
 ˆ ˆ ˆ|f ¡ }||	krz|}	ˆ||< qEˆ ˆ ||| ¡ ˆ ˆ ||f ¡|kr“tdƒ‚t
|d |ƒD ].}ˆ ||f  ˆ ||f   < t
|d |ƒD ]‰ˆ |ˆf  ˆ ||f ˆ |ˆf  8  < q±qšq<ˆ ˆ |d |d f ¡|krÝtdƒ‚|sêt|ˆjƒrêˆ |f|_ˆ |fS )zØ
        LU-factorization of a n*n matrix using the Gauss algorithm.
        Returns L and U in one matrix and the pivot indices.

        Use overwrite to specify whether A will be overwritten with L and U.
        úneed n*n matrixé   Nr   c                    s   g | ]}ˆ  ˆ ˆ|f ¡‘qS © )Úabsmin)Ú.0Úl©ÚAÚctxÚkr   új/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/mpmath/matrices/linalg.pyÚ
<listcomp>„   s    z2LinearAlgebraMethods.LU_decomp.<locals>.<listcomp>úmatrix is numerically singular)ÚrowsÚcolsÚ
ValueErrorÚ
isinstanceÚmatrixÚ_LUr   r	   ÚmnormÚepsr   ÚfsumÚZeroDivisionErrorÚswap_row)r   r   Ú	overwriteÚ	use_cacheÚorigÚtolÚnÚpÚjÚbiggestÚsÚcurrentÚir   r   r   Ú	LU_decompn   sF   "€*ÿþ
zLinearAlgebraMethods.LU_decompNc                 C   s¢   |j |jkr
tdƒ‚|j }t|ƒ|krtdƒ‚t|ƒ}|r0tdt|ƒƒD ]}|  |||| ¡ q$td|ƒD ]}t|ƒD ]}||  |||f ||  8  < q;q5|S )zG
        Solve the lower part of a LU factorized matrix for y.
        r   úValue should be equal to nr   r   )r   r   ÚRuntimeErrorÚlenr   r   r   r   )r   ÚLÚbr#   r"   r   r(   r$   r   r   r   ÚL_solve›   s   "ÿzLinearAlgebraMethods.L_solvec                 C   sœ   |j |jkr
tdƒ‚|j }t|ƒ|krtdƒ‚t|ƒ}t|d ddƒD ](}t|d |ƒD ]}||  |||f ||  8  < q,||  |||f   < q#|S )zG
        Solve the upper part of a LU factorized matrix for x.
        r   r*   r   éÿÿÿÿ)r   r   r+   r,   r   r   r   )r   ÚUÚyr"   Úxr(   r$   r   r   r   ÚU_solve®   s   "zLinearAlgebraMethods.U_solvec                    s  ˆ j }z~ˆ  j d7  _ ˆ j|fi |¤Ž ¡ ˆ j|fi |¤Ž ¡ }}|j|jk r,tdƒ‚|j|jkr\|j}|| }|| }| dd¡sNt‡ fdd„|D ƒƒsUˆ  	||¡}n'ˆ  
||¡}nˆ  |¡\}}ˆ  |||¡}ˆ  ||¡}W |ˆ _ |S W |ˆ _ |S W |ˆ _ |S |ˆ _ w )aÑ  
        Ax = b => x

        Solve a determined or overdetermined linear equations system.
        Fast LU decomposition is used, which is less accurate than QR decomposition
        (especially for overdetermined systems), but it's twice as efficient.
        Use qr_solve if you want more precision or have to solve a very ill-
        conditioned system.

        If you specify real=True, it does not check for overdeterminded complex
        systems.
        é
   ú#cannot solve underdetermined systemÚrealFc                 3   ó    | ]
}t |ƒˆ ju V  qd S ©N©ÚtypeÚmpc©r
   r(   ©r   r   r   Ú	<genexpr>Ù   ó   € z0LinearAlgebraMethods.lu_solve.<locals>.<genexpr>)Úprecr   r   r   r   r   ÚHÚgetÚsumÚcholesky_solveÚlu_solver)   r/   r4   )r   r   r.   ÚkwargsrA   ÚAHr3   r#   r   r>   r   rF   ¾   s6   .ÿøö	ÿzLinearAlgebraMethods.lu_solver   c                 C   sf   |j |jkr
tdƒ‚t|ƒD ]"}|  |||¡}|  |d¡d| j k r% |S |  || ¡}||7 }q|S )zÔ
        Improve a solution to a linear equation system iteratively.

        This re-uses the LU decomposition and is thus cheap.
        Usually 3 up to 4 iterations are giving the maximal improvement.
        r   r   r5   )r   r   r+   r   ÚresidualÚnormr   rF   )r   r   r3   r.   ÚmaxstepsÚ_ÚrÚdxr   r   r   Úimprove_solutionç   s   þ
z%LinearAlgebraMethods.improve_solutionc           
      C   sØ   |   |¡\}}|j}|  |¡}|  |¡}t|ƒD ]7}t|ƒD ]0}||kr/|||f |||f< q||krDd|||f< |||f |||f< q|||f |||f< qq|  |¡}tt|ƒƒD ]}	|  ||	||	 ¡ q[|||fS )a7  
        A -> P, L, U

        LU factorisation of a square matrix A. L is the lower, U the upper part.
        P is the permutation matrix indicating the row swaps.

        P*A = L*U

        If you need efficiency, use the low-level method LU_decomp instead, it's
        much more memory efficient.
        r   )r)   r   r   r   Úeyer,   r   )
r   r   r#   r"   r-   r1   r(   r$   ÚPr   r   r   r   Úluù   s"   

ù
	
zLinearAlgebraMethods.luc                 C   sL   d|  k r|ksJ dƒ‚ J dƒ‚| j g|d  | jg | j g||   S )z<
        Return the i-th n-dimensional unit vector.
        r   zthis unit vector does not existr   )ÚzeroÚone)r   r"   r(   r   r   r   Ú
unitvector  s   $(zLinearAlgebraMethods.unitvectorc                 K   sê   | j }zm|  j d7  _ | j|fi |¤Ž ¡ }|j}|  |¡\}}g }td|d ƒD ]}|  ||¡}|  |||¡}	| |  	||	¡¡ q)g }
t|ƒD ]}g }t|ƒD ]}| || | ¡ qP|
 |¡ qH| j|
fi |¤Ž}W || _ |S || _ w )zÅ
        Calculate the inverse of a matrix.

        If you want to solve an equation system Ax = b, it's recommended to use
        solve(A, b) instead, it's about 3 times more efficient.
        r5   r   )
rA   r   r   r   r)   r   rU   r/   Úappendr4   )r   r   rG   rA   r"   r#   r   r(   Úer2   ÚinvÚrowr$   Úresultr   r   r   Úinverse   s*   ÿzLinearAlgebraMethods.inversec                    s  t ˆ ˆjƒs
tdƒ‚ˆ j‰ˆ j‰ˆˆd k rtdƒ‚g }tdˆd ƒD ]ƒ‰ˆ ‡ ‡fdd„tˆˆƒD ƒ¡}t|ƒˆj	ks@t
dƒ‚| ˆ ˆ ˆ ˆˆf ¡¡ ˆ |¡ ¡ ˆj||ˆ ˆ ˆˆf    }ˆ ˆˆf  |ˆ 8  < tˆd ˆƒD ].‰ˆ ‡ ‡‡‡fdd„tˆˆƒD ƒ¡| }tˆˆƒD ]‰ˆ ˆˆf  ˆ ˆˆf | 8  < q’qwq#‡ ‡fd	d
„tˆd ƒD ƒ‰tˆd ddƒD ]'‰ˆˆ  ˆ ‡ ‡‡fdd„tˆd ˆd ƒD ƒ¡8  < ˆˆ  |ˆ   < q½ˆˆd ksý‡ ‡‡fdd
„tˆˆ d ƒD ƒ}ndgˆ }ˆ |ˆ|fS )a  
        (A|b) -> H, p, x, res

        (A|b) is the coefficient matrix with left hand side of an optionally
        overdetermined linear equation system.
        H and p contain all information about the transformation matrices.
        x is the solution, res the residual.
        ú A should be a type of ctx.matrixr   z$Columns should not be less than rowsr   c                 3   s$    | ]}t ˆ |ˆf ƒd  V  qdS ©r   N)Úabsr=   ©r   r$   r   r   r?   S  ó   €" z3LinearAlgebraMethods.householder.<locals>.<genexpr>r   c                 3   s.    | ]}ˆ  ˆ |ˆf ¡ˆ |ˆf  V  qd S r9   ©Úconjr=   ©r   r   r$   r   r   r   r?   Z  ó   €, c                    s   g | ]
}ˆ |ˆd  f ‘qS ©r   r   r=   )r   r"   r   r   r   ^  s    z4LinearAlgebraMethods.householder.<locals>.<listcomp>r   r0   c                 3   s$    | ]}ˆ ˆ|f ˆ|  V  qd S r9   r   ©r
   r$   )r   r(   r3   r   r   r?   `  r`   c                    s$   g | ]}ˆ ˆd  | ˆd  f ‘qS re   r   r=   )r   Úmr"   r   r   r   d  s   $ )r   r   Ú	TypeErrorr   r   r+   r   r   r^   r   r   rV   ÚsignÚreÚsqrtrT   )r   r   r#   r&   Úkappar2   rM   r   )r   r   r(   r$   r   rg   r"   r3   r   ÚhouseholderA  s8   	 *("ÿþ6$
z LinearAlgebraMethods.householderc                 K   sl   | j }z.|  j d9  _ | j|fi |¤Ž| j|fi |¤Ž| j|fi |¤Ž}}}|| | W || _ S || _ w )zt
        Calculate the residual of a solution to a linear equation system.

        r = A*x - b for A*x = b
        r   )rA   r   )r   r   r3   r.   rG   Úoldprecr   r   r   rI   v  s   :zLinearAlgebraMethods.residualc                 K   sÌ   |du r| j }| j}zW|  jd7  _| j|fi |¤Ž ¡ | j|fi |¤Ž ¡ }}|j|jk r3tdƒ‚|  |  ||¡¡\}}}}	|   |	¡}
|
dkrS|   |  	|||¡¡}
| j|fi |¤Ž|
fW || _S || _w )aa  
        Ax = b => x, ||Ax - b||

        Solve a determined or overdetermined linear equations system and
        calculate the norm of the residual (error).
        QR decomposition using Householder factorization is applied, which gives very
        accurate results even for ill-conditioned matrices. qr_solve is twice as
        efficient.
        Nr5   r6   r   )
rJ   rA   r   r   r   r   r   rm   ÚextendrI   )r   r   r.   rJ   rG   rA   rB   r#   r3   rM   Úresr   r   r   Úqr_solve„  s   
.
zLinearAlgebraMethods.qr_solvec           	         sJ  t || jƒs
tdƒ‚|j|jkstdƒ‚|du r| j
 }|j}|  |¡‰ t|ƒD ]z‰|  |ˆˆf ¡}t	||ˆˆf  ƒ|krCtdƒ‚|| j
‡ ‡fdd„tˆƒD ƒddd }||k r_td	ƒ‚|  |¡ˆ ˆˆf< tˆ|ƒD ]4‰‡ ‡fd
d„tˆƒD ƒ}‡ ‡fdd„tˆƒD ƒ}| j||dd}|ˆˆf | ˆ ˆˆf  ˆ ˆˆf< qmq(ˆ S )a}  
        Cholesky decomposition of a symmetric positive-definite matrix `A`.
        Returns a lower triangular matrix `L` such that `A = L \times L^T`.
        More generally, for a complex Hermitian positive-definite matrix,
        a Cholesky decomposition satisfying `A = L \times L^H` is returned.

        The Cholesky decomposition can be used to solve linear equation
        systems twice as efficiently as LU decomposition, or to
        test whether `A` is positive-definite.

        The optional parameter ``tol`` determines the tolerance for
        verifying positive-definiteness.

        **Examples**

        Cholesky decomposition of a positive-definite symmetric matrix::

            >>> from mpmath import *
            >>> mp.dps = 25; mp.pretty = True
            >>> A = eye(3) + hilbert(3)
            >>> nprint(A)
            [     2.0      0.5  0.333333]
            [     0.5  1.33333      0.25]
            [0.333333     0.25       1.2]
            >>> L = cholesky(A)
            >>> nprint(L)
            [ 1.41421      0.0      0.0]
            [0.353553  1.09924      0.0]
            [0.235702  0.15162  1.05899]
            >>> chop(A - L*L.T)
            [0.0  0.0  0.0]
            [0.0  0.0  0.0]
            [0.0  0.0  0.0]

        Cholesky decomposition of a Hermitian matrix::

            >>> A = eye(3) + matrix([[0,0.25j,-0.5j],[-0.25j,0,0],[0.5j,0,0]])
            >>> L = cholesky(A)
            >>> nprint(L)
            [          1.0                0.0                0.0]
            [(0.0 - 0.25j)  (0.968246 + 0.0j)                0.0]
            [ (0.0 + 0.5j)  (0.129099 + 0.0j)  (0.856349 + 0.0j)]
            >>> chop(A - L*L.H)
            [0.0  0.0  0.0]
            [0.0  0.0  0.0]
            [0.0  0.0  0.0]

        Attempted Cholesky decomposition of a matrix that is not positive
        definite::

            >>> A = -eye(3) + hilbert(3)
            >>> L = cholesky(A)
            Traceback (most recent call last):
              ...
            ValueError: matrix is not positive-definite

        **References**

        1. [Wikipedia]_ http://en.wikipedia.org/wiki/Cholesky_decomposition

        r\   r   Nzmatrix is not Hermitianc                 3   ó    | ]	}ˆ ˆ|f V  qd S r9   r   ©r
   r   ©r-   r$   r   r   r?   ê  ó   € z0LinearAlgebraMethods.cholesky.<locals>.<genexpr>T)ÚabsoluteÚsquaredzmatrix is not positive-definitec                 3   rr   r9   r   rs   )r-   r(   r   r   r?   ð  ru   c                 3   rr   r9   r   rs   rt   r   r   r?   ñ  ru   )Ú	conjugate)r   r   r+   r   r   r   r   r   rj   r^   r   rk   Úfdot)	r   r   r!   r"   Úcr&   Úit1Úit2Útr   )r-   r(   r$   r   Úcholesky   s2   >
ÿ&üzLinearAlgebraMethods.choleskyc              	      sð   | j }zp|  j d7  _ | j|fi |¤Ž ¡ | jˆfi |¤Ž ¡ }‰|j|jkr,tdƒ‚|  |¡‰ ˆ j}tˆƒ|kr>tdƒ‚t|ƒD ]$‰ˆˆ  |  	‡ ‡‡fdd„tˆƒD ƒ¡8  < ˆˆ  ˆ ˆˆf   < qB|  
ˆ jˆ¡}|W || _ S || _ w )zø
        Ax = b => x

        Solve a symmetric positive-definite linear equation system.
        This is twice as efficient as lu_solve.

        Typical use cases:
        * A.T*A
        * Hessian matrix
        * differential equations
        r5   z can only solve determined systemr*   c                 3   s$    | ]}ˆ ˆ|f ˆ|  V  qd S r9   r   rf   ©r-   r.   r(   r   r   r?     r`   z6LinearAlgebraMethods.cholesky_solve.<locals>.<genexpr>)rA   r   r   r   r   r   r~   r,   r   r   r4   ÚT)r   r   r.   rG   rA   r"   r3   r   r   r   rE   ö  s    .
,z#LinearAlgebraMethods.cholesky_solvec                 C   s    | j }zH|  |¡ ¡ }z	|  |¡\}}W n ty"   Y W || _ dS w d}t|ƒD ]\}}||kr5|d9 }q)t|jƒD ]
}||||f 9 }q;|W || _ S || _ w )z8
        Calculate the determinant of a matrix.
        r   r   r0   )rA   r   r   r)   r   Ú	enumerater   r   )r   r   rA   ÚRr#   Úzr(   rW   r   r   r   Údet  s$   
	ö€zLinearAlgebraMethods.detc                    s*   |du r
‡ fdd„}||ƒ|ˆ   |¡ƒ S )a)  
        Calculate the condition number of a matrix using a specified matrix norm.

        The condition number estimates the sensitivity of a matrix to errors.
        Example: small input errors for ill-conditioned coefficient matrices
        alter the solution of the system dramatically.

        For ill-conditioned matrices it's recommended to use qr_solve() instead
        of lu_solve(). This does not help with input errors however, it just avoids
        to add additional errors.

        Definition:    cond(A) = ||A|| * ||A**-1||
        Nc                    s   ˆ   | d¡S )Nr   )r   )r3   r>   r   r   Ú<lambda>=  s    z+LinearAlgebraMethods.cond.<locals>.<lambda>)r[   )r   r   rJ   r   r>   r   Úcond.  s   zLinearAlgebraMethods.condc                 C   sX   |   |j|j¡}t|jƒD ]}|  || |¡¡}tt|ƒƒD ]
}|| |||f< qq|S )z,Solve a * x = b  where a and b are matrices.)r   r   r   ÚrangerF   Úcolumnr,   )r   Úar.   rM   r(   rz   r$   r   r   r   Úlu_solve_mat@  s   ÿz!LinearAlgebraMethods.lu_solve_matÚfullr5   c              
      sh  t ˆ ˆjƒsJ ‚ˆ j}ˆ j}|dksJ ‚||ksJ ‚|dks J ‚t‡fdd„ˆ D ƒƒ}ˆ |¡ø ˆ |d¡}ˆ  ¡ ‰ |r;ˆ dd¡}ˆ dd¡}	ˆ d¡}
t	d|ƒD ]ä‰ˆ ˆˆf }ˆ 
|¡}ˆ |¡}|ˆ dkr‰ˆ ‡ ‡‡fdd„t	ˆd |ƒD ƒ¡}ˆ 
ˆ |¡¡}n|
}||
kr˜||
kr˜|	|ˆ< qU||
k r¬ˆ |d |d  |d  ¡}nˆ |d |d  |d  ¡ }ˆ || | | | ¡|ˆ< ˆ |ˆ ¡ }|||  }t	ˆd |ƒD ]}ˆ |ˆf  |9  < qà|ˆ ˆˆf< t	ˆd |ƒD ]4‰ˆ ‡ ‡‡‡fd	d„t	ˆ|ƒD ƒ¡}|ˆ |¡ }t	ˆ|ƒD ]}ˆ |ˆf  ˆ |ˆf | 7  < qqúˆ |d¡ˆ ˆˆf< qUnáˆ d¡}ˆ d¡}	t	d|ƒD ]Ñ‰ˆ ˆˆf }|ˆ dkrqˆ ‡ ‡fd
d„t	ˆd |ƒD ƒ¡}ˆ |¡}n|ˆ dkrƒtˆ |d ˆf ƒ}n|	}||	kr|	|ˆ< qJ||	k r¡ˆ |d |d  ¡}nˆ |d |d  ¡ }|| | |ˆ< |ˆ  }|||  }t	ˆd |ƒD ]}ˆ |ˆf  |9  < qÇ|ˆ ˆˆf< t	ˆd |ƒD ]1‰ˆ ‡ ‡‡fdd„t	ˆ|ƒD ƒ¡}|| }t	ˆ|ƒD ]}ˆ |ˆf  ˆ |ˆf | 7  < qþqâ|ˆ ˆˆf< qJ|dks&|dkr1ˆ |fW  d  ƒ S ˆ  ¡ }t	d|ƒD ]‰t	ˆd |ƒD ]	}|	||ˆf< qCq:|}|dks[|dkr]|}ˆ  j|| 7  _t	d|ƒD ]‰|ˆ ˆˆf< t	dˆƒD ]	}|	ˆ |ˆf< qxqkt	|d ddƒD ]‰‰|ˆ  }ˆ ˆˆf  |7  < t	ˆd |ƒD ]Z‰|rÅˆ ‡ ‡‡‡fdd„t	ˆd |ƒD ƒ¡}|ˆ |¡ }nˆ ‡ ‡‡fdd„t	ˆd |ƒD ƒ¡}|| }|ˆ ˆˆf< t	ˆd |ƒD ]}ˆ |ˆf  ˆ |ˆf | 7  < qéq¤t	ˆd |ƒD ]}ˆ |ˆf  |9  < qqŒˆ |d|…d|…f fW  d  ƒ S 1 s-w   Y  dS )al  
        Compute a QR factorization $A = QR$ where
        A is an m x n matrix of real or complex numbers where m >= n

        mode has following meanings:
        (1) mode = 'raw' returns two matrixes (A, tau) in the
            internal format used by LAPACK
        (2) mode = 'skinny' returns the leading n columns of Q
            and n rows of R
        (3) Any other value returns the leading m columns of Q
            and m rows of R

        edps is the increase in mp precision used for calculations

        **Examples**

            >>> from mpmath import *
            >>> mp.dps = 15
            >>> mp.pretty = True
            >>> A = matrix([[1, 2], [3, 4], [1, 1]])
            >>> Q, R = qr(A)
            >>> Q
            [-0.301511344577764   0.861640436855329   0.408248290463863]
            [-0.904534033733291  -0.123091490979333  -0.408248290463863]
            [-0.301511344577764  -0.492365963917331   0.816496580927726]
            >>> R
            [-3.3166247903554  -4.52267016866645]
            [             0.0  0.738548945875996]
            [             0.0                0.0]
            >>> Q * R
            [1.0  2.0]
            [3.0  4.0]
            [1.0  1.0]
            >>> chop(Q.T * Q)
            [1.0  0.0  0.0]
            [0.0  1.0  0.0]
            [0.0  0.0  1.0]
            >>> B = matrix([[1+0j, 2-3j], [3+j, 4+5j]])
            >>> Q, R = qr(B)
            >>> nprint(Q)
            [     (-0.301511 + 0.0j)   (0.0695795 - 0.95092j)]
            [(-0.904534 - 0.301511j)  (-0.115966 + 0.278318j)]
            >>> nprint(R)
            [(-3.31662 + 0.0j)  (-5.72872 - 2.41209j)]
            [              0.0       (3.91965 + 0.0j)]
            >>> Q * R
            [(1.0 + 0.0j)  (2.0 - 3.0j)]
            [(3.0 + 1.0j)  (4.0 + 5.0j)]
            >>> chop(Q.T * Q.conjugate())
            [1.0  0.0]
            [0.0  1.0]

        r   c                 3   r8   r9   r:   )r
   r3   r>   r   r   r?   ‰  r@   z*LinearAlgebraMethods.qr.<locals>.<genexpr>r   z1.0z0.0r   c                 3   s.    | ]}ˆ |ˆf ˆ  ˆ |ˆf ¡ V  qd S r9   ra   r=   )r   r   r$   r   r   r?   Ÿ  rd   c                 3   ó.    | ]}ˆ |ˆf ˆ  ˆ |ˆf ¡ V  qd S r9   ra   r=   rc   r   r   r?   ¶  rd   c                 3   s     | ]}ˆ |ˆf d  V  qdS r]   r   r=   r_   r   r   r?   Å  s   € c                 3   ó(    | ]}ˆ |ˆf ˆ |ˆf  V  qd S r9   r   r=   ©r   r$   r   r   r   r?   Þ  ó   €& ÚrawÚRAWNÚskinnyÚSKINNYr0   c                 3   rŒ   r9   ra   r=   rc   r   r   r?     rd   c                 3   r   r9   r   r=   rŽ   r   r   r?   	  r   )r   r   r   r   ÚanyÚextradpsr   r<   Úmpfr   rj   Úimr   rk   rb   r^   )r   r   ÚmodeÚedpsrg   r"   ÚcmplxÚtaurT   rS   ÚrzeroÚalphaÚalphrÚalphiÚxnormÚbetar}   Úzar(   r2   ÚtempÚdar‚   r#   r   rc   r   ÚqrI  sÖ   8


&  $$ÿÞ
$
$


"$ÿ¥bÿÿ
(&$ÿÿ &ùzLinearAlgebraMethods.qr)FTr9   re   )r‹   r5   )Ú__name__Ú
__module__Ú__qualname__r)   r/   r4   rF   rO   rR   rU   r[   rm   rI   rq   r~   rE   r„   r†   rŠ   r¥   r   r   r   r   r   l   s$    

-
) !5

V!
	r   N)Ú__doc__r   Úlibmp.backendr   Úobjectr   r   r   r   r   Ú<module>   s    g