Ë
    âQ(hšr  ã                   ó,  — d Z g d¢ZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlZddl	ZddlmZ dd	lmZ d
dlmZmZ dZd„ Zd„ Zd„ Zd!d„Z G d„ de«      Z G d„ de«      Z	 d"d„Z	 d"d„Z  G d„ d«      Z!d„ Z"d„ Z#d#d„Z$d„ Z%d„ Z&d„ Z'd„ Z(d „ Z)y)$z
Sparse matrix functions
)ÚexpmÚinvÚmatrix_poweré    N)ÚsolveÚsolve_triangular)Úissparse)Úspsolve)Úis_pydata_spmatrixÚ	isintlike)ÚLinearOperator)Ú	eye_arrayé   )Ú_ident_likeÚ_exact_1_normÚupper_triangularc                 óv   — t        | «      st        | «      st        d«      ‚t        | «      }t	        | |«      }|S )aË  
    Compute the inverse of a sparse arrays

    Parameters
    ----------
    A : (M, M) sparse arrays
        square matrix to be inverted

    Returns
    -------
    Ainv : (M, M) sparse arrays
        inverse of `A`

    Notes
    -----
    This computes the sparse inverse of `A`. If the inverse of `A` is expected
    to be non-sparse, it will likely be faster to convert `A` to dense and use
    `scipy.linalg.inv`.

    Examples
    --------
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import inv
    >>> A = csc_array([[1., 0.], [1., 2.]])
    >>> Ainv = inv(A)
    >>> Ainv
    <Compressed Sparse Column sparse array of dtype 'float64'
        with 3 stored elements and shape (2, 2)>
    >>> A.dot(Ainv)
    <Compressed Sparse Column sparse array of dtype 'float64'
        with 2 stored elements and shape (2, 2)>
    >>> A.dot(Ainv).toarray()
    array([[ 1.,  0.],
           [ 0.,  1.]])

    .. versionadded:: 0.12.0

    zInput must be a sparse arrays)r   r
   Ú	TypeErrorr   r	   )ÚAÚIÚAinvs      ú[/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_matfuncs.pyr   r      s;   € ôP �QŒKÔ-¨aÔ0ÜÐ7Ó8Ð8ô 	�A‹€AÜ�1�a‹=€DØ€Kó    c                 ó°  — t        |«      |k7  s|dk  rt        d«      ‚t        |«      }t        | j                  «      dk7  s| j                  d   | j                  d   k7  rt        d«      ‚t	        j
                  | j                  d   dft        ¬«      }| j                  }t        |«      D ]  }|j                  |«      }Œ t	        j                  |«      S )a†  
    Compute the 1-norm of a non-negative integer power of a non-negative matrix.

    Parameters
    ----------
    A : a square ndarray or matrix or sparse arrays
        Input matrix with non-negative entries.
    p : non-negative integer
        The power to which the matrix is to be raised.

    Returns
    -------
    out : float
        The 1-norm of the matrix power p of A.

    r   zexpected non-negative integer pé   r   ú%expected A to be like a square matrix©Údtype)ÚintÚ
ValueErrorÚlenÚshapeÚnpÚonesÚfloatÚTÚrangeÚdotÚmax)r   ÚpÚvÚMÚis        r   Ú_onenorm_matrix_power_nnmr-   P   s²   € ô$ ˆ1ƒv�‚{�a˜!’eÜÐ:Ó;Ð;ÜˆA‹€AÜ
ˆ1�7‰7ƒ|�qÒ˜AŸG™G A™J¨!¯'©'°!©*Ò4ÜÐ@ÓAÐAô 	�‰�—‘˜‘˜Q�¤uÔ-€AØ	�‰€AÜ�1‹Xò ˆØ�E‰E�!‹H‰ðä�6‰6�!‹9Ðr   c                 óJ  — t        | «      rDt        j                  j                  | d«      }|j                  dk(  xs |j                  «       dk(  S t        | «      r%dd l}|j                  | d«      }|j                  dk(  S t        j                  | d«      j                  «        S )Néÿÿÿÿr   )	r   ÚscipyÚsparseÚtrilÚnnzÚcount_nonzeror
   r"   Úany)r   Ú
lower_partr1   s      r   Ú_is_upper_triangularr7   q   s‰   € ä�„{Ü—\‘\×&Ñ& q¨"Ó-ˆ
ð �~‰~ Ñ"ÒE j×&>Ñ&>Ó&@ÀAÑ&EÐEÜ	˜AÔ	ÛØ—[‘[  BÓ'ˆ
Ø�~‰~ Ñ"Ð"ä—7‘7˜1˜b“>×%Ñ%Ó'Ð'Ð'r   c                 ó¾  — t        | j                  «      dk7  rt        d«      ‚t        |j                  «      dk7  rt        d«      ‚d}|t        k(  rPt	        | «      sEt	        |«      s:t        | «      s/t        |«      s$t        j                  j                  d| |f«      \  }|�|€d} ||| |«      }|S |€| j                  |«      }|S || j                  |«      z  }|S )aù  
    A matrix product that knows about sparse and structured matrices.

    Parameters
    ----------
    A : 2d ndarray
        First matrix.
    B : 2d ndarray
        Second matrix.
    alpha : float
        The matrix product will be scaled by this constant.
    structure : str, optional
        A string describing the structure of both matrices `A` and `B`.
        Only `upper_triangular` is currently supported.

    Returns
    -------
    M : 2d ndarray
        Matrix product of A and B.

    r   z%expected A to be a rectangular matrixz%expected B to be a rectangular matrixN)Útrmmç      ð?)
