§
    ´³Ùg|  ã                   ó¨   — d Z dgZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ dd	lmZ  G d
„ dej        j        ¦  «        ZddlmZ dd„Zdd„ZdS )zz
Matrix square root for general matrices and for upper triangular matrices.

This module exists to avoid cyclic imports.

Úsqrtmé    N)Ú_asarray_validatedé   )Únorm)ÚztrsylÚdtrsyl)ÚschurÚrsf2csf)Ú_ensure_dtype_cdszc                   ó   — e Zd ZdS )Ú
SqrtmErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    úR/granary/edev/quantum/lib/python3.11/site-packages/scipy/linalg/_matfuncs_sqrtm.pyr   r      s   € € € € € Ø€Dr   r   )Úwithin_block_loopé@   c           	      ó:  — t          j        | ¦  «        }t          j        | ¦  «        ot          j        |d¬¦  «        dk    }|sBt          j        | t           j        d¬¦  «        } t          j        |t           j        ¬¦  «        }nAt          j        | t           j        d¬¦  «        } t          j        |t           j        ¬¦  «        }t          j        t          j        |¦  «        ¦  «        }| j        \  }}t          ||z  d¦  «        }t          ||¦  «        \  }}|dz   }	||z
  }
|
|z  ||	z  z   |k    rt          d¦  «        ‚g }d}|
|f||	ffD ]6\  }}t          |¦  «        D ]!}|                     |||z   f¦  «         ||z  }Œ"Œ7	 t          || ||¦  «         n!# t          $ r}t!          |j        Ž |‚d	}~ww xY wt          |¦  «        D ]Í}||         \  }}t          |dz
  d
d
¦  «        D ]«}||         \  }}| ||…||…f         }||z
  dk    r0||||…||…f                              |||…||…f         ¦  «        z
  }|||…||…f         }|||…||…f         }|rt'          |||¦  «        \  }}}nt)          |||¦  «        \  }}}||z  |||…||…f<   Œ¬ŒÎ|S )aÜ  
    Matrix square root of an upper triangular matrix.

    This is a helper function for `sqrtm` and `logm`.

    Parameters
    ----------
    T : (N, N) array_like upper triangular
        Matrix whose square root to evaluate
    blocksize : int, optional
        If the blocksize is not degenerate with respect to the
        size of the input array, then use a blocked algorithm. (Default: 64)

    Returns
    -------
    sqrtm : (N, N) ndarray
        Value of the sqrt function at `T`

    References
    ----------
    .. [1] Edvin Deadman, Nicholas J. Higham, Rui Ralha (2013)
           "Blocked Schur Algorithms for Computing the Matrix Square Root,
           Lecture Notes in Computer Science, 7782. pp. 171-182.

    g        )Úinitialr   ÚC)ÚdtypeÚorder)r   r   zinternal inconsistencyNéÿÿÿÿ)ÚnpÚdiagÚ	isrealobjÚminÚasarrayÚ
complex128Úfloat64ÚsqrtÚshapeÚmaxÚdivmodÚ	ExceptionÚrangeÚappendr   ÚRuntimeErrorr   ÚargsÚdotr   r   )ÚTÚ	blocksizeÚT_diagÚkeep_it_realÚRÚnÚnblocksÚbsmallÚnlargeÚblargeÚnsmallÚstart_stop_pairsÚstartÚcountÚsizeÚiÚeÚjÚjstartÚjstopÚistartÚistopÚSÚRiiÚRjjÚxÚscaleÚinfos                               r   Ú_sqrtm_triurI      s5  € õ4 ŒW�Q‰ZŒZ€FÝ”< ‘?”?ÐF¥r¤v¨f¸bÐ'AÑ'AÔ'AÀQÒ'F€Lð ð 6ÝŒJ�q¥¤°SÐ9Ñ9Ô9ˆÝ”˜F­"¬-Ð8Ñ8Ô8ˆˆåŒJ�q¥¤
°#Ð6Ñ6Ô6ˆÝ”˜F­"¬*Ð5Ñ5Ô5ˆå
Œ•”˜‘”Ñ Ô €Að Œ7�D€A€qÝ�!�y‘. !Ñ$Ô$€Gõ ˜A˜wÑ'Ô'�N€FˆFØ�a‰Z€FØ�vÑ€FØ��˜ &™Ñ(¨AÒ-Ð-ÝÐ0Ñ1Ô1Ð1ð ÐØ€EØ Ð(¨6°6Ð*:Ð;ð ð ‰ˆˆtÝ�u‘”ð 	ð 	ˆAØ×#Ò# U¨E°D©LÐ$9Ñ:Ô:Ð:Ø�T‰MˆEˆEð	ð
)Ý˜!˜QÐ 0°'Ñ:Ô:Ð:Ð:øÝð )ð )ð )Ý˜!œ&Ð! qÐ(øøøøð)øøøõ �7‰^Œ^ð 6ð 6ˆØ(¨Ô+‰ˆ�Ý�q˜‘s˜B Ñ#Ô#ð 	6ð 	6ˆAØ,¨QÔ/‰MˆF�EØ�&˜�,  u Ð,Ô-ˆAØ�1‰u�qŠyˆyØ˜˜& ˜,¨¨f¨Ð4Ô5×9Ò9¸!¸EÀ&¸LØ<BÀ5¸Lð=Iô ;Jñ Kô Kñ K�ð �F˜5�L &¨ ,Ð.Ô/ˆCØ�F˜5�L &¨ ,Ð.Ô/ˆCØð 5Ý!'¨¨S°!Ñ!4Ô!4‘��5˜$˜$å!'¨¨S°!Ñ!4Ô!4‘��5˜$Ø,-°©IˆAˆf�Uˆl˜F 5˜LÐ(Ñ)Ð)ð!	6ð& €Hs   Æ
F Æ
F;Æ'F6Æ6F;Tc                 óB  — t          | dd¬¦  «        } t          | j        ¦  «        dk    rt          d¦  «        ‚|dk     rt          d¦  «        ‚t	          | ¦  «        \  } t          j        | ¦  «        }|rÄt          | ¦  «        \  }}t          j        |¦  «        }t          j        |d¦  «        }t          j	        |j
        ¦  «        j        }t          |¦  «        |t          |dd…         ¦  «        t          |dd…         ¦  «        z   z  k    }	|	                     ¦   «         rt          ||¦  «        \  }}nt          | d	¬
