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__/_interpolative_backend.cpython-311.pyc
�

d�c�����dZddlmcmZddlZed��Zd�Z	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd;d�Zd;d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d �Z$d!�Z%d"�Z&d#�Z'd$�Z(d%�Z)d&�Z*d'�Z+d(�Z,d)�Z-d*�Z.d+�Z/d;d,�Z0d;d-�Z1d.�Z2d/�Z3d0�Z4d1�Z5d2�Z6d3�Z7d4�Z8d5�Z9d6�Z:d7�Z;d8�Z<d9�Z=d:�Z>dS)<z0
Direct wrappers for Fortran `id_dist` backend.
�Nznonzero return codec��tj|��}|jjr|�d���}ntj|��}|S)z6
    Same as np.asfortranarray, but ensure a copy
    �F��order)�np�asarray�flags�f_contiguous�copy�asfortranarray)�As �E/usr/lib/python3/dist-packages/scipy/linalg/_interpolative_backend.py�_asfortranarray_copyr(sH��	�
�1�
�
�A��w��!�
�F�F��F�������a� � ���H�c�*�tj|��S)a

    Generate standard uniform pseudorandom numbers via a very efficient lagged
    Fibonacci method.

    :param n:
        Number of pseudorandom numbers to generate.
    :type n: int

    :return:
        Pseudorandom numbers.
    :rtype: :class:`numpy.ndarray`
    )�_id�id_srand)�ns rrr8s���<��?�?�rc�V�tj|��}tj|��dS)z�
    Initialize seed values for :func:`id_srand` (any appropriately random
    numbers will do).

    :param t:
        Array of 55 seed values.
    :type t: :class:`numpy.ndarray`
    N)rrr�	id_srandi)�ts rrrHs*��	��!���A��M�!�����rc�,�tj��dS)z5
    Reset seed values to their original values.
    N)r�	id_srando�rrrrUs���M�O�O�O�O�Orc�.�tj|||��S)a|
    Transform real vector via a composition of Rokhlin's random transform,
    random subselection, and an FFT.

    In contrast to :func:`idd_sfrm`, this routine works best when the length of
    the transformed vector is the power-of-two integer output by
    :func:`idd_frmi`, or when the length is not specified but instead
    determined a posteriori from the output. The returned transformed vector is
    randomly permuted.

    :param n:
        Greatest power-of-two integer satisfying `n <= x.size` as obtained from
        :func:`idd_frmi`; `n` is also the length of the output vector.
    :type n: int
    :param w:
        Initialization array constructed by :func:`idd_frmi`.
    :type w: :class:`numpy.ndarray`
    :param x:
        Vector to be transformed.
    :type x: :class:`numpy.ndarray`

    :return:
        Transformed vector.
    :rtype: :class:`numpy.ndarray`
    )r�idd_frm�r�w�xs   rrr`���4�;�q�!�Q���rc�0�tj||||��S)a�
    Transform real vector via a composition of Rokhlin's random transform,
    random subselection, and an FFT.

    In contrast to :func:`idd_frm`, this routine works best when the length of
    the transformed vector is known a priori.

    :param l:
        Length of transformed vector, satisfying `l <= n`.
    :type l: int
    :param n:
        Greatest power-of-two integer satisfying `n <= x.size` as obtained from
        :func:`idd_sfrmi`.
    :type n: int
    :param w:
        Initialization array constructed by :func:`idd_sfrmi`.
    :type w: :class:`numpy.ndarray`
    :param x:
        Vector to be transformed.
    :type x: :class:`numpy.ndarray`

    :return:
        Transformed vector.
    :rtype: :class:`numpy.ndarray`
    )r�idd_sfrm��lrrrs    rr"r"}���4�<��1�a��#�#�#rc�*�tj|��S)aC
    Initialize data for :func:`idd_frm`.

    :param m:
        Length of vector to be transformed.
    :type m: int

    :return:
        Greatest power-of-two integer `n` satisfying `n <= m`.
    :rtype: int
    :return:
        Initialization array to be used by :func:`idd_frm`.
    :rtype: :class:`numpy.ndarray`
    )r�idd_frmi��ms rr'r'�����<��?�?�rc�,�tj||��S)a�
    Initialize data for :func:`idd_sfrm`.

    :param l:
        Length of output transformed vector.
    :type l: int
    :param m:
        Length of the vector to be transformed.
    :type m: int

    :return:
        Greatest power-of-two integer `n` satisfying `n <= m`.
    :rtype: int
    :return:
        Initialization array to be used by :func:`idd_sfrm`.
    :rtype: :class:`numpy.ndarray`
    )r�	idd_sfrmi�r$r)s  rr,r,����$�=��A���rc��t|��}tj||��\}}}|jd}|j���d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a real matrix to a specified relative precision.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    �Nrr)rr�iddp_id�shape�T�ravel�reshape��epsr
�k�idx�rnormsr�projs       rr1r1��z��*	�Q���A��[��a�(�(�N�A�s�F�	���
�A��3�9�9�;�;�x��1�Q�3��x� �(�(�!�Q�q�S���(�=�=�D��c�4�<�rc���t|��}tj||��\}}|jd}|j���d|||z
z��|||z
fd���}||fS)aQ
    Compute ID of a real matrix to a specified rank.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r0Nrr)rr�iddr_idr2r3r4r5�r
r8r9r:rr;s      rr>r>��v��$	�Q���A��+�a��#�#�K�C��	���
�A��3�9�9�;�;�x��1�Q�3��x� �(�(�!�Q�q�S���(�=�=�D���9�rc��tj|��}|jdkrtj|||��S|dd�tj|��fS)as
    Reconstruct matrix from real ID.

    :param B:
        Skeleton matrix.
    :type B: :class:`numpy.ndarray`
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Reconstructed matrix.
    :rtype: :class:`numpy.ndarray`
    rN)rr�sizer�idd_reconid�argsort��Br9r;s   rrCrC��O��$	��!���A��y�1�}�}���q�#�t�,�,�,�����B�J�s�O�O�#�$�$rc�,�tj||��S)a6
    Reconstruct interpolation matrix from real ID.

    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Interpolation matrix.
    :rtype: :class:`numpy.ndarray`
    )r�idd_reconint�r9r;s  rrIrI�����C��&�&�&rc�V�tj|��}tj|||��S)aN
    Reconstruct skeleton matrix from real ID.

    :param A:
        Original matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`

    :return:
        Skeleton matrix.
    :rtype: :class:`numpy.ndarray`
    )rrr�idd_copycols�r
