Ë
    âQ(hYb  ã                   óÄ  — d dl Z d dlmZ d dlZd dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZmZ ddlmZ ddlmZ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" ddl#m$Z$m%Z% ddl&m'Z' g d¢Z( ejR                  d«      jT                  Z* ejR                  d«      jT                  Z+ddd dd ddœZ,d„ Z-d!d„Z.d„ Z/d"d„Z0d„ Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6d„ Z7d„ Z8d"d„Z9d"d„Z:d „ Z;y)#é    N)Úproduct)ÚdotÚdiagÚprodÚlogical_notÚravelÚ	transposeÚ	conjugateÚabsoluteÚamaxÚsignÚisfiniteÚtriu)ÚLinAlgErrorÚ	bandwidthé   )Únorm)ÚsolveÚinv)Úsvd)ÚschurÚrsf2csf)Úexpm_frechetÚ	expm_cond)Úsqrtm)Úpick_pade_structureÚpade_UV_calc)Ú_funm_loops)ÚexpmÚcosmÚsinmÚtanmÚcoshmÚsinhmÚtanhmÚlogmÚfunmÚsignmr   Úfractional_matrix_powerr   r   Ú
khatri_raoÚdÚf)ÚiÚlr,   r+   ÚFÚDc                 ó´   — t        j                  | «      } t        | j                  «      dk7  s| j                  d   | j                  d   k7  rt	        d«      ‚| S )aƒ  
    Wraps asarray with the extra requirement that the input be a square matrix.

    The motivation is that the matfuncs module has real functions that have
    been lifted to square matrix functions.

    Parameters
    ----------
    A : array_like
        A square matrix.

    Returns
    -------
    out : ndarray
        An ndarray copy or view or other representation of A.

    é   r   r   z expected square array_like input)ÚnpÚasarrayÚlenÚshapeÚ
ValueError©ÚAs    úT/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/linalg/_matfuncs.pyÚ_asarray_squarer;   $   sI   € ô$ 	�
‰
�1‹€AÜ
ˆ1�7‰7ƒ|�qÒ˜AŸG™G A™J¨!¯'©'°!©*Ò4ÜÐ;Ó<Ð<Ø€Hó    c                 ó  — t        j                  | «      rvt        j                  |«      ra|€1t        dz  t        dz  dœt
        |j                  j                        }t        j                  |j                  d|¬«      r|j                  }|S )a(  
    Return either B or the real part of B, depending on properties of A and B.

    The motivation is that B has been computed as a complicated function of A,
    and B may be perturbed by negligible imaginary components.
    If A is real and B is complex with small imaginary components,
    then return a real copy of B.  The assumption in that case would be that
    the imaginary components of B are numerical artifacts.

    Parameters
    ----------
    A : ndarray
        Input array whose type is to be checked as real vs. complex.
    B : ndarray
        Array to be returned, possibly without its imaginary part.
    tol : float
        Absolute tolerance.

    Returns
    -------
    out : real or complex array
        Either the input array B or only the real part of the input array B.

    ç     @�@g    €„.A©r   r   ç        )Úatol)r3   Ú	isrealobjÚiscomplexobjÚfepsÚepsÚ_array_precisionÚdtypeÚcharÚallcloseÚimagÚreal)r9   ÚBÚtols      r:   Ú_maybe_realrN   <   sf   € ô4 