r    r!   r   ÚUPPER_TRIANGULARr   r
   r0   ÚlinalgÚget_blas_funcsr'   )r   ÚBÚalphaÚ	structureÚfÚouts         r   Ú_smart_matrix_productrC   €   sÚ   € ô, ˆ1�7‰7ƒ|�qÒÜÐ@ÓAÐAÜ
ˆ1�7‰7ƒ|�qÒÜÐ@ÓAÐAØ€AØÔ$Ò$Ü˜”¤H¨Q¤KÜ*¨1Ô-Ô6HÈÔ6KÜ—‘×,Ñ,¨Y¸¸A¸Ó?‰BˆAØ€}Øˆ=ØˆEÙ��q˜!‹nˆð €Jð	 ˆ=Ø—%‘%˜“(ˆCð €Jð ˜!Ÿ%™% ›(Ñ"ˆCØ€Jr   c                   ó6   — e Zd Zdd„Zd„ Zd„ Zd„ Zed„ «       Zy)ÚMatrixPowerOperatorNc                 ó&  — |j                   dk7  s|j                  d   |j                  d   k7  rt        d«      ‚|dk  rt        d«      ‚|| _        || _        || _        |j                  | _        |j                   | _         |j                  | _        y )Nr   r   r   r   z'expected p to be a non-negative integer)Úndimr!   r   Ú_AÚ_pÚ
_structurer   )Úselfr   r)   r@   s       r   Ú__init__zMatrixPowerOperator.__init__­   sy   € Ø�6‰6�QŠ;˜!Ÿ'™' !™*¨¯©°©
Ò2ÜÐDÓEÐEØˆqŠ5ÜÐFÓGÐGØˆŒØˆŒØ#ˆŒØ—W‘WˆŒ
Ø—F‘FˆŒ	Ø—W‘Wˆ�
r   c                 óp   — t        | j                  «      D ]  }| j                  j                  |«      }Œ |S ©N)r&   rI   rH   r'   )rK   Úxr,   s      r   Ú_matveczMatrixPowerOperator._matvec¹   s/   € Ü�t—w‘w“ò 	ˆAØ—‘—‘˜A“‰Að	àˆr   c                 ó¨   — | j                   j                  }|j                  «       }t        | j                  «      D ]  }|j                  |«      }Œ |S rN   )rH   r%   Úravelr&   rI   r'   )rK   rO   ÚA_Tr,   s       r   Ú_rmatveczMatrixPowerOperator._rmatvec¾   sC   € Ø�g‰g�i‰iˆØ�G‰G‹IˆÜ�t—w‘w“ò 	ˆAØ—‘˜“
‰Að	àˆr   c                 ó~   — t        | j                  «      D ]$  }t        | j                  || j                  ¬«      }Œ& |S ©N©r@   )r&   rI   rC   rH   rJ   )rK   ÚXr,   s      r   Ú_matmatzMatrixPowerOperator._matmatÅ   s6   € Ü�t—w‘w“ò 	MˆAÜ% d§g¡g¨q¸D¿O¹OÔL‰Að	Màˆr   c                 óV   — t        | j                  j                  | j                  «      S rN   )rE   rH   r%   rI   ©rK   s    r   r%   zMatrixPowerOperator.TÊ   s   € ä" 4§7¡7§9¡9¨d¯g©gÓ6Ð6r   rN   )	Ú__name__Ú
__module__Ú__qualname__rL   rP   rT   rY   Úpropertyr%   © r   r   rE   rE   «   s*   „ ó
òò
òð
 ñ7ó ñ7r   rE   c                   ó8   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zed„ «       Z	y)ÚProductOperatorzK
    For now, this is limited to products of multiple square matrices.
    c                 óø  — |j                  dd «      | _        |D ]D  }t        |j                  «      dk7  s |j                  d   |j                  d   k7  sŒ;t	        d«      ‚ |r]|d   j                  d   }|D ]#  }|j                  D ]  }||k7  sŒ	t	        d«      ‚ Œ% ||f| _        t        | j                  «      | _        t        j                  |D �cg c]  }|j                  ‘Œ c}Ž | _        || _	        y c c}w )Nr@   r   r   r   zbFor now, the ProductOperator implementation is limited to the product of multiple square matrices.zHThe square matrices of the ProductOperator must all have the same shape.)