r8r9s   rrMrM%�)��$	��!���A���A�q�#�&�&�&rc�|�tj|��}tj|||��\}}}}|rt�|||fS)a
    Convert real ID to SVD.

    :param B:
        Skeleton matrix.
    :type B: :class:`numpy.ndarray`
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    )rrr�
idd_id2svd�_RETCODE_ERROR�rFr9r;�U�V�S�iers       rrQrQ?�H��0	��!���A��>�!�S�$�/�/�L�A�q�!�S�
�����a��7�Nr�c�<�tj|||||��\}}|S)a
    Estimate spectral norm of a real matrix by the randomized power method.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param its:
        Number of power method iterations.
    :type its: int

    :return:
        Spectral norm estimate.
    :rtype: float
    )r�	idd_snorm)r)r�matvect�matvec�its�snorm�vs       rr[r[b�$��8�}�Q��7�F�C�8�8�H�E�1��Lrc	�6�tj|||||||��S)a0
    Estimate spectral norm of the difference of two real matrices by the
    randomized power method.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the transpose of the first matrix to a vector, with
        call signature `y = matvect(x)`, where `x` and `y` are the input and
        output vectors, respectively.
    :type matvect: function
    :param matvect2:
        Function to apply the transpose of the second matrix to a vector, with
        call signature `y = matvect2(x)`, where `x` and `y` are the input and
        output vectors, respectively.
    :type matvect2: function
    :param matvec:
        Function to apply the first matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param matvec2:
        Function to apply the second matrix to a vector, with call signature
        `y = matvec2(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec2: function
    :param its:
        Number of power method iterations.
    :type its: int

    :return:
        Spectral norm estimate of matrix difference.
    :rtype: float
    )r�
idd_diffsnorm)r)rr\�matvect2r]�matvec2r^s       rrcrc��"��N��Q��7�H�f�g�s�K�K�Krc�z�tj|��}tj||��\}}}}|rt�|||fS)a�
    Compute SVD of a real matrix to a specified rank.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    )rrr�iddr_svdrR�r
r8rTrUrVrWs      rrhrh��F��*	��!���A��<��1�%�%�L�A�q�!�S�
�����a��7�Nrc�l�tj|��}|j\}}tj||��\}}}}}}	|	rt
�||dz
|||zzdz
��||fd���}
||dz
|||zzdz
��||fd���}||dz
||zdz
�}|
||fS)a�
    Compute SVD of a real matrix to a specified relative precision.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0rr)rrr2r�iddp_svdrRr5�
r7r
r)rr8�iU�iV�iSrrWrTrUrVs
             rrlrl�����*	��!���A��7�D�A�q��L��a�0�0��A�r�2�r�1�c�
����	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�t�A�v�+��A��a��7�Nrc�@�tj|��}|j\}}t|��\}}tj|d|zdzz|zdzd���}tj||||��\}}}|d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a real matrix to a specified relative precision using random
    sampling.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    �r0rrN)rrr2r'�emptyr�iddp_aidr5�	r7r
r)r�n2rr;r8r9s	         rruru�s���,	��!���A��7�D�A�q��Q�K�K�E�B��
�8�A�q��t�a�x�L�2�%��)��5�5�5�D��<��Q��4�0�0�L�A�s�D����A�a�C���>�!�!�1�a��c�(�#�!�6�6�D��c�4�<�rc���tj|��}|j\}}t|��\}}tj||z|dz|dzzzd���}tj||||��\}}|S)ae
    Estimate rank of a real matrix to a specified relative precision using
    random sampling.

    The output rank is typically about 8 higher than the actual rank.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank estimate.
    :rtype: int
    r0rr)rrr2r'rtr�idd_estrank�r7r
r)rrwr�rar8s        rryrysv��$	��!���A��7�D�A�q��Q�K�K�E�B��	��!�B�$�!�a�%�"�q�&�)�)��	5�	5�	5�B��O�C��A�r�*�*�E�A�r��Hrc
�l�tj|��}|j\}}tj|��\}}tjt
t||��dzd|zd|zzdzzdt||��dzzzd|zdz|dzz��d���}tj||||��\}}}	}
}}|rt�||dz
|||zzdz
��
||fd���}||	dz
|	||zzdz
��
||fd���}
||
dz
|
|zdz
�}||
|fS)a�
    Compute SVD of a real matrix to a specified relative precision using random
    sampling.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0���rsrr)rrr2rr'rt�max�min�	iddp_asvdrRr5�r7r
r)rrw�winitrr8rnrorprWrTrUrVs               rr�r�-sb��,	��!���A��7�D�A�q���Q���I�B��
���S��A�Y�Y��]�Q�q�S�1�Q�3�Y��]�+�b��Q����A��o�=�
�q�S�1�W�r�A�v��	 �	 ��	�	�	�A� �M�#�q�%��;�;��A�r�2�r�1�c�
����	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�t�A�v�+��A��a��7�Nrc��tj|dzd|zt||��dzzzd���}tj|||||��\}}}}|dkrt
�|d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a real matrix to a specified relative precision using random
    matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r0rsrrrN)rrtr�r�iddp_ridrRr5)r7r)rr\r;r8r9rWs        rr�r�Ws���<�8�A��E�A�a�C��Q����Q��/�/�s�;�;�;�D���S�!�Q���>�>��A�s�D�#�
�a�x�x������A�a�C���>�!�!�1�a��c�(�#�!�6�6�D��c�4�<�rc�N�tj||||��\}}}|rt�|S)aQ
    Estimate rank of a real matrix to a specified relative precision using
    random matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function

    :return:
        Rank estimate.
    :rtype: int
    )r�idd_findrankrR)r7r)rr\r8r{rWs       rr�r�}�3��0�!�#�q�!�W�5�5�J�A�r�3�
�����Hrc�6�tj|||||��\}}}}}	}
|
rt�|	|dz
|||zzdz
��||fd���}|	|dz
|||zzdz
��||fd���}|	|dz
||zdz
�}
|||
fS)a�
    Compute SVD of a real matrix to a specified relative precision using random
    matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0rr)r�	iddp_rsvdrRr5)r7r)rr\r]r8rnrorprrWrTrUrVs              rr�r������F �M�#�q�!�W�f�E�E��A�r�2�r�1�c�
����	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�t�A�v�+��A��a��7�Nrc��tj|��}|j\}}t|||��}t	j|||��\}}||krtj|||z
fdd���}n|�|||z
fd���}||fS)ag
    Compute ID of a real matrix to a specified rank using random sampling.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    �float64r��dtyperr)rrr2�	iddr_aidir�iddr_aidrtr5�r
r8r)rrr9r;s       rr�r��s���$	��!���A��7�D�A�q��!�Q����A���Q��1�%�%�I�C���A�v�v��x��A�a�C��	��=�=�=����|�|�Q��!��H�C�|�0�0����9�rc�.�tj|||��S)aO
    Initialize array for :func:`iddr_aid`.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Initialization array to be used by :func:`iddr_aid`.
    :rtype: :class:`numpy.ndarray`
    )rr��r)rr8s   rr�r�����$�=��A�q�!�!�!rc�@�tj|��}|j\}}tjd|zdz|zd|zdz|zzd|dzzzdzd���}t	|||��}||d	|j�<t
j|||��\}}}}	|	d
krt�|||fS)a�
    Compute SVD of a real matrix to a specified rank using random sampling.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    rs���r�drrNr)	rrr2rtr�rBr�	iddr_asvdrR�
r
r8r)rr�w_rTrUrVrWs
          rr�r�s���*	��!���A��7�D�A�q�
��!�A�#��(�A���1��r��1��,�r�!�Q�$�w�6��<�C�H�H�H�A�	�1�a��	�	�B��A�h�r�w�h�K��=��A�q�)�)�L�A�q�!�S�
�a�x�x����a��7�Nrc��tj||||��\}}|d|||z
z��|||z
fd���}||fS)a�
    Compute ID of a real matrix to a specified rank using random matrix-vector
    multiplication.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    Nrr)r�iddr_ridr5)r)rr\r8r9r;s      rr�r�)�W��6��Q��7�A�.�.�I�C�����A�a�C���>�!�!�1�a��c�(�#�!�6�6�D���9�rc�`�tj|||||��\}}}}|dkrt�|||fS)a�
    Compute SVD of a real matrix to a specified rank using random matrix-vector
    multiplication.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matvect:
        Function to apply the matrix transpose to a vector, with call signature
        `y = matvect(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvect: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r)r�	iddr_rsvdrR)	r)rr\r]r8rTrUrVrWs	         rr�r�Ms>��F�=��A�w���:�:�L�A�q�!�S�
�a�x�x����a��7�Nrc�.�tj|||��S)a
    Transform complex vector via a composition of Rokhlin's random transform,
    random subselection, and an FFT.

    In contrast to :func:`idz_sfrm`, this routine works best when the length of
    the transformed vector is the power-of-two integer output by
    :func:`idz_frmi`, or when the length is not specified but instead
    determined a posteriori from the output. The returned transformed vector is
    randomly permuted.

    :param n:
        Greatest power-of-two integer satisfying `n <= x.size` as obtained from
        :func:`idz_frmi`; `n` is also the length of the output vector.
    :type n: int
    :param w:
        Initialization array constructed by :func:`idz_frmi`.
    :type w: :class:`numpy.ndarray`
    :param x:
        Vector to be transformed.
    :type x: :class:`numpy.ndarray`

    :return:
        Transformed vector.
    :rtype: :class:`numpy.ndarray`
    )r�idz_frmrs   rr�r�zr rc�0�tj||||��S)a�
    Transform complex vector via a composition of Rokhlin's random transform,
    random subselection, and an FFT.

    In contrast to :func:`idz_frm`, this routine works best when the length of
    the transformed vector is known a priori.

    :param l:
        Length of transformed vector, satisfying `l <= n`.
    :type l: int
    :param n:
        Greatest power-of-two integer satisfying `n <= x.size` as obtained from
        :func:`idz_sfrmi`.
    :type n: int
    :param w:
        Initialization array constructed by :func:`idd_sfrmi`.
    :type w: :class:`numpy.ndarray`
    :param x:
        Vector to be transformed.
    :type x: :class:`numpy.ndarray`

    :return:
        Transformed vector.
    :rtype: :class:`numpy.ndarray`
    )r�idz_sfrmr#s    rr�r��r%rc�*�tj|��S)aC
    Initialize data for :func:`idz_frm`.

    :param m:
        Length of vector to be transformed.
    :type m: int

    :return:
        Greatest power-of-two integer `n` satisfying `n <= m`.
    :rtype: int
    :return:
        Initialization array to be used by :func:`idz_frm`.
    :rtype: :class:`numpy.ndarray`
    )r�idz_frmir(s rr�r��r*rc�,�tj||��S)a�
    Initialize data for :func:`idz_sfrm`.

    :param l:
        Length of output transformed vector.
    :type l: int
    :param m:
        Length of the vector to be transformed.
    :type m: int

    :return:
        Greatest power-of-two integer `n` satisfying `n <= m`.
    :rtype: int
    :return:
        Initialization array to be used by :func:`idz_sfrm`.
    :rtype: :class:`numpy.ndarray`
    )r�	idz_sfrmir-s  rr�r��r.rc��t|��}tj||��\}}}|jd}|j���d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a complex matrix to a specified relative precision.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r0Nrr)rr�idzp_idr2r3r4r5r6s       rr�r��r<rc���t|��}tj||��\}}|jd}|j���d|||z
z��|||z
fd���}||fS)aT
    Compute ID of a complex matrix to a specified rank.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r0Nrr)rr�idzr_idr2r3r4r5r?s      rr�r��r@rc��tj|��}|jdkrtj|||��S|dd�tj|��fS)av
    Reconstruct matrix from complex ID.

    :param B:
        Skeleton matrix.
    :type B: :class:`numpy.ndarray`
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Reconstructed matrix.
    :rtype: :class:`numpy.ndarray`
    rN)rrrBr�idz_reconidrDrEs   rr�r�rGrc�,�tj||��S)a9
    Reconstruct interpolation matrix from complex ID.

    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Interpolation matrix.
    :rtype: :class:`numpy.ndarray`
    )r�idz_reconintrJs  rr�r�-rKrc�V�tj|��}tj|||��S)aQ
    Reconstruct skeleton matrix from complex ID.

    :param A:
        Original matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`

    :return:
        Skeleton matrix.
    :rtype: :class:`numpy.ndarray`
    )rrr�idz_copycolsrNs   rr�r�?rOrc�|�tj|��}tj|||��\}}}}|rt�|||fS)a
    Convert complex ID to SVD.

    :param B:
        Skeleton matrix.
    :type B: :class:`numpy.ndarray`
    :param idx:
        Column index array.
    :type idx: :class:`numpy.ndarray`
    :param proj:
        Interpolation coefficients.
    :type proj: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    )rrr�
idz_id2svdrRrSs       rr�r�YrXrc�<�tj|||||��\}}|S)a
    Estimate spectral norm of a complex matrix by the randomized power method.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param its:
        Number of power method iterations.
    :type its: int

    :return:
        Spectral norm estimate.
    :rtype: float
    )r�	idz_snorm)r)r�matvecar]r^r_r`s       rr�r�|rarc	�6�tj|||||||��S)a/
    Estimate spectral norm of the difference of two complex matrices by the
    randomized power method.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the adjoint of the first matrix to a vector, with
        call signature `y = matveca(x)`, where `x` and `y` are the input and
        output vectors, respectively.
    :type matveca: function
    :param matveca2:
        Function to apply the adjoint of the second matrix to a vector, with
        call signature `y = matveca2(x)`, where `x` and `y` are the input and
        output vectors, respectively.
    :type matveca2: function
    :param matvec:
        Function to apply the first matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param matvec2:
        Function to apply the second matrix to a vector, with call signature
        `y = matvec2(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec2: function
    :param its:
        Number of power method iterations.
    :type its: int

    :return:
        Spectral norm estimate of matrix difference.
    :rtype: float
    )r�
idz_diffsnorm)r)rr��matveca2r]rer^s       rr�r��rfrc�z�tj|��}tj||��\}}}}|rt�|||fS)a�
    Compute SVD of a complex matrix to a specified rank.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    )rrr�idzr_svdrRris      rr�r��rjrc�l�tj|��}|j\}}tj||��\}}}}}}	|	rt