‡|�|�A„œ2Ÿ?™?¨1Ô-Øˆ;Ü˜3‘h¤3 s¡7Ñ+Ô,<¸Q¿W¹W¿\¹\Ñ,JÑKˆCÜ�;‰;�q—v‘v˜s¨Õ-Ø—‘ˆAØ€Hr<   c                 ól   — t        | «      } ddl}|j                  j                  j	                  | |«      S )aò  
    Compute the fractional power of a matrix.

    Proceeds according to the discussion in section (6) of [1]_.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix whose fractional power to evaluate.
    t : float
        Fractional power.

    Returns
    -------
    X : (N, N) array_like
        The fractional power of the matrix.

    References
    ----------
    .. [1] Nicholas J. Higham and Lijing lin (2011)
           "A Schur-Pade Algorithm for Fractional Powers of a Matrix."
           SIAM Journal on Matrix Analysis and Applications,
           32 (3). pp. 1056-1078. ISSN 0895-4798

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import fractional_matrix_power
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> b = fractional_matrix_power(a, 0.5)
    >>> b
    array([[ 0.75592895,  1.13389342],
           [ 0.37796447,  1.88982237]])
    >>> np.dot(b, b)      # Verify square root
    array([[ 1.,  3.],
           [ 1.,  4.]])

    r   N)r;   Úscipy.linalg._matfuncs_inv_ssqÚlinalgÚ_matfuncs_inv_ssqÚ_fractional_matrix_power)r9   ÚtÚscipys      r:   r)   r)   b   s/   € ôR 	˜Ó€AÛ)Ø�<‰<×)Ñ)×BÑBÀ1ÀaÓHÐHr<   c                 ó  — t        j                  | «      } ddl}|j                  j                  j                  | «      }t        | |«      }dt        z  }t        j                  dd¬«      5  t        t        |«      | z
  d«      t        j                  t        | d«      | j                  ¬«      j                  d   z  }ddd«       |r3t        «      r||k\  r!d	|› �}t        j                  |t         d