ÚgetrJ   r    r!   r   rG   r"   Úresult_typer   Ú_operator_sequence)rK   ÚargsÚkwargsr   ÚnÚdrO   s          r   rL   zProductOperator.__init__Ô   s  € Ø Ÿ*™* [°$Ó7ˆŒØò 	OˆAÜ�1—7‘7‹|˜qÒ  A§G¡G¨A¡J°!·'±'¸!±*Ó$<Ü ðNóOð Oð	Oñ
 Ø�Q‘—‘˜aÑ ˆAØò A�ØŸ™ò A�AØ˜A“vÜ(ð!@óAð AñAðAð ˜Q˜ˆDŒJÜ˜DŸJ™J›ˆDŒIÜ—^‘^°tÖ%<°! a§g£gÒ%<Ð=ˆŒ
Ø"&ˆÕùò &=s   ÃC7c                 ó\   — t        | j                  «      D ]  }|j                  |«      }Œ |S rN   )Úreversedrf   r'   ©rK   rO   r   s      r   rP   zProductOperator._matvecè   s.   € Ü˜$×1Ñ1Ó2ò 	ˆAØ—‘�a“‰Að	àˆr   c                 ó~   — |j                  «       }| j                  D ]  }|j                  j                  |«      }Œ |S rN   )rR   rf   r%   r'   rm   s      r   rT   zProductOperator._rmatvecí   s8   € Ø�G‰G‹IˆØ×(Ñ(ò 	ˆAØ—‘—‘˜“
‰Að	àˆr   c                 ój   — t        | j                  «      D ]  }t        ||| j                  ¬«      }Œ |S rV   )rl   rf   rC   rJ   )rK   rX   r   s      r   rY   zProductOperator._matmató   s5   € Ü˜$×1Ñ1Ó2ò 	GˆAÜ% a¨°d·o±oÔF‰Að	Gàˆr   c                 ót   — t        | j                  «      D �cg c]  }|j                  ‘Œ }}t        |Ž S c c}w rN   )rl   rf   r%   rb   )rK   r   ÚT_argss      r   r%   zProductOperator.Tø   s5   € ä'¨×(?Ñ(?Ó@ÖA˜!�!—#“#ÐAˆÐAÜ Ð'Ð'ùò Bs   ˜5N)
r\   r]   r^   Ú__doc__rL   rP   rT   rY   r_   r%   r`   r   r   rb   rb   Ï   s/   „ ñò'ò(ò
òð
 ñ(ó ñ(r   rb   c                 ól   — t         j                  j                  j                  t	        | ||¬«      «      S )aÃ  
    Efficiently estimate the 1-norm of A^p.

    Parameters
    ----------
    A : ndarray
        Matrix whose 1-norm of a power is to be computed.
    p : int
        Non-negative integer power.
    t : int, optional
        A positive parameter controlling the tradeoff between
        accuracy versus time and memory usage.
        Larger values take longer and use more memory
        but give more accurate output.
    itmax : int, optional
        Use at most this many iterations.
    compute_v : bool, optional
        Request a norm-maximizing linear operator input vector if True.
    compute_w : bool, optional
        Request a norm-maximizing linear operator output vector if True.

    Returns
    -------
    est : float
        An underestimate of the 1-norm of the sparse arrays.
    v : ndarray, optional
        The vector such that ||Av||_1 == est*||v||_1.
        It can be thought of as an input to the linear operator
        that gives an output with particularly large norm.
    w : ndarray, optional
        The vector Av which has relatively large 1-norm.
        It can be thought of as an output of the linear operator
        that is relatively large in norm compared to the input.

    rW   )r0   r1   r<   Ú
onenormestrE   )r   r)   ÚtÚitmaxÚ	compute_vÚ	compute_wr@   s          r   Ú_onenormest_matrix_powerry   þ   s.   € ôJ �<‰<×Ñ×)Ñ)Ü  1°	Ô:ó<ð <r   c                 óf   — t         j                  j                  j                  t	        | d|iŽ«      S )a^  
    Efficiently estimate the 1-norm of the matrix product of the args.

    Parameters
    ----------
    operator_seq : linear operator sequence
        Matrices whose 1-norm of product is to be computed.
    t : int, optional
        A positive parameter controlling the tradeoff between
        accuracy versus time and memory usage.
        Larger values take longer and use more memory
        but give more accurate output.
    itmax : int, optional
        Use at most this many iterations.
    compute_v : bool, optional
        Request a norm-maximizing linear operator input vector if True.
    compute_w : bool, optional
        Request a norm-maximizing linear operator output vector if True.
    structure : str, optional
        A string describing the structure of all operators.
        Only `upper_triangular` is currently supported.

    Returns
    -------
    est : float
        An underestimate of the 1-norm of the sparse arrays.
    v : ndarray, optional
        The vector such that ||Av||_1 == est*||v||_1.
        It can be thought of as an input to the linear operator
        that gives an output with particularly large norm.
    w : ndarray, optional
        The vector Av which has relatively large 1-norm.
        It can be thought of as an output of the linear operator
        that is relatively large in norm compared to the input.

    r@   )r0   r1   r<   rt   rb   )Úoperator_seqru   rv   rw   rx   r@   s         r   Ú_onenormest_productr|   '  s1   € ôL �<‰<×Ñ×)Ñ)Ü˜\Ð?°YÑ?óAð Ar   c                   ó  — e Zd ZdZdd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed	„ «       Zed
„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zd„ Zd„ Zd„ Zd„ Zd„ Zy)Ú_ExpmPadeHelperzã
    Help lazily evaluate a matrix exponential.

    The idea is to not do more work than we need for high expm precision,
    so we lazily compute matrix powers and store or precompute
    other properties of the matrix.

    Nc                 ó  — || _         d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        t        |«      | _        || _        || _        y)a>  
        Initialize the object.

        Parameters
        ----------
        A : a dense or sparse square numpy matrix or ndarray
            The matrix to be exponentiated.
        structure : str, optional
            A string describing the structure of matrix `A`.
            Only `upper_triangular` is currently supported.
        use_exact_onenorm : bool, optional
            If True then only the exact one-norm of matrix powers and products
            will be used. Otherwise, the one-norm of powers and products
            may initially be estimated.
        N)r   Ú_A2Ú_A4Ú_A6Ú_A8Ú_A10Ú	_d4_exactÚ	_d6_exactÚ	_d8_exactÚ
_d10_exactÚ
_d4_approxÚ
_d6_approxÚ
_d8_approxÚ_d10_approxr   Úidentr@   Úuse_exact_onenorm)rK   r   r@   rŽ   s       r   rL   z_ExpmPadeHelper.__init__[  s�   € ð  ˆŒØˆŒØˆŒØˆŒØˆŒØˆŒ	ØˆŒØˆŒØˆŒØˆŒØˆŒØˆŒØˆŒØˆÔÜ  “^ˆŒ
Ø"ˆŒØ!2ˆÕr   c                 ó”   — | j                   €1t        | j                  | j                  | j                  ¬«      | _         | j                   S rV   )r€   rC   r   r@   r[   s    r   ÚA2z_ExpmPadeHelper.A2}  s4   € à�8‰8ÐÜ,Ø—F‘F˜DŸF™F¨d¯n©nô>ˆDŒHà�x‰xˆr   c                 ó”   — | j                   €1t        | j                  | j                  | j                  ¬«      | _         | j                   S rV   )r�   rC   r�   r@   r[   s    r   ÚA4z_ExpmPadeHelper.A4„  ó5   € à�8‰8ÐÜ,Ø—G‘G˜TŸW™W°·±ô@ˆDŒHà�x‰xˆr   c                 ó”   — | j                   €1t        | j                  | j                  | j                  ¬«      | _         | j                   S rV   )r‚   rC   r’   r�   r@   r[   s    r   ÚA6z_ExpmPadeHelper.A6‹  r“   r   c                 ó”   — | j                   €1t        | j                  | j                  | j                  ¬«      | _         | j                   S rV   )rƒ   rC   r•   r�   r@   r[   s    r   ÚA8z_ExpmPadeHelper.A8’  r“   r   c                 ó”   — | j                   €1t        | j                  | j                  | j                  ¬«      | _         | j                   S rV   )r„   rC   r’   r•   r@   r[   s    r   ÚA10z_ExpmPadeHelper.A10™  s6   € à�9‰9ÐÜ-Ø—G‘G˜TŸW™W°·±ô@ˆDŒIà�y‰yÐr   c                 ól   — | j                   €t        | j                  «      dz  | _         | j                   S )Nç      Ð?)r…   Ú_onenormr’   r[   s    r   Úd4_tightz_ExpmPadeHelper.d4_tight   ó+   € à�>‰>Ð!Ü% d§g¡gÓ.°Ñ6ˆDŒNØ�~‰~Ðr   c                 ól   — | j                   €t        | j                  «      dz  | _         | j                   S )NçUUUUUUÅ?)r†   rœ   r•   r[   s    r   Úd6_tightz_ExpmPadeHelper.d6_tight¦  rž   r   c                 ól   — | j                   €t        | j                  «      dz  | _         | j                   S )Nç      À?)r‡   rœ   r—   r[   s    r   Úd8_tightz_ExpmPadeHelper.d8_tight¬  rž   r   c                 ól   — | j                   €t        | j                  «      dz  | _         | j                   S )Nçš™™™™™¹?)rˆ   rœ   r™   r[   s    r   Ú	d10_tightz_ExpmPadeHelper.d10_tight²  s+   € à�?‰?Ð"Ü& t§x¡xÓ0°5Ñ9ˆDŒOØ�‰Ðr   c                 óæ   — | j                   r| j                  S | j                  �| j                  S | j                  €*t	        | j
                  d| j                  ¬«      dz  | _        | j                  S )Nr   rW   r›   )rŽ   r�   r…   r‰   ry   r�   r@   r[   s    r   Úd4_loosez_ExpmPadeHelper.d4_loose¸  ó`   € à×!Ò!Ø—=‘=Ð Ø�>‰>Ð%Ø—>‘>Ð!à�‰Ð&Ü":¸4¿7¹7ÀAØ"&§.¡.ô#2Ø48ñ#:�”à—?‘?Ð"r   c                 óæ   — | j                   r| j                  S | j                  �| j                  S | j                  €*t	        | j
                  d| j                  ¬«      dz  | _        | j                  S )Né   rW   r    )rŽ   r¡   r†   rŠ   ry   r�   r@   r[   s    r   Úd6_loosez_ExpmPadeHelper.d6_looseÄ  rª   r   c                 óæ   — | j                   r| j                  S | j                  �| j                  S | j                  €*t	        | j
                  d| j                  ¬«      dz  | _        | j                  S )Nr   rW   r£   )rŽ   r¤   r‡   r‹   ry   r’   r@   r[   s    r   Úd8_loosez_ExpmPadeHelper.d8_looseÐ  rª   r   c                 óü   — | j                   r| j                  S | j                  �| j                  S | j                  €5t	        | j
                  | j                  f| j                  ¬«      dz  | _        | j                  S )NrW   r¦   )rŽ   r§   rˆ   rŒ   r|   r’   r•   r@   r[   s    r   Ú	d10_loosez_ExpmPadeHelper.d10_looseÜ  sl   € à×!Ò!Ø—>‘>Ð!Ø�?‰?Ð&Ø—?‘?Ð"à×ÑÐ'Ü#6¸¿¹ÀÇÁÐ7IØ"&§.¡.ô$2Ø49ñ$;�Ô à×#Ñ#Ð#r   c                 óâ   — d}t        | j                  |d   | j                  z  |d   | j                  z  z   | j                  ¬«      }|d   | j                  z  |d   | j                  z  z   }||fS )N)g      ^@g      N@g      (@r:   r¬   r   rW   r   r   )rC   r   r�   r�   r@   ©rK   ÚbÚUÚVs       r   Úpade3z_ExpmPadeHelper.pade3è  sk   € Ø ˆÜ! $§&¡&Ø�!‘�T—W‘W‘˜q ™t D§J¡J™Ñ.ØŸ.™.ô*ˆð ˆa‰D�—‘‰L˜1˜Q™4 §
¡
™?Ñ*ˆØ�!ˆtˆr   c                 ó.  — d}t        | j                  |d   | j                  z  |d   | j                  z  z   |d   | j                  z  z   | j
                  ¬«      }|d   | j                  z  |d   | j                  z  z   |d   | j                  z  z   }||fS )	N)g     ˆÝ@g     ˆÍ@g     @ª@g     @z@g      >@r:   é   r¬   r   rW   é   r   r   )rC   r   r’   r�   r�   r@   r³   s       r   Úpade5z_ExpmPadeHelper.pade5ð  s�   € Ø2ˆÜ! $§&¡&Ø�!‘�T—W‘W‘˜q ™t D§G¡G™|Ñ+¨a°©d°4·:±:©oÑ=ØŸ.™.ô*ˆð ˆa‰D�—‘‰L˜1˜Q™4 §¡™<Ñ'¨!¨A©$¨t¯z©z©/Ñ9ˆØ�!ˆtˆr   c                 óz  — d}t        | j                  |d   | j                  z  |d   | j                  z  z   |d   | j                  z  z   |d   | j
                  z  z   | j                  ¬«      }|d   | j                  z  |d   | j                  z  z   |d	   | j                  z  z   |d
   | j
                  z  z   }||fS )N)g    ø~pAg    ø~`Ag    @t>Ag    @ëAg     œØ@g      —@g      L@r:   é   r¹   r¬   r   rW   é   rº   r   r   )rC   r   r•   r’   r�   r�   r@   r³   s       r   Úpade7z_ExpmPadeHelper.pade7ø  s¯   € ØLˆÜ! $§&¡&Ø�!‘�T—W‘W‘˜q ™t D§G¡G™|Ñ+¨a°©d°4·7±7©lÑ:¸Q¸q¹TÀ$Ç*Á*¹_ÑLØŸ.™.ô*ˆð ˆa‰D�—‘‰L˜1˜Q™4 §¡™<Ñ'¨!¨A©$¨t¯w©w©,Ñ6¸¸1¹¸d¿j¹j¹ÑHˆØ�!ˆtˆr   c                 óÆ  — d}t        | j                  |d   | j                  z  |d   | j                  z  z   |d   | j                  z  z   |d   | j
                  z  z   |d   | j                  z  z   | j                  ¬«      }|d   | j                  z  |d	   | j                  z  z   |d
   | j                  z  z   |d   | j
                  z  z   |d   | j                  z  z   }||fS )N)
g   ynBg   yn Bg    îÞAg   @ß
²Ag    2Þ|Ag    ø~@Ag     û@g     ð®@g     €V@r:   é	   r½   r¹   r¬   r   rW   é   r¾   rº   r   r   )rC   r   r—   r•   r’   r�   r�   r@   r³   s       r   Úpade9z_ExpmPadeHelper.pade9   sß   € ð3ˆä! $§&¡&Ø�1‘�d—g‘g‘  !¡ T§W¡W¡Ñ,¨q°©t°D·G±G©|Ñ;Ø�a‘D˜Ÿ™‘Lñ!Ø#$ Q¡4¨¯
©
¡?ñ3àŸ.™.ô*ˆð ˆq‰T�$—'‘'‰\˜A˜a™D §¡™LÑ(¨1¨Q©4°·±©<Ñ7Ø�!‘�T—W‘W‘ñØ  ™t D§J¡J™ñ/ˆà�!ˆtˆr   c                 ó^  — d}| j                   d| z  z  }| j                  dd|z  z  z  }| j                  dd|z  z  z  }| j                  dd|z  z  z  }t	        ||d   |z  |d   |z  z   |d   |z  z   | j
                  ¬	«      }t	        |||d
   |z  z   |d   |z  z   |d   |z  z   |d   | j                  z  z   | j
                  ¬	«      }t	        ||d   |z  |d   |z  z   |d   |z  z   | j
                  ¬	«      }	|	|d   |z  z   |d   |z  z   |d   |z  z   |d   | j                  z  z   }
||
fS )N)g D•`æÂlCg D•`æÂ\Cg `=Hbœ;Cg 	e‘ßCg €ùÅJXÝBg  šú"5£Bg  €¹/ƒcBg   \L8Bg   pÄ·ÓAg    syƒAg    €S-Ag     þÏ@g     Àf@r:   r   éþÿÿÿéüÿÿÿiúÿÿÿé   é   rÁ   rW   r½   r¹   r¬   r   é   é
   rÂ   r¾   rº   r   )r   r�   r’   r•   rC   r@   r�   )rK   Úsr´   r>   ÚB2ÚB4ÚB6ÚU2rµ   ÚV2r¶   s              r   Úpade13_scaledz_ExpmPadeHelper.pade13_scaled  sn  € ð"ˆð �F‰F�Q˜˜‘U‰NˆØ�W‰W�q˜2˜a™4‘yÑ ˆØ�W‰W�q˜2˜a™4‘yÑ ˆØ�W‰W�q˜2˜a™4‘yÑ ˆÜ" 2Ø�"‘�b‘˜1˜R™5 ™8Ñ# a¨¡d¨2¡gÑ-ØŸ.™.ô*ˆô " !Ø�a˜‘d˜2‘g‘  !¡ R¡Ñ'Ø�a‘D˜‘GñØ ™d 4§:¡:™oñ.àŸ.™.ô*ˆô # 2Ø�"‘�b‘˜1˜R™5 ™8Ñ# a¨¡d¨2¡gÑ-ØŸ.™.ô*ˆð ��1‘�b‘‰L˜1˜Q™4 ™7Ñ" Q q¡T¨"¡WÑ,¨q°©t°D·J±J©Ñ>ˆØ�!ˆtˆr   )NF)r\   r]   r^   rr   rL   r_   r�   r’   r•   r—   r™   r�   r¡   r¤   r§   r©   r­   r¯   r±   r·   r»   r¿   rÃ   rÑ   r`   r   r   r~   r~   Q  s*  „ ñó 3ðD ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð ñó ðð
 ñó ðð
 ñó ðð
 ñó ðð
 ñ	#ó ð	#ð ñ	#ó ð	#ð ñ	#ó ð	#ð ñ	$ó ð	$òòòò	ór   r~   c                 ó   — t        | d¬«      S )a  
    Compute the matrix exponential using Pade approximation.

    Parameters
    ----------
    A : (M,M) array_like or sparse array
        2D Array or Matrix (sparse or dense) to be exponentiated

    Returns
    -------
    expA : (M,M) ndarray
        Matrix exponential of `A`

    Notes
    -----
    This is algorithm (6.1) which is a simplification of algorithm (5.1).

    .. versionadded:: 0.12.0

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham (2009)
           "A New Scaling and Squaring Algorithm for the Matrix Exponential."
           SIAM Journal on Matrix Analysis and Applications.
           31 (3). pp. 970-989. ISSN 1095-7162

    Examples
    --------
    >>> from scipy.sparse import csc_array
    >>> from scipy.sparse.linalg import expm
    >>> A = csc_array([[1, 0, 0], [0, 2, 0], [0, 0, 3]])
    >>> A.toarray()
    array([[1, 0, 0],
           [0, 2, 0],
           [0, 0, 3]], dtype=int64)
    >>> Aexp = expm(A)
    >>> Aexp
    <Compressed Sparse Column sparse array of dtype 'float64'
        with 3 stored elements and shape (3, 3)>
    >>> Aexp.toarray()
    array([[  2.71828183,   0.        ,   0.        ],
           [  0.        ,   7.3890561 ,   0.        ],
           [  0.        ,   0.        ,  20.08553692]])
    Úauto)rŽ   )Ú_expm)r   s    r   r   r   "  s   € ôZ � fÔ-Ð-r   c           
      ó~  — t        | t        t        t        j                  f«      rt        j
                  | «      } t        | j                  «      dk7  s| j                  d   | j                  d   k7  rt        d«      ‚| j                  dk(  rLt        j                  ddg| j                  ¬«      }t        | «      st        | «      r| j                  |«      S |S | j                  dk(  rVt        j                  | d   «      gg}t        | «      st        | «      r| j                  |«      S t        j                  |«      S t        | t        j                   «      st        | «      st        | «      rCt        j"                  | j                  t        j$                  «      s| j'                  t(        «      } t+        | «      rt,        nd }|dk(  r| j                  d   d	k  }t/        | ||¬