¦  «        \  }}d}
	 t          ||¬¦  «        }t          j        |¦  «        j        }|                     |¦  «                             |¦  «        }t          j        | j
        t          j        |¦  «        rdnd¦  «        }|                     |d¬¦  «        }nE# t,          $ r8 d}
t          j        | ¦  «        }|                     t
          j        ¦  «         Y nw xY w|r|
rt5          d¦  «         |S 	 t7          |                     |¦  «        | z
  d¦  «        dz  t7          | d¦  «        z  }n# t          $ r t
          j        }Y nw xY w||fS )a<  
    Matrix square root.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix whose square root to evaluate
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)
    blocksize : integer, optional
        If the blocksize is not degenerate with respect to the
        size of the input array, then use a blocked algorithm. (Default: 64)

    Returns
    -------
    sqrtm : (N, N) ndarray
        Value of the sqrt function at `A`. The dtype is float or complex.
        The precision (data size) is determined based on the precision of
        input `A`.

    errest : float
        (if disp == False)

        Frobenius norm of the estimated error, ||err||_F / ||A||_F

    References
    ----------
    .. [1] Edvin Deadman, Nicholas J. Higham, Rui Ralha (2013)
           "Blocked Schur Algorithms for Computing the Matrix Square Root,
           Lecture Notes in Computer Science, 7782. pp. 171-182.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import sqrtm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> r = sqrtm(a)
    >>> r
    array([[ 0.75592895,  1.13389342],
           [ 0.37796447,  1.88982237]])
    >>> r.dot(r)
    array([[ 1.,  3.],
           [ 1.,  4.]])

    T)Úcheck_finiteÚ
as_inexacté   z$Non-matrix input to matrix function.r   z#The blocksize should be at least 1.r   NÚcomplex)ÚoutputF)r.   y              ð?)ÚcopyzFailed to find a square root.Úfro)r   Úlenr$   Ú
ValueErrorr   r   r   r	   ÚdiagonalÚfinfor   ÚepsÚabsÚanyr
   rI   Ú	conjugater-   r,   Úresult_typeÚiscomplexobjÚastyper   Ú
empty_likeÚfillÚnanÚprintr   Úinf)ÚAÚdispr.   r0   r-   ÚZÚd0Úd1rV   Úneeds_conversionÚfailflagr1   ÚZHÚXr   Úarg2s                   r   r   r   v   s€  € õ^ 	˜1¨4¸DÐAÑAÔA€AÝ
ˆ1Œ7�|„|�qÒÐÝÐ?Ñ@Ô@Ð@Ø�1‚}€}ÝÐ>Ñ?Ô?Ð?Ý	˜AÑ	Ô	�B€AÝ”< ‘?”?€LØð 	*Ý�Q‰xŒx‰ˆˆ1ÝŒ[˜‰^Œ^ˆÝŒ[˜˜BÑÔˆÝŒh�q”wÑÔÔ#ˆÝ˜r™7œ7 S­C°°1°2°2´©K¬K½#¸bÀÀ"À¼g¹,¼,Ñ,FÑ%GÒGÐØ×ÒÑ!Ô!ð 	!Ý˜1˜a‘=”=‰DˆAˆqøå�Q˜yÐ)Ñ)Ô)‰ˆˆ1Ø€Hð	Ý˜ YÐ/Ñ/Ô/ˆÝŒ\˜!‰_Œ_ÔˆØ�EŠE�!‰HŒH�LŠL˜ÑÔˆÝ”˜qœw­b¬o¸aÑ.@Ô.@Ð(G¨¨ÀaÑHÔHˆØ�HŠH�U ˆHÑ'Ô'ˆˆøÝð ð ð ØˆÝŒM˜!ÑÔˆØ	�Š�rŒv‰Œˆˆˆðøøøð
 ð Øð 	3ÝÐ1Ñ2Ô2Ð2Øˆð	Ý˜Ÿš˜a™œ 1™ eÑ,Ô,¨aÑ/µ$°q¸%±.´.Ñ@ˆDˆDøÝð 	ð 	ð 	å”6ˆDˆDˆDð	øøøð �$ˆwˆs%   ÅBG+ Ç+?H-È,H-É:J ÊJÊJ)r   )Tr   )Ú__doc__Ú__all__Únumpyr   Úscipy._lib._utilr   Ú_miscr   Úlapackr   r   Ú_decomp_schurr	   r
   Ú_basicr   ÚlinalgÚLinAlgErrorr   Ú_matfuncs_sqrtm_triur   rI   r   r   r   r   ú<module>rw      s  ððð ð ˆ)€à Ð Ð Ð à /Ð /Ð /Ð /Ð /Ð /ð Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ø &Ð &Ð &Ð &Ð &Ð &ð	ð 	ð 	ð 	ð 	�”Ô&ñ 	ô 	ð 	ð 4Ð 3Ð 3Ð 3Ð 3Ð 3ðWð Wð Wð WðtWð Wð Wð Wð Wð Wr   