¬«       |S |fS # 1 sw Y   ŒBxY w)a  
    Compute matrix logarithm.

    The matrix logarithm is the inverse of
    expm: expm(logm(`A`)) == `A`

    Parameters
    ----------
    A : (N, N) array_like
        Matrix whose logarithm to evaluate
    disp : bool, optional
        Emit warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    logm : (N, N) ndarray
        Matrix logarithm of `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham (2012)
           "Improved Inverse Scaling and Squaring Algorithms
           for the Matrix Logarithm."
           SIAM Journal on Scientific Computing, 34 (4). C152-C169.
           ISSN 1095-7197

    .. [2] Nicholas J. Higham (2008)
           "Functions of Matrices: Theory and Computation"
           ISBN 978-0-898716-46-7

    .. [3] Nicholas J. Higham and Lijing lin (2011)
           "A Schur-Pade Algorithm for Fractional Powers of a Matrix."
           SIAM Journal on Matrix Analysis and Applications,
           32 (3). pp. 1056-1078. ISSN 0895-4798

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import logm, expm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> b = logm(a)
    >>> b
    array([[-1.02571087,  2.05142174],
           [ 0.68380725,  1.02571087]])
    >>> expm(b)         # Verify expm(logm(a)) returns a
    array([[ 1.,  3.],
           [ 1.,  4.]])

    r   Néè  Úignore)ÚdivideÚinvalidr   ©rG   © z1logm result may be inaccurate, approximate err = r2   )Ú
stacklevel)r3   r4   rP   rQ   rR   Ú_logmrN   rE   Úerrstater   r   rG   rK   r   ÚwarningsÚwarnÚRuntimeWarning)r9   ÚdisprU   r/   ÚerrtolÚerrestÚmessages          r:   r&   r&   �   sâ   € ôn 	�
‰
�1‹€Aã)Ø�‰×&Ñ&×,Ñ,¨QÓ/€AÜ�A�qÓ€AØ”#‰X€Fä	�‰˜H¨hÔ	7ñ UÜ”d˜1“g˜a‘i Ó#¤b§j¡j´°a¸³À1Ç7Á7Ô&K×&PÑ&PÐQSÑ&TÑTˆ÷UáÜ˜Ô 6¨VÒ#3ØIÈ&ÈÐRˆGÜ�M‰M˜'¤>¸aÕ@Øˆà�&ˆyÐ÷Uð Uús   Á+AC>Ã>Dc           
      ód	  — t        j                  | «      }|j                  dk(  rG|j                  dk  r8t        j                  t        j
                  |j                  «       «      gg«      S |j                  dk  rt        d«      ‚|j                  d   |j                  d   k7  rt        d«      ‚t        |j                  Ž dk(  rKt        t        j                  d|j                  ¬«      «      j                  }t        j                  ||¬«      S |j                  dd	 d
k(  rt        j
                  |«      S t        j                  |j                  t         j                  «      s |j!                  t         j"                  «      }n<|j                  t         j$                  k(  r|j!                  t         j&                  «      }|j                  d   }t        j(                  |j                  |j                  ¬«      }t        j(                  d||f|j                  ¬«      }t+        |j                  d	d D �cg c]  }t-        |«      ‘Œ c}Ž D �]\  }||   }t/        |«      }	t1        |	«      s?t        j2                  t        j
                  t        j2                  |«      «      «      ||<   Œ^||dd	d	…d	d	…f<   t5        |«      \  }
}|
dk  rt7        d|
› d�«      ‚t9        ||
«      }|dk7  r#|dk  rt7        d|› d�«      ‚t;        d|› d�«      ‚|d   }|dk7  �rF|	d   dk(  s	|	d   dk(  �r t        j2                  |«      }t        j
                  |d| z  z  «      t        j<                  d|«      d	d	 t        j2                  ||	d   dk(  rdnd¬«      }t-        |dz
  dd«      D ]£  }||z  }t        j
                  |d| z  z  «      t        j<                  d|«      d	d	 t?        |d| z  z  «      |d| z  z  z  }|	d   dk(  r#|t        j<                  d|dd	…d	d…f   «      d	d	 Œ‚|t        j<                  d|d	d…dd	…f   «      d	d	 Œ¥ nt-        |«      D ]  }||z  }Œ	 |	d   dk(  s|	d   dk(  r7|	d   dk(  rt        j@                  |«      nt        jB                  |«      ||<   �ŒX|||<   �Œ_ |S c c}w )a�  Compute the matrix exponential of an array.

    Parameters
    ----------
    A : ndarray
        Input with last two dimensions are square ``(..., n, n)``.

    Returns
    -------
    eA : ndarray
        The resulting matrix exponential with the same shape of ``A``

    Notes
    -----
    Implements the algorithm given in [1], which is essentially a Pade
    approximation with a variable order that is decided based on the array
    data.

    For input with size ``n``, the memory usage is in the worst case in the
    order of ``8*(n**2)``. If the input data is not of single and double
    precision of real and complex dtypes, it is copied to a new array.

    For cases ``n >= 400``, the exact 1-norm computation cost, breaks even with
    1-norm estimation and from that point on the estimation scheme given in
    [2] is used to decide on the approximation order.

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham, (2009), "A New Scaling
           and Squaring Algorithm for the Matrix Exponential", SIAM J. Matrix
           Anal. Appl. 31(3):970-989, :doi:`10.1137/09074721X`

    .. [2] Nicholas J. Higham and Francoise Tisseur (2000), "A Block Algorithm
           for Matrix 1-Norm Estimation, with an Application to 1-Norm
           Pseudospectra." SIAM J. Matrix Anal. Appl. 21(4):1185-1201,
           :doi:`10.1137/S0895479899356080`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Matrix version of the formula exp(0) = 1:

    >>> expm(np.zeros((3, 2, 2)))
    array([[[1., 0.],
            [0., 1.]],
    <BLANKLINE>
           [[1., 0.],
            [0., 1.]],
    <BLANKLINE>
           [[1., 0.],
            [0., 1.]]])

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    r   r2   z0The input array must be at least two-dimensionaléÿÿÿÿéþÿÿÿz-Last 2 dimensions of the array must be squarer   r[   N)r   r   é   znscipy.linalg.expm could not allocate sufficient memory while trying to compute the Pade structure (error code z).iõÿÿÿzkscipy.linalg.expm could not allocate sufficient memory while trying to compute the exponential (error code z^scipy.linalg.expm got an internal LAPACK error during the exponential computation (error code ú)zii->i)Úkg       @)"r3   r4   ÚsizeÚndimÚarrayÚexpÚitemr   r6   Úminr   ÚeyerG   Ú
empty_likeÚ
issubdtypeÚinexactÚastypeÚfloat64Úfloat16Úfloat32Úemptyr   Úranger   Úanyr   r   ÚMemoryErrorr   ÚRuntimeErrorÚeinsumÚ
_exp_sinchr   Útril)r9   ÚarG   ÚnÚeAÚAmÚxÚindÚawÚluÚmÚsÚinfoÚeAwÚdiag_awÚsdr-   Úexp_sdÚ_s                      r:   r   r   Ù   s8  € ôF 	�
‰
�1‹€AØ‡v�v�‚{�q—v‘v ’zÜ�x‰xœ"Ÿ&™& §¡£Ó*Ð+Ð,Ó-Ð-à‡v�v�‚zÜÐLÓMÐMØ‡w�wˆr�{�a—g‘g˜b‘kÒ!ÜÐIÓJÐJô ˆA�G‰G€}˜ÒÜ”R—V‘V˜A Q§W¡WÔ-Ó.×4Ñ4ˆÜ�}‰}˜Q eÔ,Ð,ð 	‡w�wˆrˆs€|�vÒÜ�v‰v�a‹yÐä�=‰=˜Ÿ™¤"§*¡*Ô-Ø�H‰H”R—Z‘ZÓ ‰Ø	
�‰”B—J‘JÒ	Ø�H‰H”R—Z‘ZÓ ˆð 	
�‰�‰€AÜ	�‰�!—'‘' §¡Ô	)€Bä	�‰�1�a˜�) 1§7¡7Ô	+€Bô ¨1¯7©7°3°B¨<Ö8 aœ˜q�Ò8Ð9ó >ˆØˆs‰Vˆä�r‹]ˆÜ�2ŒwÜ—g‘gœbŸf™f¤R§W¡W¨R£[Ó1Ó2ˆBˆs‰GØð
 ˆˆ1Ša’ˆ7‰Ü" 2Ó&‰ˆˆ1Ø�ŠEÜð 7à78°c¸ð=ó >ð >ô ˜B Ó"ˆØ�1Š9Ø�sŠ{ä!ð #9à9=¸¸bð#Bó Cð Cô #ð $2à26°°qð$:ó ;ð ;ð �‰eˆà�‹6à�1‘˜’
  1¡¨£
ô Ÿ'™' "›+�ä-/¯V©V°G¸aÀ1À"¹gÑ4EÓ-F”—	‘	˜' 3Ó'©Ð*ä—W‘W˜R¨¨A©°!ª¡2¸Ô;�ä˜q ™s B¨Ó+ò 	E�AØ ™)�Cô 24·±¸À"ÈÀrÁ(Ñ8JÓ1K”B—I‘I˜g sÓ+©AÐ.Ü'¨°2¸¸±8Ñ(<Ó=ÀÀaÈ1È"ÁgÁÑN�FØ˜!‘u ’zØ>DœŸ	™	 '¨3¨q©r°3°B°3¨w©<Ó8¹Ñ;à>DœŸ	™	 '¨3¨s°¨s°A±B¨w©<Ó8¹Ñ;ñ	Eô ˜q›ò $�AØ ™)‘Cð$ð ˆq‰E�QŠJ˜B˜q™E QšJØ&(¨¡e¨q¢j”b—g‘g˜c”l´b·g±g¸c³lˆBˆs‹GàˆBˆs‹Gð}>ð@ €IùòA 9s   È5R-c                 óê   — t        j                  t        j                  | «      «      }t        j                  | «      }|dk(  }|| xx   ||    z  cc<   t        j                  | d d |   «      ||<   |S )Nr@   rh   )r3   Údiffrp   )r‡   Ú	lexp_diffÚl_diffÚmask_zs       r:   r�   r�   €  si   € ä—‘œŸ™˜q›	Ó"€IÜ�W‰W�Q‹Z€FØ�r‰\€FØˆvˆgÓ˜& & ™/Ñ)ÓÜŸ™˜q  "˜v f™~Ó.€IˆfÑØÐr<   c                 ó²   — t        | «      } t        j                  | «      r dt        d| z  «      t        d| z  «      z   z  S t        d| z  «      j                  S )a!  
    Compute the matrix cosine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array

    Returns
    -------
    cosm : (N, N) ndarray
        Matrix cosine of A

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    ç      à?ù              ð?ù       €      ð¿)r;   r3   rC   r   rK   r8   s    r:   r    r    Š  sM   € ôB 	˜Ó€AÜ	‡��qÔØ”D˜˜A™“J¤ c¨!¡e£Ñ,Ñ-Ð-ä�B�q‘D‹z�‰Ðr<   c                 ó²   — t        | «      } t        j                  | «      r dt        d| z  «      t        d| z  «      z
  z  S t        d| z  «      j                  S )a   
    Compute the matrix sine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    sinm : (N, N) ndarray
        Matrix sine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    y       €      à¿rš   r›   )r;   r3   rC   r   rJ   r8   s    r:   r!   r!   ²  sM   € ôB 	˜Ó€AÜ	‡��qÔØ”d˜2˜a™4“j¤4¨¨A©£;Ñ.Ñ/Ð/ä�B�q‘D‹z�‰Ðr<   c           	      óh   — t        | «      } t        | t        t        | «      t	        | «      «      «      S )aÙ  
    Compute the matrix tangent.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    tanm : (N, N) ndarray
        Matrix tangent of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanm, sinm, cosm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> t = tanm(a)
    >>> t
    array([[ -2.00876993,  -8.41880636],
           [ -2.80626879, -10.42757629]])

    Verify tanm(a) = sinm(a).dot(inv(cosm(a)))

    >>> s = sinm(a)
    >>> c = cosm(a)
    >>> s.dot(np.linalg.inv(c))
    array([[ -2.00876993,  -8.41880636],
           [ -2.80626879, -10.42757629]])

    )r;   rN   r   r    r!   r8   s    r:   r"   r"   Ú  s+   € ôF 	˜Ó€AÜ�qœ%¤ Q£¬¨a«Ó1Ó2Ð2r<   c                 ób   — t        | «      } t        | dt        | «      t        |  «      z   z  «      S )a  
    Compute the hyperbolic matrix cosine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    coshm : (N, N) ndarray
        Hyperbolic matrix cosine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> c = coshm(a)
    >>> c
    array([[ 11.24592233,  38.76236492],
           [ 12.92078831,  50.00828725]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> t = tanhm(a)
    >>> s = sinhm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    r™   ©r;   rN   r   r8   s    r:   r#   r#     ó0   € ôF 	˜Ó€AÜ�q˜#¤ a£¬4°°«8Ñ!3Ñ4Ó5Ð5r<   c                 ób   — t        | «      } t        | dt        | «      t        |  «      z
  z  «      S )a  
    Compute the hyperbolic matrix sine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    sinhm : (N, N) ndarray
        Hyperbolic matrix sine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> s = sinhm(a)
    >>> s
    array([[ 10.57300653,  39.28826594],
           [ 13.09608865,  49.86127247]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> t = tanhm(a)
    >>> c = coshm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    r™   rŸ   r8   s    r:   r$   r$   (  r    r<   c           	      óh   — t        | «      } t        | t        t        | «      t	        | «      «      «      S )a  
    Compute the hyperbolic matrix tangent.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array

    Returns
    -------
    tanhm : (N, N) ndarray
        Hyperbolic matrix tangent of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> t = tanhm(a)
    >>> t
    array([[ 0.3428582 ,  0.51987926],
           [ 0.17329309,  0.86273746]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> s = sinhm(a)
    >>> c = coshm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    )r;   rN   r   r#   r$   r8   s    r:   r%   r%   O  s+   € ôF 	˜Ó€AÜ�qœ%¤ a£¬%°«(Ó3Ó4Ð4r<   c                 ó   — t        | «      } t        | «      \  }}t        ||«      \  }}|j                  \  }}t	         |t	        |«      «      «      }|j                  |j                  j                  «      }t        |d   «      }t        ||||«      \  }}t        t        ||«      t        t        |«      «      «      }t        | |«      }t        t        dœt         |j                  j                        }|dk(  r|}t#        dt%        |||z  t'        t)        |d«      d«      z  «      «      }	t+        t-        t/        t1        |«      «      «      d¬«      rt2        j4                  }	|r|	d|z  kD  rt7        d|	«       |S ||	fS )	a–  
    Evaluate a matrix function specified by a callable.

    Returns the value of matrix-valued function ``f`` at `A`. The
    function ``f`` is an extension of the scalar-valued function `func`
    to matrices.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix at which to evaluate the function
    func : callable
        Callable object that evaluates a scalar function f.
        Must be vectorized (eg. using vectorize).
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    funm : (N, N) ndarray
        Value of the matrix function specified by func evaluated at `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    Notes
    -----
    This function implements the general algorithm based on Schur decomposition
    (Algorithm 9.1.1. in [1]_).

    If the input matrix is known to be diagonalizable, then relying on the
    eigendecomposition is likely to be faster. For example, if your matrix is
    Hermitian, you can do

    >>> from scipy.linalg import eigh
    >>> def funm_herm(a, func, check_finite=False):
    ...     w, v = eigh(a, check_finite=check_finite)
    ...     ## if you further know that your matrix is positive semidefinite,
    ...     ## you can optionally guard against precision errors by doing
    ...     # w = np.maximum(w, 0)
    ...     w = func(w)
    ...     return (v * w).dot(v.conj().T)

    References
    ----------
    .. [1] Gene H. Golub, Charles F. van Loan, Matrix Computations 4th ed.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import funm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> funm(a, lambda x: x*x)
    array([[  4.,  15.],
           [  5.,  19.]])
    >>> a.dot(a)
    array([[  4.,  15.],
           [  5.,  19.]])

    )r   r   r?   r@   r   r   )ÚaxisrW   z0funm result may be inaccurate, approximate err =)r;   r   r   r6   r   rw   rG   rH   Úabsr   r   r	   r
   rN   rD   rE   rF   rr   Úmaxr   r   r   r   r   r   r3   ÚinfÚprint)
