§
    ¢éUgˆ°  ã                   ó†  — d Z ddlmc mZ ddlZ e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„Zd;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#„ 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>dS )<z0
Direct wrappers for Fortran `id_dist` backend.
é    Nznonzero return codec                 óœ   — t          j        | ¦  «        } | j        j        r|                      d¬¦  «        } nt          j        | ¦  «        } | S )z6
    Same as np.asfortranarray, but ensure a copy
    ÚF©Úorder)ÚnpÚasarrayÚflagsÚf_contiguousÚcopyÚasfortranarray)ÚAs    úb/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/linalg/_interpolative_backend.pyÚ_asfortranarray_copyr   (   sH   € õ 	Œ
�1‰Œ€AØ„wÔð !Ø�FŠF˜ˆFÑÔˆˆåÔ˜aÑ Ô ˆØ€Hó    c                 ó*   — t          j        | ¦  «        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    r   r   r   8   s   € õ Œ<˜‰?Œ?Ðr   c                 óV   — t          j        | ¦  «        } t          j        | ¦  «         dS )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)r   r   r   Ú	id_srandi)Úts    r   r   r   H   s*   € õ 	Ô˜!ÑÔ€AÝ„M�!ÑÔÐÐÐr   c                  ó,   — t          j        ¦   «          dS )z5
    Reset seed values to their original values.
    N)r   Ú	id_srando© r   r   r   r   U   s   € õ „M�O„O€O€O€Or   c                 ó.   — t          j        | ||¦  «        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      r   r   r   `   ó   € õ4 Œ;�q˜!˜QÑÔÐr   c                 ó0   — t          j        | |||¦  «        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©Úlr   r   r   s       r   r"   r"   }   ó   € õ4 Œ<˜˜1˜a Ñ#Ô#Ð#r   c                 ó*   — t          j        | ¦  «        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    r   r'   r'   š   ó   € õ Œ<˜‰?Œ?Ðr   c                 ó,   — t          j        | |¦  «        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     r   r,   r,   ¬   ó   € õ$ Œ=˜˜AÑÔÐr   c                 óø   — t          |¦  «        }t          j        | |¦  «        \  }}}|j        d         }|j                             ¦   «         d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    é   Nr   r   )r   r   Úiddp_idÚshapeÚTÚravelÚreshape©Úepsr   ÚkÚidxÚrnormsr   Úprojs          r   r1   r1   Å   óz   € õ* 	˜QÑÔ€AÝ”[  aÑ(Ô(�N€A€sˆFØ	Œ�Œ
€AØŒ3�9Š9‰;Œ;�x˜˜1˜Q™3™�xÔ ×(Ò(¨!¨Q¨q©S¨¸Ð(Ñ=Ô=€DØˆc�4ˆ<Ðr   c                 óô   — t          | ¦  «        } t          j        | |¦  «        \  }}| j        d         }| j                             ¦   «         d|||z
  z  …                              |||z
  fd¬¦  «        }||fS )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`
    r0   Nr   r   )r   r   Úiddr_idr2   r3   r4   r5   ©r   r8   r9   r:   r   r;   s         r   r>   r>   á   óv   € õ$ 	˜QÑÔ€AÝ”+˜a Ñ#Ô#�K€CˆØ	Œ�Œ
€AØŒ3�9Š9‰;Œ;�x˜˜1˜Q™3™�xÔ ×(Ò(¨!¨Q¨q©S¨¸Ð(Ñ=Ô=€DØ�ˆ9Ðr   c                 ó¨   — t          j        | ¦  «        } |j        dk    rt          j        | ||¦  «        S | dd…t          j        |¦  «        f         S )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`
    r   N)r   r   Úsizer   Úidd_reconidÚargsort©ÚBr9   r;   s      r   rC   rC   ú   óO   € õ$ 	Ô˜!ÑÔ€AØ„y�1‚}€}ÝŒ˜q # tÑ,Ô,Ð,à���•B”J˜s‘O”OÐ#Ô$Ð$r   c                 ó,   — t          j        | |¦  «        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©r9   r;   s     r   rI   rI     ó   € õ Ô˜C Ñ&Ô&Ð&r   c                 óV   — t          j        | ¦  «        } t          j        | ||¦  «        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`
    )r   r   r   Úidd_copycols©r   r8   r9   s      r   rM   rM   %  ó)   € õ$ 	Ô˜!ÑÔ€AÝÔ˜A˜q #Ñ&Ô&Ð&r   c                 ó|   — t          j        | ¦  «        } t          j        | ||¦  «        \  }}}}|rt          ‚|||fS )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`
    )r   r   r   Ú
