§
    ¢éUgM:  ã                   óX   — d Z ddlZddlmZ ddlmZ g d¢Zd„ Z	 	 dd„Z		 	 dd„Z
dd„ZdS )zQR decomposition functions.é    Né   )Úget_lapack_funcs)Ú_datacopied)ÚqrÚqr_multiplyÚrqc                 ó(  — |                      dd¦  «        }|dv r@d|d<    | |i |¤Ž}|d         d         j                             t          j        ¦  «        |d<    | |i |¤Ž}|d         dk     rt          d|d          |fz  ¦  «        ‚|dd…         S )z[Call a LAPACK routine, determining lwork automatically and handling
    error return valuesÚlworkN)Néÿÿÿÿr   éþÿÿÿr   z-illegal value in %dth argument of internal %s)ÚgetÚrealÚastypeÚnpÚint_Ú
ValueError)ÚfÚnameÚargsÚkwargsr
   Úrets         úV/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/linalg/_decomp_qr.pyÚsafecallr      s¸   € ð �JŠJ�w Ñ%Ô%€EØ�
ÐÐØˆˆw‰Øˆa�Ð ˜Ð Ð ˆØ˜bœ' !œ*œ/×0Ò0µ´Ñ9Ô9ˆˆw‰Ø
ˆ!ˆTÐ
�VÐ
Ð
€CØ
ˆ2„w�‚{€{ÝÐHØ  œW˜H dÐ+ñ,ñ -ô -ð 	-àˆs�ˆsŒ8€Oó    FÚfullTc                 óÔ  — |dvrt          d¦  «        ‚|rt          j        | ¦  «        }nt          j        | ¦  «        }t	          |j        ¦  «        dk    rt          d¦  «        ‚|j        \  }}|j        dk    rût          ||¦  «        }	|dvrDt          j        |||f¬¦  «        }
t          j	        |¦  «        |
d<   t          j        |¦  «        }n0t          j        |||	f¬¦  «        }
t          j        ||	|f¬¦  «        }|r#|t          j
        |t          j        ¬	¦  «        f}n|f}|d
k    r|S |dk    r7t          j        |||f¬¦  «        }t          j        ||	f¬¦  «        }||ff|z   S |
f|z   S |pt          || ¦  «        }|r0t          d|f¦  «        \  }t          |d||¬¦  «        \  }}}|dz  }n*t          d|f¦  «        \  }t          |d|||¬¦  «        \  }}|dvs||k     rt          j        |¦  «        }n t          j        |d|…dd…f         ¦  «        }|r||f}n|f}|d
k    r|S |dk    r||ff|z   S t          d|f¦  «        \  }||k     r$t          |d|dd…d|…f         ||d¬¦  «        \  }
nd|dk    rt          |d|||d¬¦  «        \  }
nF|j        j        }t          j        ||f|¬	¦  «        }||dd…d|…f<   t          |d|||d¬¦  «        \  }
|
f|z   S )aG  
    Compute QR decomposition of a matrix.

    Calculate the decomposition ``A = Q R`` where Q is unitary/orthogonal
    and R upper triangular.

    Parameters
    ----------
    a : (M, N) array_like
        Matrix to be decomposed
    overwrite_a : bool, optional
        Whether data in `a` is overwritten (may improve performance if
        `overwrite_a` is set to True by reusing the existing input data
        structure rather than creating a new one.)
    lwork : int, optional
        Work array size, lwork >= a.shape[1]. If None or -1, an optimal size
        is computed.
    mode : {'full', 'r', 'economic', 'raw'}, optional
        Determines what information is to be returned: either both Q and R
        ('full', default), only R ('r') or both Q and R but computed in
        economy-size ('economic', see Notes). The final option 'raw'
        (added in SciPy 0.11) makes the function return two matrices
        (Q, TAU) in the internal format used by LAPACK.
    pivoting : bool, optional
        Whether or not factorization should include pivoting for rank-revealing
        qr decomposition. If pivoting, compute the decomposition
        ``A[:, P] = Q @ R`` as above, but where P is chosen such that the 
        diagonal of R is non-increasing.
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    Q : float or complex ndarray
        Of shape (M, M), or (M, K) for ``mode='economic'``. Not returned
        if ``mode='r'``. Replaced by tuple ``(Q, TAU)`` if ``mode='raw'``.
    R : float or complex ndarray
        Of shape (M, N), or (K, N) for ``mode in ['economic', 'raw']``.
        ``K = min(M, N)``.
    P : int ndarray
        Of shape (N,) for ``pivoting=True``. Not returned if
        ``pivoting=False``.

    Raises
    ------
    LinAlgError
        Raised if decomposition fails

    Notes
    -----
    This is an interface to the LAPACK routines dgeqrf, zgeqrf,
    dorgqr, zungqr, dgeqp3, and zgeqp3.

    If ``mode=economic``, the shapes of Q and R are (M, K) and (K, N) instead
    of (M,M) and (M,N), with ``K=min(M,N)``.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> rng = np.random.default_rng()
    >>> a = rng.standard_normal((9, 6))

    >>> q, r = linalg.qr(a)
    >>> np.allclose(a, np.dot(q, r))
    True
    >>> q.shape, r.shape
    ((9, 9), (9, 6))

    >>> r2 = linalg.qr(a, mode='r')
    >>> np.allclose(r, r2)
    True

    >>> q3, r3 = linalg.qr(a, mode='economic')
    >>> q3.shape, r3.shape
    ((9, 6), (6, 6))

    >>> q4, r4, p4 = linalg.qr(a, pivoting=True)
    >>> d = np.abs(np.diag(r4))
    >>> np.all(d[1:] <= d[:-1])
    True
    >>> np.allclose(a[:, p4], np.dot(q4, r4))
    True
    >>> q4.shape, r4.shape, p4.shape
    ((9, 9), (9, 6), (6,))

    >>> q5, r5, p5 = linalg.qr(a, mode='economic', pivoting=True)
    >>> q5.shape, r5.shape, p5.shape
    ((9, 6), (6, 6), (6,))

    )r   r   ÚrÚeconomicÚrawz?Mode argument should be one of ['full', 'r', 'economic', 'raw']é   zexpected a 2-D arrayr   )r   r   ©Úshape.©Údtyper   r   )Úgeqp3r%   )Úoverwrite_ar   )Úgeqrfr'   ©r
   r&   N)Úorgqrzgorgqr/gungqrr   )r   r   Úasarray_chkfiniteÚasarrayÚlenr"   ÚsizeÚminÚ