r9   Úfuncrc   ÚTÚZr„   r/   ÚmindenrM   Úerrs
             r:   r'   r'   v  sD  € ô~ 	˜Ó€Aä�‹8�D€A€qÜ�1�a‹=�D€A€qØ�7‰7�D€A€qÜ‰T”$�q“'‹]Ó€AØ	�‰�—‘—‘Ó€Aä��4‘‹\€Fô ˜A˜q ! VÓ,�I€A€väŒC��1‹I”y¤¨1£Ó.Ó/€AÜ�A�qÓ€Aä”sÑ
Ô,¨Q¯W©W¯\©\Ñ:Ñ
;€CØ�‚}ØˆÜ
ˆa”�S˜3˜v™:¤t¬D°°A«J¸Ó':Ñ:Ó;Ó
<€CÜŒE”+œh q›kÓ*Ó+°!Õ4Ü�f‰fˆÙØ��c‘Š>ÜÐDÀcÔJØˆà�#ˆvˆr<   c                 óR  — t        | «      } d„ }t        | |d¬«      \  }}dt        z  dt        z  dœt        |j
                  j                        }||k  r|S t        | d¬«      }t        j                  |«      }d|z  }| |t        j                  | j                  d   «      z  z   }	|}
t        d	«      D ]N  }t        |	«      }d|	|z   z  }	dt        |	|	«      |	z   z  }t        t        ||«      |z
  d