idd_id2svdÚ_RETCODE_ERROR©rF   r9   r;   ÚUÚVÚSÚiers          r   rQ   rQ   ?  óH   € õ0 	Ô˜!ÑÔ€AÝ”> ! S¨$Ñ/Ô/�L€A€qˆ!ˆSØ
ð ÝÐØˆa�ˆ7€Nr   é   c                 ó<   — t          j        | ||||¦  «        \  }}|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          r   r[   r[   b  ó$   € õ8 Œ}˜Q  7¨F°CÑ8Ô8�H€Eˆ1Ø€Lr   c           	      ó6   — t          j        | ||||||¦  «        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)   r   r\   Úmatvect2r]   Úmatvec2r^   s          r   rc   rc   ‚  ó"   € õN Ô˜Q  7¨H°f¸gÀsÑKÔKÐKr   c                 óz   — t          j        | ¦  «        } t          j        | |¦  «        \  }}}}|rt          ‚|||fS )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`
    )r   r   r   Úiddr_svdrR   ©r   r8   rT   rU   rV   rW   s         r   rh   rh   °  óF   € õ* 	Ô˜!ÑÔ€AÝ”<  1Ñ%Ô%�L€A€qˆ!ˆSØ
ð ÝÐØˆa�ˆ7€Nr   c                 ól  — t          j        |¦  «        }|j        \  }}t          j        | |¦  «        \  }}}}}}	|	rt
          ‚||dz
  |||z  z   dz
  …                              ||fd¬¦  «        }
||dz
  |||z  z   dz
  …                              ||fd¬¦  «        }||dz
  ||z   dz
  …         }|