empty_likeÚidentityÚarangeÚint32Ú
zeros_liker   r   r   Útriur$   ÚcharÚempty)Úar&   r
   ÚmodeÚpivotingÚcheck_finiteÚa1ÚMÚNÚKÚQÚRÚRjr   Útaur%   Újpvtr'   Ú
gor_un_gqrÚtÚqqrs                        r   r   r      s˜  € ðD Ð9Ð9Ð9Ýð .ñ /ô /ð 	/ð ð ÝÔ! !Ñ$Ô$ˆˆåŒZ˜‰]Œ]ˆÝ
ˆ2Œ8�}„}˜ÒÐÝÐ/Ñ0Ô0Ð0àŒ8�D€A€qð 
„w�!‚|€|Ý��1‰IŒIˆàÐ*Ð*Ð*Ý”˜b¨¨A¨Ð/Ñ/Ô/ˆAÝ”[ ‘^”^ˆAˆc‰FÝ”˜bÑ!Ô!ˆAˆAå”˜b¨¨A¨Ð/Ñ/Ô/ˆAÝ”˜b¨¨A¨Ð/Ñ/Ô/ˆAàð 	Ø•B”I˜a¥r¤xÐ0Ñ0Ô0Ð0ˆBˆBà�ˆBà�3Š;ˆ;ØˆIØ�UŠ]ˆ]Ý”˜r¨!¨Q¨Ð0Ñ0Ô0ˆBÝ”- ¨1¨$Ð/Ñ/Ô/ˆCØ˜�I�< "Ñ$Ð$Øˆt�b‰yÐàÐ5¥+¨b°!Ñ"4Ô"4€Kàð 4Ý! *¨r¨eÑ4Ô4‰ˆÝ  ¨°ÀÐMÑMÔM‰ˆˆD�#Ø�‰	ˆˆå! *¨r¨eÑ4Ô4‰ˆÝ˜5 '¨2°UØ'2ð4ñ 4ô 4‰ˆˆCð Ð&Ð&Ð&¨!¨aª%¨%ÝŒG�B‰KŒKˆˆåŒG�B�r˜�r˜1˜1˜1�u”IÑÔˆàð Ø�ˆWˆˆàˆRˆàˆs‚{€{Øˆ	Ø	�ŠˆØ�S�	ˆ|˜bÑ Ð å" :°¨uÑ5Ô5�K€Jàˆ1‚u€uÝ�j /°2°a°a°a¸¸!¸°e´9¸cØ!¨qð2ñ 2ô 2‰ˆˆà	�Ò	Ð	Ý�j /°2°sÀ%Ø"#ð%ñ %ô %‰ˆˆð ŒHŒMˆÝŒh˜˜1�v QÐ'Ñ'Ô'ˆØˆˆAˆAˆAˆr�ˆrˆE‰
Ý�j /°3¸À5Ø"#ð%ñ %ô %‰ˆð ˆ4�"‰9Ðr   Úrightc           
      ó|  — |dvrt          d|› d�¦  «        ‚t          j        |¦  «        }|j        dk     r$d}t          j        |¦  «        }|dk    r|j        }nd}t          j        t          j        | ¦  «        ¦  «        } | j        \  }}	|dk    rH|j        d         t          ||	|||	z
  z  z   ¦  «        k    rt          d	| j        › d