«      }t1        |j2                  |j4                  «      }|dk  r:t7        |j8                  d«      dk(  r!|j;                  «       \  }}t=        |||¬«      S t1        |j>                  |j4                  «      }|dk  r:t7        |j8                  d«      dk(  r!|jA                  «       \  }}t=        |||¬«      S t1        |jB                  |jD                  «      }	|	dk  r:t7        |j8                  d«      dk(  r!|jG                  «       \  }}t=        |||¬«      S |	dk  r:t7        |j8                  d«      dk(  r!|jI                  «       \  }}t=        |||¬«      S t1        |jD                  |jJ                  «      }
tM        |	|
«      }d}|dk(  rd}n>t1        tO        t        jP                  t        jR                  ||z  «      «      «      d«      }|t7        d| z  |j8                  z  d«      z   }|jU                  |«      \  }}t=        |||¬«      }|t,        k(  rtW        ||j8                  |«      }|S tY        |«      D ]  }|j[                  |«      }Œ |S )Nr   r   r   zexpected a square matrix)r   r   r   )r   r   rÓ   éÈ   )r@   rŽ   gî ö,¡Ž?r¬   rW   g©|zÛŒ@Ð?r¹   g×QŒÌÒiî?r½   g“¢ƒdÈ @rÁ   g      @rÇ   ).Ú
isinstanceÚlistÚtupler"   ÚmatrixÚasarrayr    r!   r   Úzerosr   r   r
   Ú	__class__ÚexpÚarrayÚndarrayÚ