||fS )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`
    r0   r   r   )r   r   r2   r   Úiddp_svdrR   r5   ©r7   r   r)   r   r8   ÚiUÚiVÚiSr   rW   rT   rU   rV   s                r   rl   rl   Ì  óÙ   € õ* 	Ô˜!ÑÔ€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€Nr   c                 ó@  — t          j        |¦  «        }|j        \  }}t          |¦  «        \  }}t          j        |d|z  dz   z  |z   dz   d¬¦  «        }t          j        | |||¦  «        \  }}}|d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    é   r0   r   r   N)r   r   r2   r'   Úemptyr   Úiddp_aidr5   ©	r7   r   r)   r   Ún2r   r;   r8   r9   s	            r   ru   ru   ð  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ˆ<Ðr   c                 óä   — t          j        |¦  «        }|j        \  }}t          |¦  «        \  }}t          j        ||z  |dz   |dz   z  z   d¬¦  «        }t          j        | |||¦  «        \  }}|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
    r0   r   r   )r   r   r2   r'   rt   r   Úidd_estrank©r7   r   r)   r   rw   r   Úrar8   s           r   ry   ry     sv   € õ$ 	Ô˜!ÑÔ€AØŒ7�D€A€qÝ�Q‰KŒK�E€BˆÝ	Œ�!�B‘$˜!˜a™% " q¡&Ñ)Ñ)°Ð	5Ñ	5Ô	5€BÝŒO˜C  A rÑ*Ô*�E€A€rØ€Hr   c           
      ól  — t          j        |¦  «        }|j        \  }}t          j        |¦  «        \  }}t          j        t          t          ||¦  «        dz   d|z  d|z  z   dz   z  dt          ||¦  «        dz  z  z   d|z  dz   |dz   z  ¦  «        d¬¦  «        }t          j        | |||¦  «        \  }}}	}
}}|rt          ‚||dz
  |||z  z   dz
  …          
                    ||fd¬¦  «        }||	dz
  |	||z  z   dz
  …          
                    ||fd¬¦  «        }||
dz
  |
|z   dz
  …         }|||fS )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   é   é   é   rs   r   r   )r   r   r2   r   r'   rt   ÚmaxÚminÚ	iddp_asvdrR   r5   ©r7   r   r)   r   rw   Úwinitr   r8   rn   ro   rp   rW   rT   rU   rV   s                  r   r‚   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€Nr   c                 ó  — t          j        |dz   d|z  t          ||¦  «        dz   z  z   d¬¦  «        }t          j        | ||||¦  «        \  }}}}|dk    rt
          ‚|d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    r0   rs   r   r   r   N)r   rt   r�   r   Úiddp_ridrR   r5   )r7   r)   r   r\   r;   r8   r9   rW   s           r   r†   r†   W  s¡   € õ< Œ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ˆ<Ðr   c                 óN   — t          j        | |||¦  «        \  }}}|rt          ‚|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   )r7   r)   r   r\   r8   r{   rW   s          r   rˆ   rˆ   }  ó3   € õ0 Ô! # q¨!¨WÑ5Ô5�J€A€rˆ3Ø
ð ÝÐØ€Hr   c                 ó6  — t          j        | ||||¦  «        \  }}}}}	}
|
rt          ‚|	|dz
  |||z  z   dz
  …                              ||fd¬¦  «        }|	|dz
  |||z  z   dz
  …                              ||fd¬¦  «        }|	|dz
  ||z   dz
  …         }|||fS )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`
    r0   r   r   )r   Ú	iddp_rsvdrR   r5   )r7   r)   r   r\   r]   r8   rn   ro   rp   r   rW   rT   rU   rV   s                 r   r‹   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€Nr   c                 ó  — t          j        | ¦  «        } | j        \  }}t          |||¦  «        }t	          j        | ||¦  «        \  }}||k    rt          j        |||z
  fdd¬¦  «        }n|                     |||z
  fd¬¦  «        }||fS )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   ©Údtyper   r   )r   r   r2   Ú	iddr_aidir   Úiddr_aidrt   r5   ©r   r8   r)   r   r   r9   r;   s          r   r’   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Ðr   c                 ó.   — t          j        | ||¦  «        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`
    )r   r‘   ©r)   r   r8   s      r   r‘   r‘   ì  ó   € õ$ Œ=˜˜A˜qÑ!Ô!Ð!r   c                 ó@  — t          j        | ¦  «        } | j        \  }}t          j        d|z  dz   |z  d|z  dz   |z  z   d|dz  z  z   dz   d¬¦  «        }t	          |||¦  «        }||d	|j        …<   t          j        | ||¦  «        \  }}}}	|	d
k    rt          ‚|||fS )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   éd   r   r   Nr   )	r   r   r2   rt   r‘   rB   r   Ú	iddr_asvdrR   ©
r   r8   r)   r   r   Úw_rT   rU   rV   rW   s
             r   rœ   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€Nr   c                 ó’   — t          j        | |||¦  «        \  }}|d|||z
  z  …                              |||z
  fd¬¦  «        }||fS )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`
    Nr   r   )r   Úiddr_ridr5   )r)   r   r\   r8   r9   r;   s         r   r    r    )  óW   € õ6 ”˜Q  7¨AÑ.Ô.�I€CˆØ���A�a‘C‘�Œ>×!Ò! 1 a¨¡c (°#Ð!Ñ6Ô6€DØ�ˆ9Ðr   c                 ó`   — t          j        | ||||¦  «        \  }}}}|dk    rt          ‚|||fS )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)   r   r\   r]   r8   rT   rU   rV   rW   s	            r   r£   r£   M  s>   € õF ”=  A w°¸Ñ:Ô:�L€A€qˆ!ˆSØ
ˆa‚x€xÝÐØˆa�ˆ7€Nr   c                 ó.   — t          j        | ||¦  «        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_frmr   s      r   r¥   r¥   z  r    r   c                 ó0   — t          j        | |||¦  «        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       r   r§   r§   —  r%   r   c                 ó*   — t          j        | ¦  «        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    r   r©   r©   ´  r*   r   c                 ó,   — t          j        | |¦  «        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     r   r«   r«   Æ  r.   r   c                 óø   — t          |¦  «        }t          j        | |¦  «        \  }}}|j        d         }|j                             ¦   «         d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    r0   Nr   r   )r   r   Úidzp_idr2   r3   r4   r5   r6   s          r   r­   r­   ß  r<   r   c                 óô   — t          | ¦  «        } t          j        | |¦  «        \  }}| j        d         }| j                             ¦   «         d|||z
  z  …                              |||z
  fd¬¦  «        }||fS )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`
    r0   Nr   r   )r   r   Úidzr_idr2   r3   r4   r5   r?   s         r   r¯   r¯   û  r@   r   c                 ó¨   — t          j        | ¦  «        } |j        dk    rt          j        | ||¦  «        S | dd…t          j        |¦  «        f         S )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`
    r   N)r   r   rB   r   Úidz_reconidrD   rE   s      r   r±   r±     rG   r   c                 ó,   — t          j        | |¦  «        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_reconintrJ   s     r   r³   r³   -  rK   r   c                 óV   — t          j        | ¦  «        } t          j        | ||¦  «        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`
    )r   r   r   Úidz_copycolsrN   s      r   rµ   rµ   ?  rO   r   c                 ó|   — t          j        | ¦  «        } t          j        | ||¦  «        \  }}}}|rt          ‚|||fS )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`
    )r   r   r   Ú