|j        › �¦  «        ‚n0||j        d         k    rt          d|j        › d
| j        › �¦  «        ‚t          | |dd|¦  «        }
|
d         \  }}|j
        dk    r t          j        |¦  «        f|
dd…         z   S t          d|f¦  «        \  }|j        dv rd}nd}|dd…dt          ||	¦  «        …f         }||	k    r„|dk    r~|s||r:t          j        |j        d         |f|j        d¬¦  «        }|j        |dd…d|	…f<   n6t          j        ||j        d         f|j        d¬¦  «        }||d|	…dd…f<   d}|rd}nd}d}n7|j        d         r|dk    s|r|j        }|dk    rd}nd}nd}|}|dk    rd}nd}t#          |d||||||¬¦  «        \  }|dk    r|j        }|dk    r|dd…dt          ||	¦  «        …f         }|r|                     ¦   «         }|f|
dd…         z   S )a¬	  
    Calculate the QR decomposition and multiply Q with a matrix.

    Calculate the decomposition ``A = Q R`` where Q is unitary/orthogonal
    and R upper triangular. Multiply Q with a vector or a matrix c.

    Parameters
    ----------
    a : (M, N), array_like
        Input array
    c : array_like
        Input array to be multiplied by ``q``.
    mode : {'left', 'right'}, optional
        ``Q @ c`` is returned if mode is 'left', ``c @ Q`` is returned if
        mode is 'right'.
        The shape of c must be appropriate for the matrix multiplications,
        if mode is 'left', ``min(a.shape) == c.shape[0]``,
        if mode is 'right', ``a.shape[0] == c.shape[1]``.
    pivoting : bool, optional
        Whether or not factorization should include pivoting for rank-revealing
        qr decomposition, see the documentation of qr.
    conjugate : bool, optional
        Whether Q should be complex-conjugated. This might be faster
        than explicit conjugation.
    overwrite_a : bool, optional
        Whether data in a is overwritten (may improve performance)
    overwrite_c : bool, optional
        Whether data in c is overwritten (may improve performance).
        If this is used, c must be big enough to keep the result,
        i.e. ``c.shape[0]`` = ``a.shape[0]`` if mode is 'left'.

    Returns
    -------
    CQ : ndarray
        The product of ``Q`` and ``c``.
    R : (K, N), ndarray
        R array of the resulting QR factorization where ``K = min(M, N)``.
    P : (N,) ndarray
        Integer pivot array. Only returned when ``pivoting=True``.

    Raises
    ------
    LinAlgError
        Raised if QR decomposition fails.

    Notes
    -----
    This is an interface to the LAPACK routines ``?GEQRF``, ``?ORMQR``,
    ``?UNMQR``, and ``?GEQP3``.

    .. versionadded:: 0.11.0

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import qr_multiply, qr
    >>> A = np.array([[1, 3, 3], [2, 3, 2], [2, 3, 3], [1, 3, 2]])
    >>> qc, r1, piv1 = qr_multiply(A, 2*np.eye(4), pivoting=1)
    >>> qc
    array([[-1.,  1., -1.],
           [-1., -1.,  1.],
           [-1., -1., -1.],
           [-1.,  1.,  1.]])
    >>> r1
    array([[-6., -3., -5.            ],
           [ 0., -1., -1.11022302e-16],
           [ 0.,  0., -1.            ]])
    >>> piv1
    array([1, 0, 2], dtype=int32)
    >>> q2, r2, piv2 = qr(A, mode='economic', pivoting=1)
    >>> np.allclose(2*q2 - qc, np.zeros((4, 3)))
    True

    )ÚleftrG   z5Mode argument can only be 'left' or 'right' but not 'ú'r    TrI   Fr   z5Array shapes are not compatible for Q @ c operation: z vs r   z5Array shapes are not compatible for c @ Q operation: Nr   )Úormqr)ÚsÚdÚTÚCÚF)r$   Úorderr=   r@   ÚLÚC_CONTIGUOUSzgormqr/gunmqr)Úoverwrite_crG   )r   r   r*   ÚndimÚ