�||dz
|||zzdz
��||fd���}
||dz
|||zzdz
��||fd���}||dz
||zdz
�}|
||fS)a�
    Compute SVD of a complex matrix to a specified relative precision.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0rr)rrr2r�idzp_svdrRr5rms
             rr�r��rqrc�B�tj|��}|j\}}t|��\}}tj|d|zdzz|zdzdd���}tj||||��\}}}|d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a complex matrix to a specified relative precision using
    random sampling.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    rsr0�
complex128rr�Nr)rrr2r�rtr�idzp_aidr5rvs	         rr�r�
s���,	��!���A��7�D�A�q��Q�K�K�E�B��
�8�A�q��t�a�x�L�2�%��)��S�I�I�I�D��<��Q��4�0�0�L�A�s�D����A�a�C���>�!�!�1�a��c�(�#�!�6�6�D��c�4�<�rc���tj|��}|j\}}t|��\}}tj||z|dz|dzzzdd���}tj||||��\}}|S)ah
    Estimate rank of a complex matrix to a specified relative precision using
    random sampling.

    The output rank is typically about 8 higher than the actual rank.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Rank estimate.
    :rtype: int
    r0r�rr�)rrr2r�rtr�idz_estrankrzs        rr�r�)sx��$	��!���A��7�D�A�q��Q�K�K�E�B��	��!�B�$�!�a�%�"�q�&�)�)��S�	I�	I�	I�B��O�C��A�r�*�*�E�A�r��Hrc