idz_id2svdrR   rS   s          r   r·   r·   Y  rX   r   c                 ó<   — t          j        | ||||¦  «        \  }}|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          r   r¹   r¹   |  ra   r   c           	      ó6   — t          j        | ||||||¦  «        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)   r   rº   Úmatveca2r]   re   r^   s          r   r¼   r¼   œ  rf   r   c                 óz   — t          j        | ¦  «        } t          j        | |¦  «        \  }}}}|rt          ‚|||fS )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`
    )r   r   r   Úidzr_svdrR   ri   s         r   r¿   r¿   Ê  rj   r   c                 ól  — t          j        |¦  «        }|j        \  }}t          j        | |¦  «        \  }}}}}}	|	rt
          ‚||dz
  |||z  z   dz
  …                              ||fd¬¦  «        }
||dz
  |||z  z   dz
  …                              ||fd¬¦  «        }||dz
  ||z   dz
  …         }|
||fS )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`
    r0   r   r   )r   r   r2   r   Úidzp_svdrR   r5   rm   s                r   rÁ   rÁ   æ  rq   r   c                 óB  — t          j        |¦  «        }|j        \  }}t          |¦  «        \  }}t          j        |d|z  dz   z  |z   dz   dd¬¦  «        }t          j        | |||¦  «        \  }}}|d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    rs   r0   Ú
complex128r   r�   Nr   )r   r   r2   r©   rt   r   Úidzp_aidr5   rv   s	            r   rÄ   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ˆ<Ðr   c                 óæ   — t          j        |¦  «        }|j        \  }}t          |¦  «        \  }}t          j        ||z  |dz   |dz   z  z   dd¬¦  «        }t          j        | |||¦  «        \  }}|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
    r0   rÃ   r   r�   )r   r   r2   r©   rt   r   Úidz_estrankrz   s           r   rÆ   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Ø€Hr   c           
      ó‚  — t          j        |¦  «        }|j        \  }}t          j        |¦  «        \  }}t          j        t          t          ||¦  «        dz   d|z  d|z  z   dz   z  dt          ||¦  «        dz  z  z   d|z  dz   |dz   z  ¦  «        t           j        d¬¦  «        }t          j	        | |||¦  «        \  }}}	}
}}|rt          ‚||dz
  |||z  z   dz
  …                              ||fd¬	¦  «        }||	dz
  |	||z  z   dz
  …                              ||fd¬	¦  «        }||