issubdtypeÚinexactÚastyper$   r7   r;   r~   r(   r©   r­   Ú_ellr   r·   Ú
_solve_P_Qr�   r»   r¡   r¯   r¿   rÃ   r±   Úminr   ÚceilÚlog2rÑ   Ú_fragment_2_1r&   r'   )r   rŽ   rB   r@   ÚhÚeta_1rµ   r¶   Úeta_2Úeta_3Úeta_4Úeta_5Útheta_13rË   rX   r,   s                   r   rÔ   rÔ   R  s~  € ô
 �!”dœE¤2§9¡9Ð-Ô.Ü�J‰J�q‹MˆÜ
ˆ1�7‰7ƒ|�qÒ˜AŸG™G A™J¨!¯'©'°!©*Ò4ÜÐ3Ó4Ð4ð 	‡w�w�&ÒÜ�h‰h˜˜1�v Q§W¡WÔ-ˆÜ�AŒ;Ô,¨QÔ/Ø—;‘;˜sÓ#Ð#Øˆ
ð 	‡w�w�&ÒÜ—‘�q˜‘w“Ð Ð!ˆô �AŒ;Ô,¨QÔ/Ø—;‘;˜sÓ#Ð#ä�x‰x˜‹}Ðô 
�A”r—z‘zÔ	"¤h¨q¤kÔ5GÈÔ5JÜ—M‘M !§'¡'¬2¯:©:Ô6Ø�H‰H”U‹Oˆô %9¸Ô$;Õ À€Ià˜FÒ"àŸG™G A™J¨Ñ,Ðô 	Ø˜Ð6Gô	I€Aô �—
‘
˜AŸJ™JÓ'€EØÐ%Ò%¬$¨q¯s©s°A«,¸!Ò*;Ø�w‰w‹y‰ˆˆ1Ü˜!˜Q¨)Ô4Ð4ô �—
‘
˜AŸJ™JÓ'€EØÐ%Ò%¬$¨q¯s©s°A«,¸!Ò*;Ø�w‰w‹y‰ˆˆ1Ü˜!˜Q¨)Ô4Ð4ô �—
‘
˜AŸJ™JÓ'€EØÐ%Ò%¬$¨q¯s©s°A«,¸!Ò*;Ø�w‰w‹y‰ˆˆ1Ü˜!˜Q¨)Ô4Ð4ØÐ%Ò%¬$¨q¯s©s°A«,¸!Ò*;Ø�w‰w‹y‰ˆˆ1Ü˜!˜Q¨)Ô4Ð4ô �—
‘
˜AŸK™KÓ(€EÜ��uÓ€EØ€Hð �‚zà‰ä””B—G‘GœBŸG™G E¨HÑ$4Ó5Ó6Ó7¸Ó;ˆØ	ŒD��Q�B‘˜Ÿ™‘˜bÓ!Ñ!€AØ�?‰?˜1Ó�D€A€qÜ�1�a 9Ô-€AØÔ$Ò$ä˜!˜QŸS™S !Ó$ˆð
 €Hô �q“ò 	ˆAØ—‘�a“‰Að	à€Hr   c                 óÐ   — | |z   }|  |z   }t        | «      st        | «      rt        ||«      S |€t        ||«      S |t        k(  rt        ||«      S t        dt        |«      z   «      ‚)a­  
    A helper function for expm_2009.

    Parameters
    ----------
    U : ndarray
        Pade numerator.
    V : ndarray
        Pade denominator.
    structure : str, optional
        A string describing the structure of both matrices `U` and `V`.
        Only `upper_triangular` is currently supported.

    Notes
    -----
    The `structure` argument is inspired by similar args
    for theano and cvxopt functions.

    zunsupported matrix structure: )r   r
   r	   r   r;   r   r   Ústr)rµ   r¶   r@   ÚPÚQs        r   rå   rå   ¬  sp   € ð( 	
ˆA‰€AØ	
ˆˆQ‰€AÜ�„{Ô(¨Ô+Ü�q˜!‹}ÐØ	Ð	Ü�Q˜‹{ÐØ	Ô&Ò	&Ü  1Ó%Ð%äÐ9¼CÀ	»NÑJÓKÐKr   c                 óö   — t        |«      dk  r5||z  }t        j                  | «      d|dz  d|dz  d|dz  z   z  z   z  z   z  S t        j                  | |z   «      t        j                  | |z
  «      z
  d|z  z  S )a×  
    Stably evaluate exp(a)*sinh(x)/x

    Notes
    -----
    The strategy of falling back to a sixth order Taylor expansion
    was suggested by the Spallation Neutron Source docs
    which was found on the internet by google search.
    http://www.ornl.gov/~t6p/resources/xal/javadoc/gov/sns/tools/math/ElementaryFunction.html
    The details of the cutoff point and the Horner-like evaluation
    was picked without reference to anything in particular.

    Note that sinch is not currently implemented in scipy.special,
    whereas the "engineer's" definition of sinc is implemented.
    The implementation of sinc involves a scaling factor of pi
    that distinguishes it from the "mathematician's" version of sinc.

    gÙÎ÷Sã¥‹?r   g      @g      4@g      E@r   )Úabsr"   rÞ   )ÚarO   Úx2s      r   Ú
