Ë
    âQ(h|  ã                   ó´   — 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y)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y)Ú
SqrtmErrorN)Ú__name__Ú
__module__Ú__qualname__© ó    úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs_sqrtm.pyr   r      s   „ Ør   r   )Úwithin_block_loopc           	      ó  — t        j                  | «      }t        j                  | «      xr t        j                  |d¬«      dk\  }|sLt        j                  | t         j
                  d¬«      } t        j                  |t         j
                  ¬«      }nKt        j                  | t         j                  d¬«      } t        j                  |t         j                  ¬«      }t        j                  t        j                  |«      «      }| j                  \  }}t        ||z  d«      }t        ||«      \  }}|dz   }	||z
  }
|
|z  ||	z  z   |k7  rt        d«      ‚g }d}|
|f||	ffD ]0  \  }}t        |«      D ]  }|j                  |||z   f«       ||z  }Œ Œ2 	 t        || ||«       t        |«      D ]©  }||   \  }}t        |dz
  d
d
«      D ]Œ  }||   \  }}| ||…||…f   }||z
  dkD  r&||||…||…f   j%                  |||…||…f   «      z
  }|||…||…f   }|||…||…f   }|rt'        |||«      \  }}}nt)        |||«      \  }}}||z  |||…||…f<   ŒŽ Œ« |S # t        $ r}t!        |j"                  Ž |‚d	}~ww xY w)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_triurH      sÒ  € ô4 �W‰W�Q‹Z€FÜ—<‘< “?ÒF¤r§v¡v¨f¸bÔ'AÀQÑ'F€Lñ Ü�J‰J�q¤§¡°SÔ9ˆÜ—‘˜F¬"¯-©-Ô8‰ä�J‰J�q¤§
¡
°#Ô6ˆÜ—‘˜F¬"¯*©*Ô5ˆä
�‰”—‘˜“Ó €Að �7‰7�D€A€qÜ�!�y‘. !Ó$€Gô ˜A˜wÓ'�N€FˆFØ�a‰Z€FØ�vÑ€FØ��˜ &™Ñ(¨AÒ-ÜÐ0Ó1Ð1ð ÐØ€EØ Ð(¨6°6Ð*:Ð;ò ‰ˆˆtÜ�u“ò 	ˆAØ×#Ñ# U¨E°D©LÐ$9Ô:Ø�T‰M‰Eñ	ðð)Ü˜!˜QÐ 0°'Ô:ô
 �7‹^ò 6ˆØ(¨Ñ+‰ˆ�Ü�q˜‘s˜B Ó#ò 	6ˆAØ,¨QÑ/‰MˆF�EØ�&˜�,  u Ð,Ñ-ˆAØ�1‰u�qŠyØ˜˜& ˜,¨¨f¨Ð4Ñ5×9Ñ9¸!¸EÀ&¸LØ<BÀ5¸Lð=Iñ ;Jó Kñ K�ð �F˜5�L &¨ ,Ð.Ñ/ˆCØ�F˜5�L &¨ ,Ð.Ñ/ˆCÙÜ!'¨¨S°!Ó!4‘��5™$ä!'¨¨S°!Ó!4‘��5˜$Ø,-°©IˆAˆf�Uˆl˜F 5˜LÐ(Ò)ñ!	6ð6ð* €Høô3 ò )Ü˜!Ÿ&™&Ð! qÐ(ûð)ús   ÆI É	J É(I;É;J c                 óÐ  — t        | dd¬«      } t        | j                  «      dk7  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  kD  }	|	j                  «       r t        ||«      \  }}nt        | d	¬
«      \  }}d}
	 t        ||¬«      }t        j                   |«      j"                  }|j%                  |«      j%                  |«      }t        j&                  | j                  t        j(                  |«      rdnd«      }|j+                  |d¬«      }|r|
rt5        d«       |S 	 t7        |j%                  |«      | z
  d«      dz  t7        | d«      z  }||fS # t,        $ r9 d}
t        j.                  | «      }|j1                  t
        j2                  «       Y Œ…w xY w# t        $ r t
        j8                  }Y ||fS w xY w)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
   rH   Ú	conjugater,   r+   Úresult_typeÚiscomplexobjÚastyper   Ú
empty_likeÚfillÚnanÚprintr   Úinf)ÚAÚdispr-   r/   r,   ÚZÚd0Úd1rU   Úneeds_conversionÚfailflagr0   ÚZHÚXr   Úarg2s                   r   r   r   v   s  € ô^ 	˜1¨4¸DÔA€AÜ
ˆ1�7‰7ƒ|�qÒÜÐ?Ó@Ð@Ø�1‚}ÜÐ>Ó?Ð?Ü	˜AÓ	�B€AÜ—<‘< “?€LÙÜ�Q‹x‰ˆˆ1Ü�[‰[˜‹^ˆÜ�[‰[˜˜BÓˆÜ�h‰h�q—w‘wÓ×#Ñ#ˆÜ˜r›7 S¬C°°1°2°«K¼#¸bÀÀ"¸g»,Ñ,FÑ%GÑGÐØ×ÑÔ!Ü˜1˜a“=‰DˆA‰qä�Q˜yÔ)‰ˆˆ1Ø€Hð	Ü˜ YÔ/ˆÜ�\‰\˜!‹_×ÑˆØ�E‰E�!‹H�L‰L˜ÓˆÜ—‘˜qŸw™w¬b¯o©o¸aÔ.@©ÀaÓHˆØ�H‰H�U ˆHÓ'ˆñ ÙÜÐ1Ô2Øˆð	Ü˜Ÿ™˜a› 1™ eÓ,¨aÑ/´$°q¸%³.Ñ@ˆDð
 �$ˆwˆøô! ò ØˆÜ�M‰M˜!ÓˆØ	�‰Œr�v‰vŽðûô ò 	ä—6‘6‰Dà�$ˆwˆð		ús%   Ä'BH Ç.I È?IÉIÉI%É$I%)é@   )Trk   )Ú__doc__Ú__all__Únumpyr   Úscipy._lib._utilr   Ú_miscr   Úlapackr   r   Ú_decomp_schurr	   r
   Ú_basicr   ÚlinalgÚLinAlgErrorr   Ú_matfuncs_sqrtm_triur   rH   r   r   r   r   ú<module>rw      sO   ðñð ˆ)€ã å /õ ß "ß )Ý &ô	�—‘×&Ñ&ô 	õ 4óWôtWr   