atleast_2drN   r+   r"   r.   r   r-   r/   r   ÚtypecodeÚzerosr$   Úflagsr   Úravel)r7   Úcr8   r9   Ú	conjugater&   rT   Úonedimr<   r=   r   r?   rB   Ú
gor_un_mqrÚtransÚccÚlrÚcQs                     r   r   r   Î   s�  € ðX Ð$Ð$Ð$Ýð )Ø!%ð)ð )ð )ñ *ô *ð 	*å
Ô˜QÑÔ€AØ„v�‚z€zØˆÝŒM˜!ÑÔˆØ�6Š>ˆ>Ø”ˆAøàˆå
Œ•b”j ‘m”mÑ$Ô$€AØŒ7�D€A€qàˆv‚~€~ØŒ7�1Œ:�˜Q  K°°1±Ñ$5Ñ 5Ñ6Ô6Ò6Ð6Ýð CØ,-¬GðCð CØ9:¼ðCð Cñ Dô Dð Dð 7ð �”˜”
Š?ˆ?Ýð CØ,-¬GðCð CØ9:¼ðCð Cñ Dô Dð Dõ ˆQ�˜T 5¨(Ñ
3Ô
3€CØ�ŒV�F€A€sð 	„v�‚{€{Ý”˜aÑ Ô Ð" S¨¨¨¤WÑ,Ð,å" :°¨tÑ4Ô4�K€JØÔ˜jÐ(Ð(Øˆˆàˆà	ˆ!ˆ!ˆ!ˆZ�c�!�Q‰iŒiˆZˆ-Ô€AØˆ1‚u€u�˜’�¨�Øð 	Ý”˜1œ7 1œ: q˜/°´ÀÐDÑDÔDˆBØœˆBˆqˆqˆq�"�1�"ˆu‰IˆIå”˜1˜aœg aœj˜/°´ÀÐDÑDÔDˆBØˆBˆr�ˆr�1�1�1ˆu‰IØˆEØð 	ØˆBˆBàˆBØˆˆØ	
Œ�Ô	 ð  U¨c¢\ \°Y \ØŒSˆØ�6Š>ˆ>ØˆBˆBàˆBˆBàˆØˆØ�6Š>ˆ>ØˆBˆBàˆBÝ
�:˜°°E¸1¸cÀ2Ø*ð,ñ ,ô ,�C€Bà�‚|€|ØŒTˆØˆw‚€Ø����:•C˜˜1‘I”I�:�ÔˆØð Ø�XŠX‰ZŒZˆàˆ5�3�q�r�r”7‰?Ðr   c                 óh  — |dvrt          d¦  «        ‚|rt          j        | ¦  «        }nt          j        | ¦  «        }t	          |j        ¦  «        dk    rt          d¦  «        ‚|j        \  }}|j        dk    r–t          ||¦  «        }|dk    sDt          j        |¦  «        }	t          j        |||f¬¦  «        }
t          j	        |¦  «        |
d<   n0t          j        |||f¬¦  «        }	t          j        |||f¬¦  «        }
|d	k    r|	S |	|
fS |pt          || ¦  «        }t          d
|f¦  «        \  }t          |d|||¬¦  «        \  }}|dk    r||k     rt          j        |||z
  ¦  «        }	n"t          j        || d…| d…f         ¦  «        }	|d	k    r|	S t          d|f¦  «        \  }||k     r!t          |d|| d…         ||d¬¦  «        \  }