_exp_sinchrù   Ì  s{   € ô0 ˆ1ƒv�‚Øˆq‰SˆÜ�v‰v�a‹y˜A  B¡¨¨b°©f°q¸B¸s¹F±|Ñ-DÑ)DÑ EÑEÑFÐFä—‘�q˜1‘u“¤§¡ q¨1¡u£Ñ-°!°A±#Ñ6Ð6r   c                 ó@   — d| |z   z  }d| |z
  z  }|t        ||«      z  S )a·  
    Equation (10.42) of Functions of Matrices: Theory and Computation.

    Notes
    -----
    This is a helper function for _fragment_2_1 of expm_2009.
    Equation (10.42) is on page 251 in the section on Schur algorithms.
    In particular, section 10.4.3 explains the Schur-Parlett algorithm.
    expm([[lam_1, t_12], [0, lam_1])
    =
    [[exp(lam_1), t_12*exp((lam_1 + lam_2)/2)*sinch((lam_1 - lam_2)/2)],
    [0, exp(lam_2)]
    g      à?)rù   )Úlam_1Úlam_2Út_12r÷   r´   s        r   Ú	_eq_10_42rþ   ë  s2   € ð& 	ˆu�u‰}Ñ€AØˆu�u‰}Ñ€AØ”*˜Q Ó"Ñ"Ð"r   c                 óF  — | j                   d   }t        j                  |j                  «       j	                  «       «      }d| z  }t        j
                  ||z  «      }t        |«      D ]  }||   | ||f<   Œ t        |dz
  dd«      D ]•  }| j                  | «      } d| z  }t        j
                  ||z  «      }t        |«      D ]  }||   | ||f<   Œ t        |dz
  «      D ]9  }|||   z  }	|||dz      z  }