dz
  |
|z   dz
  …         }|||fS )
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`
    r0   r}   r~   é   é   rs   r   r�   r   )r   r   r2   r   r©   rt   r€   r�   rÃ   Ú	idzp_asvdrR   r5   rƒ   s                  r   rÊ   rÊ   G  sf  € õ, 	Ô˜!ÑÔ€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€Nr   c                 ó(  — t          j        |dz   d|z  t          ||¦  «        dz   z  z   t           j        d¬¦  «        }t	          j        | ||||¦  «        \  }}}}|rt          ‚|d|||z
  z  …                              |||z
  fd¬¦  «        }|||fS )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`
    r0   rs   r   r�   Nr   )r   rt   r�   rÃ   r   Úidzp_ridrR   r5   )r7   r)   r   rº   r;   r8   r9   rW   s           r   rÌ   rÌ   q  s®   € õ< Œ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ˆ<Ðr   c                 óN   — t          j        | |||¦  «        \  }}}|rt          ‚|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   )r7   r)   r   rº   r8   r{   rW   s          r   rÎ   rÎ   ™  r‰   r   c                 ó6  — t          j        | ||||¦  «        \  }}}}}	}
|
rt          ‚|	|dz
  |||z  z   dz
  …                              ||fd¬¦  «        }|	|dz
  |||z  z   dz
  …                              ||fd¬¦  «        }|	|dz
  ||z   dz
  …         }|||fS )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`
    r0   r   r   )r   Ú	idzp_rsvdrR   r5   )r7   r)   r   rº   r]   r8   rn   ro   rp   r   rW   rT   rU   rV   s                 r   rÐ   rÐ   »  rŒ   r   c                 ó  — t          j        | ¦  «        } | j        \  }}t          |||¦  «        }t	          j        | ||¦  «        \  }}||k    rt          j        |||z
  fdd¬¦  «        }n|                     |||z
  fd¬¦  «        }||fS )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Ã   r   r�   r   )r   r   r2   Ú	idzr_aidir   Úidzr_aidrt   r5   r“   s          r   rÓ   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Ðr   c                 ó.   — t          j        | ||¦  «        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`
    )r   rÒ   r•   s      r   rÒ   rÒ     r–   r   c                 óF  — t          j        | ¦  «        } | j        \  }}t          j        d|z  dz   |z  d|z  dz   |z  z   d|dz  z  z   d|z  z   dz   dd	¬
¦  «        }t	          |||¦  «        }||d|j        …<   t          j        | ||¦  «        \  }}}}	|	rt          ‚|||fS )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É   é
   éZ   rÃ   r   r�   N)	r   r   r2   rt   rÒ   rB   r   Ú	idzr_asvdrR   r�   s
             r   rÙ   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€Nr   c                 ó’   — t          j        | |||¦  «        \  }}|d|||z
  z  …                              |||z
  fd¬¦  «        }||fS )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`
    Nr   r   )r   Úidzr_ridr5   )r)   r   rº   r8   r9   r;   s         r   rÛ   rÛ   G  r¡   r   c                 óX   — t          j        | ||||¦  «        \  }}}}|rt          ‚|||fS )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)   r   rº   r]   r8   rT   rU   rV   rW   s	            r   rÝ   rÝ   k  s=   € õF ”=  A w°¸Ñ:Ô:�L€A€qˆ!ˆSØ
ð ÝÐØˆa�ˆ7€Nr   )rY   )?Ú__doc__Úscipy.linalg._interpolativeÚlinalgÚ_interpolativer   Únumpyr   ÚRuntimeErrorrR   r   r   r   r   r   r"   r'   r,   r1   r>   rC   rI   rM   rQ   r[   rc   rh   rl   ru   ry   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Û   rÝ   r   r   r   ú<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   