«      }||k  s|
|k(  r n|}
ŒP |rt!        |«      r||k\  rt#        d|«       |	S |	|fS )a'  
    Matrix sign function.

    Extension of the scalar sign(x) to matrices.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix at which to evaluate the sign function
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    signm : (N, N) ndarray
        Value of the sign function at `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    Examples
    --------
    >>> from scipy.linalg import signm, eigvals
    >>> a = [[1,2,3], [1,2,1], [1,1,1]]
    >>> eigvals(a)
    array([ 4.12488542+0.j, -0.76155718+0.j,  0.63667176+0.j])
    >>> eigvals(signm(a))
    array([-1.+0.j,  1.+0.j,  1.+0.j])

    c                 óè   — t        j                  | «      }|j                  j                  dk(  rdt        z  t        | «      z  }ndt        z  t        | «      z  }t        t        |«      |kD  |z  «      S )Nr,   r>   )	r3   rK   rG   rH   rD   r   rE   r   r   )r‡   ÚrxÚcs      r:   Úrounded_signzsignm.<locals>.rounded_sign÷  s[   € Ü�W‰W�Q‹ZˆØ�8‰8�=‰=˜CÒØ”D‘œ˜a›Ñ ‰Aà”C‘œ˜Q›‘ˆAÜ”X˜b“\ AÑ%¨Ñ+Ó,Ð,r<   r   )rc   r>   r?   F)Ú
compute_uvr™   éd   r   z1signm result may be inaccurate, approximate err =)r;   r'   rD   rE   rF   rG   rH   r   r3   r   Úidentityr6   r|   r   r   r   r   r¨   )r9   rc   r²   Úresultre   rd   ÚvalsÚmax_svr±   ÚS0Úprev_errestr-   ÚiS0ÚPps                 r:   r(   r(   Ô  s=  € ôB 	˜Ó€Aò-ô ˜!˜\°Ô2�N€FˆFØ”T‘˜c¤#™gÑ&Ô'7¸¿¹×8IÑ8IÑ'JÑK€FØ�‚Øˆô ˆq˜UÔ#€DÜ�W‰W�T‹]€Fð 	ˆF‰
€AØ	
ˆQŒr�{‰{˜1Ÿ7™7 1™:Ó&Ñ&Ñ	&€BØ€KÜ�3‹Zò ˆÜ�"‹gˆØ�"�s‘(‰^ˆØ”#�b˜"“+˜b‘.Ñ!ˆÜ”c˜"˜b“k "‘n aÓ(ˆØ�FŠ?˜k¨VÒ3ÙØ‰ðñ Ü˜Ô 6¨VÒ#3ÜÐEÀvÔNØˆ	à�6ˆzÐr<   c                 óv  — t        j                  | «      } t        j                  |«      }| j                  dk(  r|j                  dk(  st        d«      ‚| j                  d   |j                  d   k(  st        d«      ‚| j
                  dk(  s|j
                  dk(  rG| j                  d   |j                  d   z  }| j                  d   }t        j                  | ||f¬«      S | ddd…t         j                  dd…f   |dt         j                  dd…dd…f   z  }|j                  d	|j                  dd z   «      S )
aÁ  
    Khatri-rao product

    A column-wise Kronecker product of two matrices

    Parameters
    ----------
    a : (n, k) array_like
        Input array
    b : (m, k) array_like
        Input array

    Returns
    -------
    c:  (n*m, k) ndarray
        Khatri-rao product of `a` and `b`.

    Notes
    -----
    The mathematical definition of the Khatri-Rao product is:

    .. math::

        (A_{ij}  \bigotimes B_{ij})_{ij}

    which is the Kronecker product of every column of A and B, e.g.::

        c = np.vstack([np.kron(a[:, k], b[:, k]) for k in range(b.shape[1])]).T

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[1, 2, 3], [4, 5, 6]])
    >>> b = np.array([[3, 4, 5], [6, 7, 8], [2, 3, 9]])
    >>> linalg.khatri_rao(a, b)
    array([[ 3,  8, 15],
           [ 6, 14, 24],
           [ 2,  6, 27],
           [12, 20, 30],
           [24, 35, 48],
           [ 8, 15, 54]])

    r2   z(The both arrays should be 2-dimensional.r   z6The number of columns for both arrays should be equal.r   )r6   .N)rh   )	r3   r4   rn   r7   r6   rm   rt   ÚnewaxisÚreshape)rƒ   Úbr‹   r„   r±   s        r:   r*   r*   $  s  € ôZ 	�
‰
�1‹€AÜ
�
‰
�1‹€Aà�F‰F�aŠK˜AŸF™F ašKÜÐCÓDÐDà�7‰7�1‰:˜Ÿ™ ™Ò#Üð ,ó -ð 	-ð 	‡v�v�‚{�a—f‘f ’kØ�G‰G�A‰J˜Ÿ™ ™Ñ#ˆØ�G‰G�A‰JˆÜ�}‰}˜Q q¨! fÔ-Ð-ð 	
ˆ#Šq”"—*‘*šaÐ
Ñ  1 S¬"¯*©*²aºÐ%:Ñ#;Ñ;€AØ�9‰9�U˜QŸW™W Q R˜[Ñ(Ó)Ð)r<   )N)T)<r`   Ú	itertoolsr   Únumpyr3   r   r   r   r   r   r	   r
   r   r   r   r   r   Úscipy.linalgr   r   Ú_miscr   Ú_basicr   r   Ú_decomp_svdr   Ú_decomp_schurr   r   Ú_expm_frechetr   r   Ú_matfuncs_sqrtmr   Ú_matfuncs_expmr   r   Ú_linalg_pythranr   Ú__all__ÚfinforE   rD   rF   r;   rN   r)   r&   r   r�   r    r!   r"   r#   r$   r%   r'   r(   r*   r\   r<   r:   ú<module>rÎ      sç   ðó Ý ã ÷D÷ D÷ Dó D÷ 0Ý ß Ý ß )ß 2Ý "ß =Ý (ò&€ð €b‡h�hˆsƒm×Ñ€Ø€r‡x�x�ƒ}×Ñ€à ¨°¸ÀÑCÐ òó0òL+Ió\FòRdòNò%òP%òP$3òN$6òN$6òN$5óN[ó|Mó`?*r<   