nZ|dk    rt          |d|||d¬¦  «        \  }
n<t          j        ||f|j        ¬¦  «        }||| d…<   t          |d|||d¬¦  «        \  }
|	|
fS )aß  
    Compute RQ decomposition of a matrix.

    Calculate the decomposition ``A = R Q`` where Q is unitary/orthogonal
    and R upper triangular.

    Parameters
    ----------
    a : (M, N) array_like
        Matrix to be decomposed
    overwrite_a : bool, optional
        Whether data in a is overwritten (may improve performance)
    lwork : int, optional
        Work array size, lwork >= a.shape[1]. If None or -1, an optimal size
        is computed.
    mode : {'full', 'r', 'economic'}, optional
        Determines what information is to be returned: either both Q and R
        ('full', default), only R ('r') or both Q and R but computed in
        economy-size ('economic', see Notes).
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    R : float or complex ndarray
        Of shape (M, N) or (M, K) for ``mode='economic'``. ``K = min(M, N)``.
    Q : float or complex ndarray
        Of shape (N, N) or (K, N) for ``mode='economic'``. Not returned
        if ``mode='r'``.

    Raises
    ------
    LinAlgError
        If decomposition fails.

    Notes
    -----
    This is an interface to the LAPACK routines sgerqf, dgerqf, cgerqf, zgerqf,
    sorgrq, dorgrq, cungrq and zungrq.

    If ``mode=economic``, the shapes of Q and R are (K, N) and (M, K) instead
    of (N,N) and (M,N), with ``K=min(M,N)``.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> rng = np.random.default_rng()
    >>> a = rng.standard_normal((6, 9))
    >>> r, q = linalg.rq(a)
    >>> np.allclose(a, r @ q)
    True
    >>> r.shape, q.shape
    ((6, 9), (9, 9))
    >>> r2 = linalg.rq(a, mode='r')
    >>> np.allclose(r, r2)
    True
    >>> r3, q3 = linalg.rq(a, mode='economic')
    >>> r3.shape, q3.shape
    ((6, 6), (6, 9))

    )r   r   r   z8Mode argument should be one of ['full', 'r', 'economic']r    zexpected matrixr   r   r!   .r   )Úgerqfrd   r(   N)Úorgrqzgorgrq/gungrqr   r#   )r   r   r*   r+   r,   r"   r-   r.   r/   r0   r   r   r   r4   r6   r$   )r7   r&   r
   r8   r:   r;   r<   r=   r>   r@   r?   rd   r   rB   Ú
gor_un_grqÚrq1s                   r   r   r   f  sž  € ðB Ð,Ð,Ð,ÝØKñMô Mð 	Mð ð ÝÔ! !Ñ$Ô$ˆˆåŒZ˜‰]Œ]ˆÝ
ˆ2Œ8�}„}˜ÒÐÝÐ*Ñ+Ô+Ð+àŒ8�D€A€qð 
„w�!‚|€|Ý��1‰IŒIˆà�zÒ!Ð!Ý”˜bÑ!Ô!ˆAÝ”˜b¨¨A¨Ð/Ñ/Ô/ˆAÝ”[ ‘^”^ˆAˆc‰FˆFå”˜b¨¨A¨Ð/Ñ/Ô/ˆAÝ”˜b¨¨A¨Ð/Ñ/Ô/ˆAà�3Š;ˆ;ØˆHØ�!ˆtˆàÐ5¥+¨b°!Ñ"4Ô"4€Kå˜j¨2¨%Ñ0Ô0�F€EÝ�u˜g r°Ø#.ð0ñ 0ô 0�G€Bˆà�:ÒÐ  Q¢ ÝŒG�B˜˜!™ÑÔˆˆåŒG�B˜�r�s�s˜Q˜B˜C˜C�x”LÑ!Ô!ˆàˆs‚{€{Øˆå" :°¨uÑ5Ô5�K€Jàˆ1‚u€uÝ�j /°2°q°b°c°c´7¸CÀuØ"#ð%ñ %ô %‰ˆˆà	�Ò	Ð	Ý�j /°2°sÀ%Ø"#ð%ñ %ô %‰ˆˆõ Œh˜˜1�v R¤XÐ.Ñ.Ô.ˆØˆˆQˆBˆCˆC‰Ý�j /°3¸À5Ø"#ð%ñ %ô %‰ˆð ˆaˆ4€Kr   )FNr   FT)rG   FFFF)FNr   T)Ú__doc__Únumpyr   Úlapackr   Ú_miscr   Ú__all__r   r   r   r   © r   r   ú<module>rn      sÀ   ðØ !Ð !Ø Ð Ð Ð ð %Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð à
%Ð
%Ð
%€ðð ð ð @EØðqð qð qð qðh ?DØ/4ðUð Uð Uð Uðpyð yð yð yð yð yr   