403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/linalg/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/linalg/__pycache__/_solvers.cpython-311.pyc
�

d�c�n����dZddlZddlZddlmZmZmZmZm	Z	ddl
mZmZm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZmZgd
�Zd�Zd�ZeZ d�Z!d�Z"dd�Z#dd�Z$dd�Z%dd�Z&dS)zMatrix equation solver routines�N)�inv�LinAlgError�norm�cond�svd�)�solve�solve_triangular�matrix_balance)�get_lapack_funcs)�schur)�lu)�qr)�ordqz)�_asarray_validated)�kron�
block_diag)�solve_sylvester�solve_continuous_lyapunov�solve_discrete_lyapunov�solve_lyapunov�solve_continuous_are�solve_discrete_arec�z�t|d���\}}t|������d���\}}tjtj|������|��|��}td|||f��\}|�t
d���||||d���\}	}
}|
|	z}	|dkrtd	|fz���tjtj||	��|��������S)
a�
    Computes a solution (X) to the Sylvester equation :math:`AX + XB = Q`.

    Parameters
    ----------
    a : (M, M) array_like
        Leading matrix of the Sylvester equation
    b : (N, N) array_like
        Trailing matrix of the Sylvester equation
    q : (M, N) array_like
        Right-hand side

    Returns
    -------
    x : (M, N) ndarray
        The solution to the Sylvester equation.

    Raises
    ------
    LinAlgError
        If solution was not found

    Notes
    -----
    Computes a solution to the Sylvester matrix equation via the Bartels-
    Stewart algorithm. The A and B matrices first undergo Schur
    decompositions. The resulting matrices are used to construct an
    alternative Sylvester equation (``RY + YS^T = F``) where the R and S
    matrices are in quasi-triangular form (or, when R, S or F are complex,
    triangular form). The simplified equation is then solved using
    ``*TRSYL`` from LAPACK directly.

    .. versionadded:: 0.11.0

    Examples
    --------
    Given `a`, `b`, and `q` solve for `x`:

    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[-3, -2, 0], [-1, -1, 3], [3, -5, -1]])
    >>> b = np.array([[1]])
    >>> q = np.array([[1],[2],[3]])
    >>> x = linalg.solve_sylvester(a, b, q)
    >>> x
    array([[ 0.0625],
           [-0.5625],
           [ 0.6875]])
    >>> np.allclose(a.dot(x) + x.dot(b), q)
    True

    �real��output)�trsylNzQLAPACK implementation does not contain a proper Sylvester equation solver (TRSYL)�C��tranbrz(Illegal value encountered in the %d term)r
�conj�	transpose�np�dotr�RuntimeErrorr)�a�b�q�r�u�s�v�fr�y�scale�infos            �7/usr/lib/python3/dist-packages/scipy/linalg/_solvers.pyrrs7��n��6�"�"�"�D�A�q�������#�#�%�%�f�5�5�5�D�A�q�	��r�v�a�f�f�h�h�(�(�*�*�A�.�.��2�2�A��j�1�a��)�
4�
4�F�E��}��?�@�@�	@��U�1�a��#�.�.�.�N�A�u�d�
�a��A��a�x�x��(�,0�5�(�3�4�4�	4��6�"�&��A�,�,������ 2� 2� 4� 4�5�5�5�c���tjt|d�����}tjt|d�����}t}t	||f��D][\}}tj|��rt}tj|j�s(td�
d|������\|j|jkrtd���t|d���\}}|���j
�|�|����}td||f��}|tkrd	nd
}	|||||	���\}
}}|dkr#td
�
|�����|dkrt!jdt$��|
|z}
|�|
���|���j
��S)a�
    Solves the continuous Lyapunov equation :math:`AX + XA^H = Q`.

    Uses the Bartels-Stewart algorithm to find :math:`X`.

    Parameters
    ----------
    a : array_like
        A square matrix

    q : array_like
        Right-hand side square matrix

    Returns
    -------
    x : ndarray
        Solution to the continuous Lyapunov equation

    See Also
    --------
    solve_discrete_lyapunov : computes the solution to the discrete-time
        Lyapunov equation
    solve_sylvester : computes the solution to the Sylvester equation

    Notes
    -----
    The continuous Lyapunov equation is a special form of the Sylvester
    equation, hence this solver relies on LAPACK routine ?TRSYL.

    .. versionadded:: 0.11.0

    Examples
    --------
    Given `a` and `q` solve for `x`:

    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[-3, -2, 0], [-1, -1, 0], [0, -5, -1]])
    >>> b = np.array([2, 4, -1])
    >>> q = np.eye(3)
    >>> x = linalg.solve_continuous_lyapunov(a, q)
    >>> x
    array([[ -0.75  ,   0.875 ,  -3.75  ],
           [  0.875 ,  -1.375 ,   5.3125],
           [ -3.75  ,   5.3125, -27.0625]])
    >>> np.allclose(a.dot(x) + x.dot(a.T), q)
    True
    T��check_finite�Matrix {} should be square.�aq�*Matrix a and q should have the same shape.rrr�Trr rz�?TRSYL exited with the internal error "illegal value in argument number {}.". See LAPACK documentation for the ?TRSYL error codes.rz�Input "a" has an eigenvalue pair whose sum is very close to or exactly zero. The solution is obtained via perturbing the coefficients.)r$�
atleast_2dr�float�	enumerate�iscomplexobj�complex�equal�shape�
ValueError�formatr
r"r:r%r�warnings�warn�RuntimeWarning)
r'r)�r_or_c�ind�_r*r+r.r�dtype_stringr/r0r1s
             r2rrms���d	�
�(���>�>�>�?�?�A�
�
�(���>�>�>�?�?�A�
�F��Q��F�#�#�N�N���Q�
�?�1���	��F��x���!�	N��:�A�A�$�s�)�L�L�M�M�M�	N�	�w�!�'����E�F�F�F���6�"�"�"�D�A�q�	
�����
���q�u�u�Q�x�x� � �A�
�W�q�!�f�-�-�E� �E�/�/�3�3�s�L��U�1�a��,�7�7�7�N�A�u�d��a�x�x���#�F�D�5�M�M�+�+�	+�
�����
�B�%�	&�	&�	&���J�A��5�5��8�8�<�<������
�#�#�#r3c��t||�����}tj|jd��|z
}t||�����}tj||j��S)z�
    Solves the discrete Lyapunov equation directly.

    This function is called by the `solve_discrete_lyapunov` function with
    `method=direct`. It is not supposed to be called directly.
    r)rr"r$�eyerAr	�flatten�reshape)r'r)�lhs�xs    r2�_solve_discrete_lyapunov_directrQ�s`���q�!�&�&�(�(�
�
�C�
�&���1��
�
��
$�C�
�c�1�9�9�;�;���A�
�:�a���!�!�!r3c	��tj|jd��}|������}t||z��}tj||z
|��}dtjtjt||z��|��|��z}t|������|��S)z�
    Solves the discrete Lyapunov equation using a bilinear transformation.

    This function is called by the `solve_discrete_lyapunov` function with
    `method=bilinear`. It is not supposed to be called directly.
    r�)r$rLrAr"r#rr%r)r'r)rL�aH�aHI_invr(�cs       r2�!_solve_discrete_lyapunov_bilinearrW�s���
�&�����
�
�C�	
�����	�	�	�	�B��"�s�(�m�m�G�
��r�C�x��!�!�A�	�"�&����A��G���a�(�(�'�
2�
2�2�A��!�&�&�(�(�,�,�.�.���3�3�3r3c�.�tj|��}tj|��}|�|jddkrd}nd}|���}|dkrt	||��}n)|dkrt||��}nt
d|z���|S)aE	
    Solves the discrete Lyapunov equation :math:`AXA^H - X + Q = 0`.

    Parameters
    ----------
    a, q : (M, M) array_like
        Square matrices corresponding to A and Q in the equation
        above respectively. Must have the same shape.

    method : {'direct', 'bilinear'}, optional
        Type of solver.

        If not given, chosen to be ``direct`` if ``M`` is less than 10 and
        ``bilinear`` otherwise.

    Returns
    -------
    x : ndarray
        Solution to the discrete Lyapunov equation

    See Also
    --------
    solve_continuous_lyapunov : computes the solution to the continuous-time
        Lyapunov equation

    Notes
    -----
    This section describes the available solvers that can be selected by the
    'method' parameter. The default method is *direct* if ``M`` is less than 10
    and ``bilinear`` otherwise.

    Method *direct* uses a direct analytical solution to the discrete Lyapunov
    equation. The algorithm is given in, for example, [1]_. However, it requires
    the linear solution of a system with dimension :math:`M^2` so that
    performance degrades rapidly for even moderately sized matrices.

    Method *bilinear* uses a bilinear transformation to convert the discrete
    Lyapunov equation to a continuous Lyapunov equation :math:`(BX+XB'=-C)`
    where :math:`B=(A-I)(A+I)^{-1}` and
    :math:`C=2(A' + I)^{-1} Q (A + I)^{-1}`. The continuous equation can be
    efficiently solved since it is a special case of a Sylvester equation.
    The transformation algorithm is from Popov (1964) as described in [2]_.

    .. versionadded:: 0.11.0

    References
    ----------
    .. [1] Hamilton, James D. Time Series Analysis, Princeton: Princeton
       University Press, 1994.  265.  Print.
       http://doc1.lbfl.li/aca/FLMF037168.pdf
    .. [2] Gajic, Z., and M.T.J. Qureshi. 2008.
       Lyapunov Matrix Equation in System Stability and Control.
       Dover Books on Engineering Series. Dover Publications.

    Examples
    --------
    Given `a` and `q` solve for `x`:

    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[0.2, 0.5],[0.7, -0.9]])
    >>> q = np.eye(2)
    >>> x = linalg.solve_discrete_lyapunov(a, q)
    >>> x
    array([[ 0.70872893,  1.43518822],
           [ 1.43518822, -2.4266315 ]])
    >>> np.allclose(a.dot(x).dot(a.T)-x, -q)
    True

    Nr�
�bilinear�directzUnknown solver %s)r$�asarrayrA�lowerrQrWrB)r'r)�method�methrPs     r2rr�s���N	�
�1�
�
�A�
�
�1�
�
�A�
�~��7�1�:�����F�F��F��<�<�>�>�D��x���+�A�q�1�1���	
��	�	�-�a��3�3����,�v�5�6�6�6��Hr3Tc
��t||||||d��\
}}}}}}}}}	}
tjd|z|zd|z|zf|	���}||d|�d|�f<d|d|�|d|z�f<||d|�d|zd�f<|||d|z�d|�f<|���j||d|z�|d|z�f<|�dn|||d|z�d|zd�f<|�dn|���j|d|zd�d|�f<|���j|d|zd�|d|z�f<||d|zd�d|zd�f<|
r?|�=t||���jtj||	�����}n9ttjd|z��tj||	�����}|�rtj|��tj|��z}
d|
tj	|
��<t|
dd���\}\}}tj|tj|����s�tj
|��}tj||d|z�|d|�z
dz��}dtj|||d|zd�fz}|dd�dftj|��z}||z}||z}t#|dd�|d�f��\}}|dd�|d�f���j�|dd�dd|z�f��}|dd|z�|d�f���j�|dd|z�dd|z�f��}|	t&krd	nd
}t)||dddd
|���\}}}}}}|�Qt#tj|�|d|�d|�f��||d�d|�ff����\}}|d|�d|�f}||d�d|�f}t-|��\}}}dt/|��ztjd��krt3d���t5|���jt5|���j|���jd���d������j�|���j��}|r||d|�df|d|�zz}|���j�|��}t7|d��}||���jz
}tjtjd��d|zg��}t7|d��|krt3d���||���jzdzS)a
    Solves the continuous-time algebraic Riccati equation (CARE).

    The CARE is defined as

    .. math::

          X A + A^H X - X B R^{-1} B^H X + Q = 0

    The limitations for a solution to exist are :

        * All eigenvalues of :math:`A` on the right half plane, should be
          controllable.

        * The associated hamiltonian pencil (See Notes), should have
          eigenvalues sufficiently away from the imaginary axis.

    Moreover, if ``e`` or ``s`` is not precisely ``None``, then the
    generalized version of CARE

    .. math::

          E^HXA + A^HXE - (E^HXB + S) R^{-1} (B^HXE + S^H) + Q = 0

    is solved. When omitted, ``e`` is assumed to be the identity and ``s``
    is assumed to be the zero matrix with sizes compatible with ``a`` and
    ``b``, respectively.

    Parameters
    ----------
    a : (M, M) array_like
        Square matrix
    b : (M, N) array_like
        Input
    q : (M, M) array_like
        Input
    r : (N, N) array_like
        Nonsingular square matrix
    e : (M, M) array_like, optional
        Nonsingular square matrix
    s : (M, N) array_like, optional
        Input
    balanced : bool, optional
        The boolean that indicates whether a balancing step is performed
        on the data. The default is set to True.

    Returns
    -------
    x : (M, M) ndarray
        Solution to the continuous-time algebraic Riccati equation.

    Raises
    ------
    LinAlgError
        For cases where the stable subspace of the pencil could not be
        isolated. See Notes section and the references for details.

    See Also
    --------
    solve_discrete_are : Solves the discrete-time algebraic Riccati equation

    Notes
    -----
    The equation is solved by forming the extended hamiltonian matrix pencil,
    as described in [1]_, :math:`H - \lambda J` given by the block matrices ::

        [ A    0    B ]             [ E   0    0 ]
        [-Q  -A^H  -S ] - \lambda * [ 0  E^H   0 ]
        [ S^H B^H   R ]             [ 0   0    0 ]

    and using a QZ decomposition method.

    In this algorithm, the fail conditions are linked to the symmetry
    of the product :math:`U_2 U_1^{-1}` and condition number of
    :math:`U_1`. Here, :math:`U` is the 2m-by-m matrix that holds the
    eigenvectors spanning the stable subspace with 2-m rows and partitioned
    into two m-row matrices. See [1]_ and [2]_ for more details.

    In order to improve the QZ decomposition accuracy, the pencil goes
    through a balancing step where the sum of absolute values of
    :math:`H` and :math:`J` entries (after removing the diagonal entries of
    the sum) is balanced following the recipe given in [3]_.

    .. versionadded:: 0.11.0

    References
    ----------
    .. [1]  P. van Dooren , "A Generalized Eigenvalue Approach For Solving
       Riccati Equations.", SIAM Journal on Scientific and Statistical
       Computing, Vol.2(2), :doi:`10.1137/0902010`

    .. [2] A.J. Laub, "A Schur Method for Solving Algebraic Riccati
       Equations.", Massachusetts Institute of Technology. Laboratory for
       Information and Decision Systems. LIDS-R ; 859. Available online :
       http://hdl.handle.net/1721.1/1301

    .. [3] P. Benner, "Symplectic Balancing of Hamiltonian Matrices", 2001,
       SIAM J. Sci. Comput., 2001, Vol.22(5), :doi:`10.1137/S1064827500367993`

    Examples
    --------
    Given `a`, `b`, `q`, and `r` solve for `x`:

    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[4, 3], [-4.5, -3.5]])
    >>> b = np.array([[1], [-1]])
    >>> q = np.array([[9, 6], [6, 4.]])
    >>> r = 1
    >>> x = linalg.solve_continuous_are(a, b, q, r)
    >>> x
    array([[ 21.72792206,  14.48528137],
           [ 14.48528137,   9.65685425]])
    >>> np.allclose(a.T.dot(x) + x.dot(a)-x.dot(b).dot(b.T).dot(x), -q)
    True

    �carerS��dtypeN�rr��separate�permuterr?�lhpTF��sort�overwrite_a�overwrite_br6r��?�!Failed to find a finite solution.�r]��
unit_diagonal�@�@皙�����?zQThe associated Hamiltonian pencil has eigenvalues too close to the imaginary axis)�_are_validate_argsr$�emptyr"r:r�
zeros_likerL�abs�diag_indices_fromr�allclose�	ones_like�log2�round�r_�
reciprocalrr%r<r�vstackrr�spacingrr
r�max)r'r(r)r*�er,�balanced�m�nrG�gen_are�H�J�MrI�sca�elwisescale�out_strr+�u00�u10�up�ul�uurP�u_sym�n_u_sym�
sym_thresholds                            r2rrHs���p/A�56��1�a��A�v�/O�/O�+�A�q�!�Q��1�a��F�G�	��!�A�#�a�%��1��Q���v�.�.�.�A��A�b�q�b�"�1�"�f�I��A�b�q�b�!�A�a�C�%�i�L��A�b�q�b�!�A�#�$�$�h�K��2�A�a��!��e�R�a�R�i�L��v�v�x�x�z�k�A�a��!��e�Q�q��s�U�l�O��9�R�R�1�"�A�a��!��e�Q�q�S�T�T�k�N��	�"�"�q�v�v�x�x�z�A�a��c�d�d�B�Q�B�h�K��V�V�X�X�Z�A�a��c�d�d�A�a��c�E�k�N��A�a��c�d�d�A�a�C�D�D�j�M��D�1�=��q�!�&�&�(�(�*�b�m�A�V�&D�&D�&D�E�E����r�v�a��c�{�{�B�M�!�6�$B�$B�$B�C�C����
�F�1�I�I���q�	�	�!��%'��"�
�q�
!�
!�"�$�Q��A�>�>�>���8�C���{�3���S� 1� 1�2�2�
	��'�#�,�,�C���#�a��!��e�*�s�2�A�2�w�.��1�2�2�A��r�u�Q���C��!����I�-�.�.�C��a�a�a��g�,���s�);�);�;�K�
���A�
���A��a����A�2�3�3��i�=�=�D�A�q�	�!�!�!�Q�R�R�%��
�
������a����4�A�a�C�4��j�)�)�A�	�$�1�Q�3�$����(������� � ��4�A�a�C�4��!�A�#��:��/�/�A��%���f�f�Y�G��Q���4�)-�E�$+�-�-�-��A�q�!�Q��1�
	�}��"�)�Q�U�U�1�R�a�R��!��V�9�-�-�q����R�a�R��y�9�:�:�;�;���1�
�B�Q�B����F�)�C�
�A�B�B����F�)�C��C���J�B��B���b���z�B�J�r�N�N�"�"��=�>�>�>�	�������)�"�'�'�)�)�+�*-�(�(�*�*�,�04�6�6�6�(,�		�	�	�
 �4�6�6�!�C�C����	�	��$4�$4���%�	�S��!��T��]�S��!��W�
$�$��
�H�H�J�J�L���S�!�!�E��5�!�n�n�G��E�J�J�L�L�N�"�E��F�B�J�u�-�-�s�7�{�;�<�<�M��E�1�~�~�
�%�%��<�=�=�	=�
������
�N�A��r3c
�`�t||||||d��\
}}}}}}}}}	}
tjd|z|zd|z|zf|	���}||d|�d|�f<||d|�d|zd�f<|||d|z�d|�f<|�tj|��n|���j||d|z�|d|z�f<|�dn|||d|z�d|zd�f<|�dn|���j|d|zd�d|�f<||d|zd�d|zd�f<tj||	���}|�tj|��n||d|�d|�f<|���j||d|z�|d|z�f<|���j|d|zd�|d|z�f<|�rtj|��tj|��z}
d|
tj|
��<t|
dd���\}\}}tj
|tj|����s�tj|��}tj
||d|z�|d|�z
dz��}dtj|||d|zd�fz}|dd�dftj|��z}||z}||z}t!|dd�|d�f��\}}|dd�|d�f���j�|dd�dd|z�f��}|dd�|d�f���j�|dd�dd|z�f��}|	t$krd	nd
}t'||dddd
|���\}}}}}}|�Qt!tj|�|d|�d|�f��||d�d|�ff����\}}|d|�d|�f}||d�d|�f}t+|��\}}}dt-|��ztjd��krt1d���t3|���jt3|���j|���jd���d������j�|���j��}|r||d|�df|d|�zz}|���j�|��}t5|d��}||���jz
}tjtjd��d|zg��}t5|d��|krt1d���||���jzdzS)al
    Solves the discrete-time algebraic Riccati equation (DARE).

    The DARE is defined as

    .. math::

          A^HXA - X - (A^HXB) (R + B^HXB)^{-1} (B^HXA) + Q = 0

    The limitations for a solution to exist are :

        * All eigenvalues of :math:`A` outside the unit disc, should be
          controllable.

        * The associated symplectic pencil (See Notes), should have
          eigenvalues sufficiently away from the unit circle.

    Moreover, if ``e`` and ``s`` are not both precisely ``None``, then the
    generalized version of DARE

    .. math::

          A^HXA - E^HXE - (A^HXB+S) (R+B^HXB)^{-1} (B^HXA+S^H) + Q = 0

    is solved. When omitted, ``e`` is assumed to be the identity and ``s``
    is assumed to be the zero matrix.

    Parameters
    ----------
    a : (M, M) array_like
        Square matrix
    b : (M, N) array_like
        Input
    q : (M, M) array_like
        Input
    r : (N, N) array_like
        Square matrix
    e : (M, M) array_like, optional
        Nonsingular square matrix
    s : (M, N) array_like, optional
        Input
    balanced : bool
        The boolean that indicates whether a balancing step is performed
        on the data. The default is set to True.

    Returns
    -------
    x : (M, M) ndarray
        Solution to the discrete algebraic Riccati equation.

    Raises
    ------
    LinAlgError
        For cases where the stable subspace of the pencil could not be
        isolated. See Notes section and the references for details.

    See Also
    --------
    solve_continuous_are : Solves the continuous algebraic Riccati equation

    Notes
    -----
    The equation is solved by forming the extended symplectic matrix pencil,
    as described in [1]_, :math:`H - \lambda J` given by the block matrices ::

           [  A   0   B ]             [ E   0   B ]
           [ -Q  E^H -S ] - \lambda * [ 0  A^H  0 ]
           [ S^H  0   R ]             [ 0 -B^H  0 ]

    and using a QZ decomposition method.

    In this algorithm, the fail conditions are linked to the symmetry
    of the product :math:`U_2 U_1^{-1}` and condition number of
    :math:`U_1`. Here, :math:`U` is the 2m-by-m matrix that holds the
    eigenvectors spanning the stable subspace with 2-m rows and partitioned
    into two m-row matrices. See [1]_ and [2]_ for more details.

    In order to improve the QZ decomposition accuracy, the pencil goes
    through a balancing step where the sum of absolute values of
    :math:`H` and :math:`J` rows/cols (after removing the diagonal entries)
    is balanced following the recipe given in [3]_. If the data has small
    numerical noise, balancing may amplify their effects and some clean up
    is required.

    .. versionadded:: 0.11.0

    References
    ----------
    .. [1]  P. van Dooren , "A Generalized Eigenvalue Approach For Solving
       Riccati Equations.", SIAM Journal on Scientific and Statistical
       Computing, Vol.2(2), :doi:`10.1137/0902010`

    .. [2] A.J. Laub, "A Schur Method for Solving Algebraic Riccati
       Equations.", Massachusetts Institute of Technology. Laboratory for
       Information and Decision Systems. LIDS-R ; 859. Available online :
       http://hdl.handle.net/1721.1/1301

    .. [3] P. Benner, "Symplectic Balancing of Hamiltonian Matrices", 2001,
       SIAM J. Sci. Comput., 2001, Vol.22(5), :doi:`10.1137/S1064827500367993`

    Examples
    --------
    Given `a`, `b`, `q`, and `r` solve for `x`:

    >>> import numpy as np
    >>> from scipy import linalg as la
    >>> a = np.array([[0, 1], [0, -1]])
    >>> b = np.array([[1, 0], [2, 1]])
    >>> q = np.array([[-4, -4], [-4, 7]])
    >>> r = np.array([[9, 3], [3, 1]])
    >>> x = la.solve_discrete_are(a, b, q, r)
    >>> x
    array([[-4., -4.],
           [-4.,  7.]])
    >>> R = la.solve(r + b.T.dot(x).dot(b), b.T.dot(x).dot(a))
    >>> np.allclose(a.T.dot(x).dot(a) - x - a.T.dot(x).dot(b).dot(R), -q)
    True

    �darerSrbNrdrrrerr?�iucTFrirmrnrorprrrszLThe associated symplectic pencil has eigenvaluestoo close to the unit circle)rtr$�zerosrLr"r:rvrwrxrryrzr{r|r}r~rr%r<rrrrr�rr
rr�)r'r(r)r*r�r,r�r�r�rGr�r�r�r�rIr�r��q_of_qrr�r+r�r�r�r�r�rPr�r�r�s                             r2rrs���t/A�56��1�a��A�v�/O�/O�+�A�q�!�Q��1�a��F�G�	��!�A�#�a�%��1��Q���v�.�.�.�A��A�b�q�b�"�1�"�f�I��A�b�q�b�!�A�#�$�$�h�K��2�A�a��!��e�R�a�R�i�L�#$�9�b�f�Q�i�i�i�!�&�&�(�(�*�A�a��!��e�Q�q��s�U�l�O��9�R�R�1�"�A�a��!��e�Q�q�S�T�T�k�N��	�"�"�q�v�v�x�x�z�A�a��c�d�d�B�Q�B�h�K��A�a��c�d�d�A�a�C�D�D�j�M�
�
�a�v�&�&�&�A��Y���q�	�	�	�A�A�b�q�b�"�1�"�f�I��f�f�h�h�j�A�a��!��e�Q�q��s�U�l�O��f�f�h�h�j�[�A�a��c�d�d�A�a��c�E�k�N���
�F�1�I�I���q�	�	�!��%'��"�
�q�
!�
!�"�$�Q��A�>�>�>���8�C���{�3���S� 1� 1�2�2�
	��'�#�,�,�C���#�a��!��e�*�s�2�A�2�w�.��1�2�2�A��r�u�Q���C��!����I�-�.�.�C��a�a�a��g�,���s�);�);�;�K�
���A�
���A��A�a�a�a�!����f�I���J�G�Q�����1�2�2��������#�#�A�a�a�a��!�A�#��g�J�/�/�A�����1�2�2��������#�#�A�a�a�a��!�A�#��g�J�/�/�A��%���f�f�Y�G��Q���)-�)-�*/�$+�	-�-�-��A�q�!�Q��1�	�}��"�)�Q�U�U�1�R�a�R��!��V�9�-�-�q����R�a�R��y�9�:�:�;�;���1�
�B�Q�B����F�)�C�
�A�B�B����F�)�C��C���J�B��B���b���z�B�J�r�N�N�"�"��=�>�>�>�	�������)�"�'�'�)�)�+�*-�(�(�*�*�,�04�6�6�6�(,�		�	�	�
 �4�6�6�!�C�C����	�	��$4�$4���%�	�S��!��T��]�S��!��W�
$�$��
�H�H�J�J�L���S�!�!�E��5�!�n�n�G��E�J�J�L�L�N�"�E��F�B�J�u�-�-�s�7�{�;�<�<�M��E�1�~�~�
�%�%��9�:�:�	:�
������
�N�A��r3rac
���|���dvrtd���tjt	|d�����}tjt	|d�����}tjt	|d�����}tjt	|d�����}tj|��rtnt}t|||f��D][\}}	tj|	��rt}tj	|	j
�s(td�d|������\|j
\}
}|
|j
dkrtd���|
|j
dkrtd	���||j
dkrtd
���t||f��D]~\}}	t|	|	�
��jz
d��tjt|	d����dzkr(td
�d|������|dkrUt!|d���d}|dks)|tjd��t|d��zkrtd���|dup|du}
|
�r6|��tjt	|d�����}tj	|j
�std���|
|j
dkrtd���t!|d���d}|dks)|tjd��t|d��zkrtd���tj|��rt}|�]tjt	|d�����}|j
|j
krtd���tj|��rt}|||||||
|||
f
S)a�
    A helper function to validate the arguments supplied to the
    Riccati equation solvers. Any discrepancy found in the input
    matrices leads to a ``ValueError`` exception.

    Essentially, it performs:

        - a check whether the input is free of NaN and Infs
        - a pass for the data through ``numpy.atleast_2d()``
        - squareness check of the relevant arrays
        - shape consistency check of the arrays
        - singularity check of the relevant arrays
        - symmetricity check of the relevant matrices
        - a check whether the regular or the generalized version is asked.

    This function is used by ``solve_continuous_are`` and
    ``solve_discrete_are``.

    Parameters
    ----------
    a, b, q, r, e, s : array_like
        Input data
    eq_type : str
        Accepted arguments are 'care' and 'dare'.

    Returns
    -------
    a, b, q, r, e, s : ndarray
        Regularized input data
    m, n : int
        shape of the problem
    r_or_c : type
        Data type of the problem, returns float or complex
    gen_or_not : bool
        Type of the equation, True for generalized and False for regular ARE.

    )r�raz;Equation type unknown. Only 'care' and 'dare' is understoodTr5r7�aqrrz3Matrix a and b should have the same number of rows.r9z3Matrix b and r should have the same number of cols.r�dz(Matrix {} should be symmetric/hermitian.rraF)�
compute_uv���rdrmz!Matrix r is numerically singular.NzMatrix e should be square.z*Matrix a and e should have the same shape.z!Matrix e is numerically singular.z*Matrix b and s should have the same shape.)r]rBr$r;rr>r?r<r=r@rArCrr"r:r�r)r'r(r)r*r�r,�eq_typerGrH�matr�r��min_sv�generalized_cases              r2rtrt�s���N�=�=�?�?�.�.�.��@�A�A�	A�	�
�(���>�>�>�?�?�A�
�
�(���>�>�>�?�?�A�
�
�(���>�>�>�?�?�A�
�
�(���>�>�>�?�?�A����*�*�
5�W�W��F��q�!�Q�i�(�(�O�O���S�
�?�3���	��F��x���#�	O��:�A�A�%��*�M�M�N�N�N�	O�
�7�D�A�q��A�G�A�J����N�O�O�O��A�G�A�J����E�F�F�F��A�G�A�J����N�O�O�O��q�!�f�%�%�3�3���S���c�h�h�j�j�l�"�A�&�&���D��a�L�L�)A�)A�#�)E�E�E�� � &��t�C�y� 1� 1�3�3�
3�F�
�&����Q�5�)�)�)�"�-���R�<�<�6�B�J�r�N�N�4��1�:�:�$=�=�=��@�A�A�A���}�5���
���!��=��
�0���F�F�F�G�G�A��8�Q�W�%�
?� �!=�>�>�>��A�G�A�J��� �!M�N�N�N���u�-�-�-�b�1�F���|�|�v��
�2����a����(C�C�C� �!D�E�E�E���q�!�!�
!� ���=��
�0���F�F�F�G�G�A��w�!�'�!�!� �!M�N�N�N���q�!�!�
!� ���a��A�q�!�Q��6�+;�;�;r3)N)NNT)ra)'�__doc__rD�numpyr$�numpy.linalgrrrrr�_basicr	r
r�lapackr�
_decomp_schurr
�
_decomp_lur�
_decomp_qrr�
_decomp_qzr�_decompr�_special_matricesrr�__all__rrrrQrWrrrrt�r3r2�<module>r�s���%�%���������:�:�:�:�:�:�:�:�:�:�:�:�:�:�;�;�;�;�;�;�;�;�;�;�$�$�$�$�$�$� � � � � � �������������������'�'�'�'�'�'�/�/�/�/�/�/�/�/�9�9�9��L6�L6�L6�^Z$�Z$�Z$�|+��"�"�"�4�4�4�Y
�Y
�Y
�Y
�xJ�J�J�J�ZN�N�N�N�bi<�i<�i<�i<�i<�i<r3

Youez - 2016 - github.com/yon3zu
LinuXploit