��tj|��}|j\}}tj|��\}}tjt
t||��dzd|zd|zzdzzdt||��dzzzd|zdz|dzz��tjd���}tj	||||��\}}}	}
}}|rt�||dz
|||zzdz
��||fd�	��}||	dz
|	||zzdz
��||fd�	��}
||
dz
|
|zdz
�}||
|fS)
a�
    Compute SVD of a complex matrix to a specified relative precision using
    random sampling.

    :param eps:
        Relative precision.
    :type eps: float
    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0r}r~��rsrr�r)rrr2rr�rtr�r�r��	idzp_asvdrRr5r�s               rr�r�Gsf��,	��!���A��7�D�A�q���Q���I�B��
���S��A�Y�Y��]�Q�q�S�1�Q�3�Y��^�,�q��Q����A��~�=�
�q�S�1�W�r�A�v��	 �	 ��m�3�	(�	(�	(�A� �M�#�q�%��;�;��A�r�2�r�1�c�
����	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�A�#�v�a�x�-�� � �!�Q��s� �3�3�A�	�"�Q�$�r�!�t�A�v�+��A��a��7�Nrc�(�tj|dzd|zt||��dzzztjd���}t	j|||||��\}}}}|rt�|d|||z
z��|||z
fd���}|||fS)a�
    Compute ID of a complex matrix to a specified relative precision using
    random matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function

    :return:
        Rank of ID.
    :rtype: int
    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r0rsrr�Nr)rrtr�r�r�idzp_ridrRr5)r7r)rr�r;r8r9rWs        rr�r�qs���<�8�	�A���!��S��A�Y�Y��]�#�#��m�3�(�(�(�D���S�!�Q���>�>��A�s�D�#�
�������A�a�C���>�!�!�1�a��c�(�#�!�6�6�D��c�4�<�rc�N�tj||||��\}}}|rt�|S)aR
    Estimate rank of a complex matrix to a specified relative precision using
    random matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function

    :return:
        Rank estimate.
    :rtype: int
    )r�idz_findrankrR)r7r)rr�r8r{rWs       rr�r��r�rc�6�tj|||||��\}}}}}	}
|
rt�|	|dz
|||zzdz
��||fd���}|	|dz
|||zzdz
��||fd���}|	|dz
||zdz
�}
|||
fS)a�
    Compute SVD of a complex matrix to a specified relative precision using
    random matrix-vector multiplication.

    :param eps:
        Relative precision.
    :type eps: float
    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    r0rr)r�	idzp_rsvdrRr5)r7r)rr�r]r8rnrorprrWrTrUrVs              rr�r��r�rc��tj|��}|j\}}t|||��}t	j|||��\}}||krtj|||z
fdd���}n|�|||z
fd���}||fS)aj
    Compute ID of a complex matrix to a specified rank using random sampling.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    r�rr�r)rrr2�	idzr_aidir�idzr_aidrtr5r�s       rr�r��s���$	��!���A��7�D�A�q��!�Q����A���Q��1�%�%�I�C���A�v�v��x��A�a�C���C�@�@�@����|�|�Q��!��H�C�|�0�0����9�rc�.�tj|||��S)aO
    Initialize array for :func:`idzr_aid`.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Initialization array to be used by :func:`idzr_aid`.
    :rtype: :class:`numpy.ndarray`
    )rr�r�s   rr�r�r�rc�F�tj|��}|j\}}tjd|zdz|zd|zdz|zzd|dzzzd|zzdzdd	�
��}t	|||��}||d|j�<t
j|||��\}}}}	|	rt�|||fS)a�
    Compute SVD of a complex matrix to a specified rank using random sampling.

    :param A:
        Matrix.
    :type A: :class:`numpy.ndarray`
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    rs�r�r�r��
�Zr�rr�N)	rrr2rtr�rBr�	idzr_asvdrRr�s
          rr�r�!s���*	��!���A��7�D�A�q�
��	
�1��r��1���!��b��!�|�#�a��1��f�,�r�!�t�3�b�8��#�	'�	'�	'�A�
�1�a��	�	�B��A�h�r�w�h�K��=��A�q�)�)�L�A�q�!�S�
�����a��7�Nrc��tj||||��\}}|d|||z
z��|||z
fd���}||fS)a�
    Compute ID of a complex matrix to a specified rank using random
    matrix-vector multiplication.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function
    :param k:
        Rank of ID.
    :type k: int

    :return:
        Column index array.
    :rtype: :class:`numpy.ndarray`
    :return:
        Interpolation coefficients.
    :rtype: :class:`numpy.ndarray`
    Nrr)r�idzr_ridr5)r)rr�r8r9r;s      rr�r�Gr�rc�X�tj|||||��\}}}}|rt�|||fS)a�
    Compute SVD of a complex matrix to a specified rank using random
    matrix-vector multiplication.

    :param m:
        Matrix row dimension.
    :type m: int
    :param n:
        Matrix column dimension.
    :type n: int
    :param matveca:
        Function to apply the matrix adjoint to a vector, with call signature
        `y = matveca(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matveca: function
    :param matvec:
        Function to apply the matrix to a vector, with call signature
        `y = matvec(x)`, where `x` and `y` are the input and output vectors,
        respectively.
    :type matvec: function
    :param k:
        Rank of SVD.
    :type k: int

    :return:
        Left singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Right singular vectors.
    :rtype: :class:`numpy.ndarray`
    :return:
        Singular values.
    :rtype: :class:`numpy.ndarray`
    )r�	idzr_rsvdrR)	r)rr�r]r8rTrUrVrWs	         rr�r�ks=��F�=��A�w���:�:�L�A�q�!�S�
�����a��7�Nr)rY)?�__doc__�scipy.linalg._interpolative�linalg�_interpolativer�numpyr�RuntimeErrorrRrrrrrr"r'r,r1r>rCrIrMrQr[rcrhrlruryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�<module>r�s���<��*�)�)�)�)�)�)�)�)�������3�4�4��	
�	
�	
� 
�
�
� 
�
�
���� � � �:$�$�$�:���$���2���8���2%�%�%�2'�'�'�$'�'�'�4���F����@'L�'L�'L�'L�\���8���H���>
�
�
�<#�#�#�T#�#�#�L
�
�
�D)�)�)�`���:"�"�"�2���H���H&�&�&�Z � � �:$�$�$�:���$���2���8���2%�%�%�2'�'�'�$'�'�'�4���F����@'L�'L�'L�'L�\���8���H���>
�
�
�<#�#�#�T%�%�%�P
�
�
�D)�)�)�`���:"�"�"�2���L���H&�&�&�&�&r

Youez - 2016 - github.com/yon3zu
LinuXploit