||||dz   f   z  }t        |	|
|«      }|| ||dz   f<   Œ; Œ— | S )aË  
    A helper function for expm_2009.

    Notes
    -----
    The argument X is modified in-place, but this modification is not the same
    as the returned value of the function.
    This function also takes pains to do things in ways that are compatible
    with sparse arrays, for example by avoiding fancy indexing
    and by using methods of the matrices whenever possible instead of
    using functions of the numpy or scipy libraries themselves.

    r   r   r   r/   )	r!   r"   rR   ÚdiagonalÚcopyrÞ   r&   r'   rþ   )rX   r%   rË   ri   Údiag_TÚscaleÚexp_diagÚkr,   rû   rü   rý   Úvalues                r   ré   ré     sT  € ð  	
�‰�‰
€AÜ�X‰X�a—j‘j“l×'Ñ'Ó)Ó*€Fð �!�‰G€EÜ�v‰v�e˜f‘nÓ%€HÜ�1‹Xò ˆØ˜1‘+ˆˆ!ˆQˆ$Šðô �1�Q‘3˜˜BÓò ˆØ�E‰E�!‹Hˆð �a�R‘ˆÜ—6‘6˜% &™.Ó)ˆÜ�q“ò 	"ˆAØ˜q‘kˆAˆa�ˆdŠGð	"ô �q˜‘s“ò 	ˆAØ˜F 1™IÑ%ˆEØ˜F 1 Q¡3™KÑ'ˆEØ˜1˜Q  !¡˜V™9Ñ$ˆDÜ˜e U¨DÓ1ˆEØˆAˆa��1‘ˆfŠIñ	ðð* €Hr   c                 ó’  — t        | j                  «      dk7  s| j                  d   | j                  d   k7  rt        d«      ‚ddddd	d
œ}||   }d}t        t	        | «      d|z  dz   «      }|sy|t        | «      |z  z  }t        j                  ||z  «      }t        t        j                  |d|z  z  «      «      }t        |d«      S )a!  
    A helper function for expm_2009.

    Parameters
    ----------
    A : linear operator
        A linear operator whose norm of power we care about.
    m : int
        The power of the linear operator

    Returns
    -------
    value : int
        A value related to a bound.

    r   r   r   r   g     œø@g   `…¼Bg €ç/ƒã/CgµÒu;é	tDgßäñ¿±Ï5G)r¬   r¹   r½   rÁ   rÇ   g       <)r    r!   r   r-   rö   rœ   r"   rè   r   rç   r(   )	r   ÚmÚc_iÚabs_c_recipÚuÚA_abs_onenormr?   Úlog2_alpha_div_ur  s	            r   rä   rä   4  sÒ   € ô" ˆ1�7‰7ƒ|�qÒ˜AŸG™G A™J¨!¯'©'°!©*Ò4ÜÐ@ÓAÐAð ØØØ%Ø4ñ	€Cð �a‘&€Kð 	€Aô .¬c°!«f°a¸±c¸A±gÓ>€Mñ ØàœX a›[¨;Ñ6Ñ7€EÜ—w‘w˜u Q™wÓ'ÐÜ”—‘Ð(¨A°©EÑ2Ó3Ó4€EÜˆu�a‹=Ðr   c                 óF  — | j                   \  }}||k7  rt        d«      ‚t        |«      rmt        |«      }|dk  rt	        d«      ‚|dk(  rt        || j                  ¬«      S |dk(  r| j                  «       S t        | |dz  «      }|dz  r| |z  |z  S ||z  S t	        d«      ‚)aö  
    Raise a square matrix to the integer power, `power`.

    For non-negative integers, ``A**power`` is computed using repeated
    matrix multiplications. Negative integers are not supported. 

    Parameters
    ----------
    A : (M, M) square sparse array or matrix
        sparse array that will be raised to power `power`
    power : int
        Exponent used to raise sparse array `A`

    Returns
    -------
    A**power : (M, M) sparse array or matrix
        The output matrix will be the same shape as A, and will preserve
        the class of A, but the format of the output may be changed.
    
    Notes
    -----
    This uses a recursive implementation of the matrix power. For computing
    the matrix power using a reasonably large `power`, this may be less efficient
    than computing the product directly, using A @ A @ ... @ A.
    This is contingent upon the number of nonzero entries in the matrix. 

    .. versionadded:: 1.12.0

    Examples
    --------
    >>> from scipy import sparse
    >>> A = sparse.csc_array([[0,1,0],[1,0,1],[0,1,0]])
    >>> A.todense()
    array([[0, 1, 0],
           [1, 0, 1],
           [0, 1, 0]])
    >>> (A @ A).todense()
    array([[1, 0, 1],
           [0, 2, 0],
           [1, 0, 1]])
    >>> A2 = sparse.linalg.matrix_power(A, 2)
    >>> A2.todense()
    array([[1, 0, 1],
           [0, 2, 0],
           [1, 0, 1]])
    >>> A4 = sparse.linalg.matrix_power(A, 4)
    >>> A4.todense()
    array([[2, 0, 2],
           [0, 4, 0],
           [2, 0, 2]])

    zsparse matrix is not squarer   zexponent must be >= 0r   r   r   zexponent must be an integer)	r!   r   r   r   r   r   r   r  r   )r   Úpowerr+   ÚNÚtmps        r   r   r   b  s®   € ðj �7‰7�D€A€qØˆA‚vÜÐ5Ó6Ð6ä�ÔÜ�E“
ˆØ�1Š9ÜÐ4Ó5Ð5à�AŠ:Ü˜Q a§g¡gÔ.Ð.à�AŠ:Ø—6‘6“8ˆOä˜1˜e q™jÓ)ˆØ�1Š9Ø�s‘7˜S‘=Ð à˜‘9ÐäÐ6Ó7Ð7r   )NN)r   r¹   FFNrN   )*rr   Ú__all__Únumpyr"   Úscipy.linalg._basicr   r   Úscipy.sparse._baser   Úscipy.sparse.linalgr	   Úscipy.sparse._sputilsr
   r   Úscipy.sparser0   Úscipy.sparse.linalg._interfacer   Úscipy.sparse._constructr   Ú_expm_multiplyr   r   rœ   r;   r   r-   r7   rC   rE   rb   ry   r|   r~   r   rÔ   rå   rù   rþ   ré   rä   r   r`   r   r   ú<module>r     sÀ   ðñò *€ã ß 7å 'Ý 'ß ?ã Û Ý 9Ý -ç Bð &Ð ò.òbòB(ó(ôV!7˜.ô !7ôH,(�nô ,(ð` CGó&<ðT CGó'A÷TNñ Nòb-.ò`WótLò@7ò>#ò0.òb,ó\J8r   