ó
    pñ:i,|  ã                   óî  • S SK r S SKJr  S SKrS SKJrJrJrJrJ	r	J
r
JrJrJrJrJrJr  S SKJr  S SKJr  S SKJrJrJr  SSKJr  SS	KJrJr  SS
KJr  SSK J!r!J"r"  SSK#J$r$J%r%  SSK&J'r'  SSK(J)r)J*r*  SSK+J,r,  / SQr-\R\                  " S5      R^                  r/\R\                  " S5      R^                  r0SSS SS SS.r1S r2S'S jr3\" S5      S 5       r4\" S5      \4S j5       r5S r6S r7\\4S jr8\" S5      S 5       r9\" S5      S 5       r:\" S5      S 5       r;\" S5      S 5       r<\" S5      S  5       r=\" S5      S! 5       r>\" S5      S(S" j5       r?\" S5      \4S# j5       r@\" S$S%5      S& 5       rAg))é    N)Úproduct)ÚdotÚdiagÚprodÚlogical_notÚravelÚ	transposeÚ	conjugateÚabsoluteÚamaxÚsignÚisfiniteÚtriu)Ú_apply_over_batch)Ú_NoValue)ÚLinAlgErrorÚ	bandwidthÚLinAlgWarningé   )Únorm)ÚsolveÚinv)Úsvd)ÚschurÚrsf2csf)Úexpm_frechetÚ	expm_cond)Úrecursive_schur_sqrtm)Úpick_pade_structureÚpade_UV_calc)Ú_funm_loops)ÚexpmÚcosmÚsinmÚtanmÚcoshmÚsinhmÚtanhmÚlogmÚfunmÚsignmÚsqrtmÚfractional_matrix_powerr   r   Ú
khatri_raoÚdÚf)ÚiÚlr0   r/   ÚFÚDc                 óº   • [         R                  " U 5      n [        U R                  5      S:w  d   U R                  S   U R                  S   :w  a  [	        S5      eU $ )aS  
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    ÚY/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/scipy/linalg/_matfuncs.pyÚ_asarray_squarer?   '   sI   € ô$ 	�
Š
�1‹€AÜ
ˆ1�7‰7ƒ|�qÓ˜AŸG™G A™J¨!¯'©'°!©*Ó4ÜÐ;Ó<Ð<Ø€Hó    c                 ó<  • [         R                  " U 5      (       a€  [         R                  " U5      (       ae  Uc1  [        S-  [        S-  S.[
        UR                  R                        n[         R                  " UR                  SUS9(       a  UR                  nU$ )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)r7   Ú	isrealobjÚiscomplexobjÚfepsÚepsÚ_array_precisionÚdtypeÚcharÚallcloseÚimagÚreal)r=   ÚBÚtols      r>   Ú_maybe_realrR   ?   sk   € ô4 
‡|‚|�A‡�œ2Ÿ?š?¨1×-Ñ-Ø‰;Ü˜3‘h¤3 s¡7Ñ+Ô,<¸Q¿W¹W¿\¹\Ñ,JÑKˆCÜ�;Š;�q—v‘v˜s¨×-Ø—‘ˆAØ€Hr@   )r=   r6   c                 ój   • [        U 5      n SSKnUR                  R                  R	                  X5      $ )av  
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)r=   ÚtÚscipys      r>   r-   r-   e   s-   € ôT 	˜Ó€AÛ)Ø�<‰<×)Ñ)×BÑBÀ1ÓHÐHr@   c                 ór  • U[         L a  SnO[        R                  " S[        SS9  [        R
                  " U 5      n SSKnUR                  R                  R                  U 5      n[        X5      nS[        -  n[        R                  " SSS	9   [        [        U5      U -
  S
5      [        R
                  " [        U S
5      U R                  S9R                   S   -  nSSS5        U(       a6  [#        W5      (       a  XT:¼  a  SU 3n[        R                  " U[$        SS9  U$ UW4$ ! , (       d  f       NO= f)aG  
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)

    .. deprecated:: 1.16.0
        The `disp` argument is deprecated and will be
        removed in SciPy 1.18.0. The previously returned error estimate
        can be computed as ``norm(expm(logm(A)) - A, 1) / norm(A, 1)``.

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.]])

TúFThe `disp` argument is deprecated and will be removed in SciPy 1.18.0.r6   ©Ú
stacklevelr   Néè  Úignore)ÚdivideÚinvalidr   ©rK   © z1logm result may be inaccurate, approximate err = )r   ÚwarningsÚwarnÚDeprecationWarningr7   r8   rT   rU   rV   Ú_logmrR   rI   Úerrstater   r"   rK   rO   r   ÚRuntimeWarning)r=   ÚdisprY   r3   ÚerrtolÚerrestÚmessages          r>   r)   r)   ”   sû   € ðz ŒxÒØ‰ä�Šð =ä(°Qò	8ô 	�
Š
�1‹€Aã)Ø�‰×&Ñ&×,Ñ,¨QÓ/€AÜ�AÓ€AØ”#‰X€Fä	�Š˜H¨hÓ	7Ü”d˜1“g˜a‘i Ó#¤b§j¢j´°a¸³À1Ç7Á7Ñ&K×&PÑ&PÐQSÑ&TÑTˆ÷ 
8æÜ˜×Ñ 6Ó#3ØIÈ&ÈÐRˆGÜ�MŠM˜'¤>¸aÒ@Øˆà�&ˆyÐ÷ 
8Õ	7ús   ÂAD(Ä(
D6c           
      óª	  • [         R                  " U 5      nUR                  S:X  aJ  UR                  S:  a:  [         R                  " [         R
                  " UR                  5       5      //5      $ UR                  S:  a  [        S5      eUR                  S   UR                  S   :w  a  [        S5      e[        UR                  6 S:X  aF  [        [         R                  " SUR                  S95      R                  n[         R                  " XS9$ UR                  SS	 S
:X  a  [         R
                  " U5      $ [         R                  " UR                  [         R                  5      (       d   UR!                  [         R"                  5      nO=UR                  [         R$                  :X  a  UR!                  [         R&                  5      nUR                  S   n[         R(                  " UR                  UR                  S9n[         R(                  " SX34UR                  S9n[+        UR                  S	S  Vs/ s H  n[-        U5      PM     sn6  GHt  nX   n[/        U5      n	[1        U	5      (       dB  [         R2                  " [         R
                  " [         R2                  " U5      5      5      XG'   Me  X…SS	S	2S	S	24'   [5        U5      u  p«U
S:  a  [7        SU
 S35      e[9        XZ5      nUS:w  a$  US::  a  [7        SU S35      e[;        SU S35      eUS   nUS:w  GaQ  U	S   S:X  d
  U	S   S:X  Ga(  [         R2                  " U5      n[         R
                  " USU* -  -  5      [         R<                  " SU5      S	S	& [         R2                  " X‰S   S:X  a  SOSS9n[-        US-
  SS5       H©  nXÝ-  n[         R
                  " USU* -  -  5      [         R<                  " SU5      S	S	& [?        USU* -  -  5      USU* -  -  -  nU	S   S:X  a%  U[         R<                  " SUSS	2S	S24   5      S	S	& M†  U[         R<                  " SUS	S2SS	24   5      S	S	& M«     O[-        U5       H  nXÝ-  nM	     U	S   S:X  d	  U	S   S:X  a:  U	S   S:X  a  [         R@                  " U5      O[         RB                  " U5      XG'   GMp  XÔU'   GMw     U$ s  snf )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   r6   ú0The input array must be at least two-dimensionaléÿÿÿÿéþÿÿÿú-Last 2 dimensions of the array must be squarer   rb   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       @)"r7   r8   ÚsizeÚndimÚarrayÚexpÚitemr   r:   Úminr"   ÚeyerK   Ú
empty_likeÚ
issubdtypeÚinexactÚastypeÚfloat64Úfloat16Úfloat32Úemptyr   Úranger   Úanyr   r   ÚMemoryErrorr    ÚRuntimeErrorÚeinsumÚ
_exp_sinchr   Útril)r=   ÚarK   ÚnÚeAÚAmÚxÚindÚawÚluÚmÚsÚinfoÚeAwÚdiag_awÚsdr1   Úexp_sdÚ_s                      r>   r"   r"   é   s  € ô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Ñ,Ð,ð 	‡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ˆØ‰Vˆä�r‹]ˆÜ�2�w‰wÜ—g’gœbŸfšf¤R§W¢W¨R£[Ó1Ó2ˆB‰GÙð
 ˆ1Ša’ˆ7‰Ü" 2Ó&‰ˆØ�‹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¨Ö+�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¹Ò;ò ,ô ˜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ŒGàˆsŒGñ} :ð@ €IùòA 9s   È<Sc                 óì   • [         R                  " [         R                  " U 5      5      n[         R                  " U 5      nUS:H  nX) ==   X#)    -  ss'   [         R                  " U S S U   5      X'   U$ )NrD   rp   )r7   Údiffrz   )r‘   Ú	lexp_diffÚl_diffÚmask_zs       r>   r‹   r‹   �  sc   € ä—’œŸš˜q›	Ó"€IÜ�WŠW�Q‹Z€FØ�r‰\€FØˆgÓ˜& ™/Ñ)ÓÜŸš˜q  "˜v f™~Ó.€IÑØÐr@   c                 óÒ  • U[         L a  SnO[        R                  " S[        SS9  U[         La  [        R                  " S[        SS9  [        R
                  " U 5      nUR                  S:X  aJ  UR                  S:  a:  [        R                  " [        R                  " UR                  5       5      //5      $ UR                  S:  a  [        S5      eUR                  S   UR                  S	   :w  a  [        S
5      e[        UR                  6 S:X  aF  [        [        R                  " SUR                   S95      R                   n[        R"                  " X4S9$ UR                  S	S S:X  a  [        R$                  R'                  U5      $ [        R(                  " UR                   [        R*                  5      (       d   UR-                  [        R.                  5      nO±UR                   [        R0                  :X  a   UR-                  [        R2                  5      nOsUR                   R4                  S;   a   UR-                  [        R6                  5      nO9UR                   R4                  S;   a  UR-                  [        R.                  5      nUR                   R4                  S;  a  [9        SUR                    35      e[;        U5      u  pVpxUS:  a  [        SU 35      eU(       d  U(       a&  U(       a  Sn	OSn	[        R                  " U	[<        SS9  USL a%   [?        XU-  U -
  S5      S-  [?        U S5      -  n
XZ4$ U$ ! [@         a    [        RB                  n
 XZ4$ f = f)a`
  
Compute, if exists, the matrix square root.

The matrix square root of ``A`` is a matrix ``X`` such that ``X @ X = A``.
Every square matrix is not guaranteed to have a matrix square root, for
example, the array ``[[0, 1], [0, 0]]`` does not have a square root.

Moreover, not every real matrix has a real square root. Hence, for
real-valued matrices the return type can be complex if, numerically, there
is an eigenvalue on the negative real axis.

Parameters
----------
A : ndarray
    Input with last two dimensions are square ``(..., n, n)``.
disp : bool, optional
    Print warning if error in the result is estimated large
    instead of returning estimated error. (Default: True)

    .. deprecated:: 1.16.0
        The `disp` argument is deprecated and will be
        removed in SciPy 1.18.0. The previously returned error estimate
        can be computed as ``norm(X @ X - A, 'fro')**2 / norm(A, 'fro')``

blocksize : integer, optional

    .. deprecated:: 1.16.0
        The `blocksize` argument is deprecated as it is unused by the algorithm
        and will be removed in SciPy 1.18.0.

Returns
-------
sqrtm : ndarray
    Computed matrix squareroot of `A` with same size ``(..., n, n)``.

errest : float
    Frobenius norm of the estimated error, ||err||_F / ||A||_F. Only
    returned, if ``disp`` is set to ``False``. This return argument will be
    removed in version 1.20.0 and only the sqrtm result will be returned.

    .. deprecated:: 1.16.0

Notes
-----
This function uses the Schur decomposition method to compute the matrix
square root following [1]_ and for real matrices [2]_. Moreover, note
that, there exist matrices that have square roots that are not polynomials
in ``A``. For a classical example from [2]_, the matrix satisfies::

        [ a, a**2 + 1]**2     [-1,  0]
        [-1,       -a]     =  [ 0, -1]

for any scalar ``a`` but it is not a polynomial in ``-I``. Thus, they will
not be found by this function.

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.
       :doi:`10.1016/0024-3795(87)90118-2`
.. [2] Nicholas J. Higham (1987) "Computing real square roots of a real
       matrix", Linear Algebra and its Applications, 88/89:405-430.
       :doi:`10.1016/0024-3795(87)90118-2`

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.]])

Tr[   r6   r\   zKThe `blocksize` argument is deprecated and will be removed in SciPy 1.18.0.r   ro   rp   rq   rr   r   rb   Nrs   ÚGÚgÚfdFDz6scipy.linalg.sqrtm is not supported for the data type z&Internal error in scipy.linalg.sqrtm: z]Matrix is singular. The result might be inaccurate or the array might not have a square root.zdMatrix is ill-conditioned. The result might be inaccurate or the array might not have a square root.FÚfro)"r   rd   re   rf   r7   r8   rw   rx   ry   rz   r{   r   r:   r|   r,   r}   rK   r~   ÚemathÚsqrtr   r€   r�   r‚   rƒ   r„   rL   Ú
complex128Ú	TypeErrorr   r   r   r;   Úinf)r=   rj   Ú	blocksizer�   rK   ÚresÚisIllconditionedÚ
isSingularr—   ÚmsgÚarg2s              r>   r,   r,   š  s¦  € ð` ŒxÒØ‰ä�Šð  ä(°Qò	8ð œÒ Ü�Šð &ä(°Qò	8ô 	�
Š
�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€}˜ÓÜ”b—f’f˜Q a§g¡gÑ.Ó/×5Ñ5ˆÜ�}Š}˜QÑ,Ð,ð 	‡w�wˆrˆs€|�vÓÜ�x‰x�}‰}˜QÓÐä�=Š=˜Ÿ™¤"§*¡*×-Ñ-Ø�H‰H”R—Z‘ZÓ ‰Ø	
�‰”B—J‘JÓ	Ø�H‰H”R—Z‘ZÓ ‰Ø	
�‰�‰˜Ó	Ø�H‰H”R—]‘]Ó#‰Ø	
�‰�‰˜Ó	Ø�H‰H”R—Z‘ZÓ ˆà‡w�w‡|�|˜6Ó!Üð ØŸG™G˜9ð&ó 'ð 	'ô /DÀAÓ.FÑ+€C˜:ØˆaƒxÜÐBÀ4À&ÐIÓJÐJæÖ%Þð:‰CðAˆCä�Š�cœ=°QÒ7àˆu‚}ð	Ü˜™	 A™ uÓ-¨qÑ0´4¸¸5³>ÑAˆDð ˆyÐàˆ
øô ó 	ä—6‘6‰DØˆyÐð	ús   Ì!!M ÍM&Í%M&c                 ó¾   • [        U 5      n [        R                  " U 5      (       a   S[        SU -  5      [        SU -  5      -   -  $ [        SU -  5      R                  $ )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?   r7   rG   r"   rO   r<   s    r>   r#   r#   ,  sP   € ôD 	˜Ó€AÜ	‡‚�q×ÑØ”D˜˜A™“J¤ c¨!¡e£Ñ,Ñ-Ð-ä�B�q‘D‹z�‰Ðr@   c                 ó¾   • [        U 5      n [        R                  " U 5      (       a   S[        SU -  5      [        SU -  5      -
  -  $ [        SU -  5      R                  $ )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?   r7   rG   r"   rN   r<   s    r>   r$   r$   U  sP   € ôD 	˜Ó€AÜ	‡‚�q×ÑØ”d˜2˜a™4“j¤4¨¨A©£;Ñ.Ñ/Ð/ä�B�q‘D‹z�‰Ðr@   c           	      óh   • [        U 5      n [        U [        [        U 5      [	        U 5      5      5      $ )aq  
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?   rR   r   r#   r$   r<   s    r>   r%   r%   ~  s+   € ôH 	˜Ó€AÜ�qœ%¤ Q£¬¨a«Ó1Ó2Ð2r@   c                 ób   • [        U 5      n [        U S[        U 5      [        U * 5      -   -  5      $ )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?   rR   r"   r<   s    r>   r&   r&   ¦  ó0   € ôH 	˜Ó€AÜ�q˜#¤ a£¬4°°«8Ñ!3Ñ4Ó5Ð5r@   c                 ób   • [        U 5      n [        U S[        U 5      [        U * 5      -
  -  5      $ )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¹   r<   s    r>   r'   r'   Î  rº   r@   c           	      óh   • [        U 5      n [        U [        [        U 5      [	        U 5      5      5      $ )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?   rR   r   r&   r'   r<   s    r>   r(   r(   ö  s+   € ôH 	˜Ó€AÜ�qœ%¤ a£¬%°«(Ó3Ó4Ð4r@   c                 óþ  • [        U 5      n [        U 5      u  p4[        X45      u  p4UR                  u    n[	        U" [	        U5      5      5      nUR                  UR                  R                  5      n[        US   5      n[        XcXW5      u  pg[        [        XF5      [        [        U5      5      5      n[        X5      n[        [        S.[         UR                  R                        nUS:X  a  Un[#        S[%        XˆU-  ['        [)        US5      S5      -  5      5      n	[+        [-        [/        [1        U5      5      5      SS9(       a  [2        R4                  n	U(       a  U	SU-  :”  a  [7        SU	5        U$ Xi4$ )	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   rC   rD   r   r   )Úaxisr^   z0funm result may be inaccurate, approximate err =)r?   r   r   r:   r   r�   rK   rL   Úabsr!   r   r	   r
   rR   rH   rI   rJ   r|   Úmaxr   r   r   r   r   r   r7   r«   Úprint)
r=   Úfuncrj   ÚTÚZrŽ   r3   ÚmindenrQ   Úerrs
             r>   r*   r*     s0  € ô@ 	˜Ó€Aä�‹8�D€AÜ�1‹=�D€AØ�7‰7�D€A€qÜ‰T”$�q“'‹]Ó€AØ	�‰�—‘—‘Ó€Aä��4‘‹\€Fô ˜A !Ó,�I€AäŒC�‹I”y¤¨1£Ó.Ó/€AÜ�AÓ€Aä”sÑ
Ô,¨Q¯W©W¯\©\Ñ:Ñ
;€CØ�ƒ}ØˆÜ
ˆa”�S˜v™:¤t¬D°°A«J¸Ó':Ñ:Ó;Ó
<€CÜŒE”+œh q›kÓ*Ó+°!×4Ü�f‰fˆÞØ��c‘‹>ÜÐDÀcÔJØˆàˆvˆr@   c                 ó   • U[         L a  SnO[        R                  " S[        SS9  [	        U 5      n S n[        XSS9u  p4S[        -  S[        -  S	.[        UR                  R                        nXE:  a  U$ [        U S
S9n[        R                  " U5      nSU-  nX[        R                  " U R                  S   5      -  -   n	Un
[!        S5       HL  n[#        U	5      nSXœ-   -  n	S[%        X™5      U	-   -  n['        [%        XÝ5      U-
  S5      nXE:  d  X¤:X  a    OUn
MN     U(       a#  [)        U5      (       a  XE:¼  a  [+        SU5        U	$ X”4$ )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)

    .. deprecated:: 1.16.0
        The `disp` argument is deprecated and will be
        removed in SciPy 1.18.0. The previously returned error estimate
        can be computed as ``norm(signm @ signm - signm, 1)``.

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])

Tr[   r6   r\   c                 óì   • [         R                  " U 5      nUR                  R                  S:X  a  S[        -  [        U 5      -  nOS[        -  [        U 5      -  n[        [        U5      U:„  U-  5      $ )Nr0   rB   )	r7   rO   rK   rL   rH   r   rI   r   r   )r‘   ÚrxÚcs      r>   Úrounded_signÚsignm.<locals>.rounded_sign­  s[   € Ü�WŠW�Q‹ZˆØ�8‰8�=‰=˜CÓØ”D‘œ˜a›Ñ ‰Aà”C‘œ˜Q›‘ˆAÜ”X˜b“\ AÑ%¨Ñ+Ó,Ð,r@   r   )rj   rB   rC   F)Ú
compute_uvr³   éd   r   z1signm result may be inaccurate, approximate err =)r   rd   re   rf   r?   r*   rH   rI   rJ   rK   rL   r   r7   r   Úidentityr:   r†   r   r   r   r   rÁ   )r=   rj   rË   Úresultrl   rk   ÚvalsÚmax_svrÊ   ÚS0Úprev_errestr1   ÚiS0ÚPps                 r>   r+   r+   }  sJ  € ðN ŒxÒØ‰ä�Šð =ä(°Qò	8ô 	˜Ó€Aò-ô ˜!°Ñ2�N€FØ”T‘˜c¤#™gÑ&Ô'7¸¿¹×8IÑ8IÑ'JÑK€FØƒØˆô ˆq˜UÑ#€DÜ�WŠW�T‹]€Fð 	ˆF‰
€AØ	
Œr�{Š{˜1Ÿ7™7 1™:Ó&Ñ&Ñ	&€BØ€KÜ�3ŽZˆÜ�"‹gˆØ�"‘(‰^ˆØ”#�b“+˜b‘.Ñ!ˆÜ”c˜"“k "‘n aÓ(ˆØ‹?˜kÓ3ÙØŠñ ö Ü˜×Ñ 6Ó#3ÜÐEÀvÔNØˆ	àˆzÐr@   )r�   r6   )Úbr6   c                 ó~  • [         R                  " U 5      n [         R                  " U5      nU R                  S:X  a  UR                  S:X  d  [        S5      eU R                  S   UR                  S   :X  d  [        S5      eU R
                  S:X  d  UR
                  S:X  aD  U R                  S   UR                  S   -  nU R                  S   n[         R                  " XU4S9$ U SSS2[         R                  SS24   US[         R                  SS2SS24   -  nUR                  S	UR                  SS -   5      $ )
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]])

r6   z(The both arrays should be 2-dimensional.r   z6The number of columns for both arrays should be equal.r   )r:   .N)rp   )	r7   r8   rx   r;   r:   rw   r~   ÚnewaxisÚreshape)r�   r×   r•   rŽ   rÊ   s        r>   r.   r.   Ú  s	  € ô\ 	�
Š
�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¨! fÑ-Ð-ð 	
ˆ#Šq”"—*‘*šaÐ
Ñ  1 S¬"¯*©*²aºÐ%:Ñ#;Ñ;€AØ�9‰9�U˜QŸW™W Q R˜[Ñ(Ó)Ð)r@   )N)T)Brd   Ú	itertoolsr   Únumpyr7   r   r   r   r   r   r	   r
   r   r   r   r   r   Úscipy._lib._utilr   Úscipy._lib.deprecationr   Úscipy.linalgr   r   r   Ú_miscr   Ú_basicr   r   Ú_decomp_svdr   Ú_decomp_schurr   r   Ú_expm_frechetr   r   Ú_matfuncs_schur_sqrtmr   Ú_matfuncs_expmr   r    Ú_linalg_pythranr!   Ú__all__ÚfinforI   rH   rJ   r?   rR   r-   r)   r"   r‹   r,   r#   r$   r%   r&   r'   r(   r*   r+   r.   rc   r@   r>   Ú<module>rê      sä  ðó Ý ã ÷D÷ D÷ Dó Dõ /Ý +÷ ?Ñ >Ý ß Ý ß )ß 2Ý 8ß =Ý (ò&€ð 	‡h‚hˆsƒm×Ñ€Ø	‡x‚x�ƒ}×Ñ€à ¨°¸ÀÑCÐ òô0ñL �8Óñ+Ió ð+Iñ\ �8ÓØó Qó ðQòhdòNð  hô Oñd �8Óñ%ó ð%ñP �8Óñ%ó ð%ñP �8Óñ$3ó ð$3ñN �8Óñ$6ó ð$6ñN �8Óñ$6ó ð$6ñN �8Óñ$5ó ð$5ñN �8Óó[ó ð[ñ| �8ÓØó Yó ðYñx �8˜XÓ&ñ?*ó 'ñ?*r@   