ó
Ë½÷Xc           @   s  d  Z  d d l j j 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 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+ „ Z/ d d, „ Z0 d- „  Z1 d. „  Z2 d/ „  Z3 d0 „  Z4 d1 „  Z5 d2 „  Z6 d3 „  Z7 d4 „  Z8 d5 „  Z9 d6 „  Z: d7 „  Z; d8 „  Z< d9 „  Z= d S(:   s0   
Direct wrappers for Fortran `id_dist` backend.
iÿÿÿÿNs   nonzero return codec         C   s   t  j |  ƒ S(   s  
    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`
    (   t   _idt   id_srand(   t   n(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   ,   s    c         C   s    t  j |  ƒ }  t j |  ƒ d S(   s¹   
    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(   t   npt   asfortranarrayR    t	   id_srandi(   t   t(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   <   s    	c           C   s   t  j ƒ  d S(   s5   
    Reset seed values to their original values.
    N(   R    t	   id_srando(    (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   I   s    c         C   s   t  j |  | | ƒ S(   s|  
    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    t   idd_frm(   R   t   wt   x(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   T   s    c         C   s   t  j |  | | | ƒ S(   sê  
    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    t   idd_sfrm(   t   lR   R	   R
   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   q   s    c         C   s   t  j |  ƒ S(   sC  
    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    t   idd_frmi(   t   m(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   Ž   s    c         C   s   t  j |  | ƒ S(   s•  
    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    t	   idd_sfrmi(   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR       s    c         C   sx   t  j | ƒ } t j |  | ƒ \ } } } | j d } | j j ƒ  | | |  j | | | f d d ƒ} | | | f S(   sž  
    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`
    i   t   ordert   F(   R   R   R    t   iddp_idt   shapet   Tt   ravelt   reshape(   t   epst   At   kt   idxt   rnormsR   t   proj(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   ¹   s
    4c         C   sr   t  j |  ƒ }  t j |  | ƒ \ } } |  j d } |  j j ƒ  | | |  j | | | f d d ƒ} | | f S(   sQ  
    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`
    i   R   R   (   R   R   R    t   iddr_idR   R   R   R   (   R   R   R   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   Õ   s
    4c         C   sR   t  j |  ƒ }  | j d k r1 t j |  | | ƒ S|  d d … t  j | ƒ f Sd S(   ss  
    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`
    i    N(   R   R   t   sizeR    t   idd_reconidt   argsort(   t   BR   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR   î   s    c         C   s   t  j |  | ƒ S(   s6  
    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    t   idd_reconint(   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR"     s    c         C   s"   t  j |  ƒ }  t j |  | | ƒ S(   sN  
    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    t   idd_copycols(   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR#     s    c         C   sL   t  j |  ƒ }  t j |  | | ƒ \ } } } } | r? t ‚ n  | | | f S(   s  
    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    t
   idd_id2svdt   _RETCODE_ERROR(   R!   R   R   t   Ut   Vt   St   ier(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR$   3  s
    !	i   c         C   s%   t  j |  | | | | ƒ \ } } | S(   s  
    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    t	   idd_snorm(   R   R   t   matvectt   matvect   itst   snormt   v(    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR*   V  s    !c         C   s   t  j |  | | | | | | ƒ S(   s0  
    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    t   idd_diffsnorm(   R   R   R+   t   matvect2R,   t   matvec2R-   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR0   v  s    'c         C   sI   t  j |  ƒ }  t j |  | ƒ \ } } } } | r< t ‚ n  | | | f S(   s›  
    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    t   iddr_svdR%   (   R   R   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR3   ¤  s
    	c         C   sÛ   t  j | ƒ } | j \ } } t j |  | ƒ \ } } } } } }	 |	 rQ t ‚ n  | | d | | | d !j | | f d d ƒ}
 | | d | | | d !j | | f d d ƒ} | | d | | d !} |
 | | f S(   s¶  
    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`
    i   R   R   (   R   R   R   R    t   iddp_svdR%   R   (   R   R   R   R   R   t   iUt   iVt   iSR	   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR4   À  s    $	22c   	      C   s²   t  j | ƒ } | j \ } } t | ƒ \ } } t  j | d | d | d d d ƒ} t j |  | | | ƒ \ } } } | | | |  j | | | f d d ƒ} | | | f S(   s¸  
    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`
    i   i   R   R   (   R   R   R   R   t   emptyR    t   iddp_aidR   (	   R   R   R   R   t   n2R	   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR9   ä  s    )!+c         C   s{   t  j | ƒ } | j \ } } t | ƒ \ } } t  j | | | d | d d d ƒ} t j |  | | | ƒ \ } } | S(   se  
    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
    i   R   R   (   R   R   R   R   R8   R    t   idd_estrank(   R   R   R   R   R:   R	   t   raR   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR;     s    )c         C   sZ  t  j | ƒ } | j \ } } t j | ƒ \ } } t  j t t | | ƒ d d | d | d d t | | ƒ d d | d | d ƒ d d ƒ} t j |  | | | ƒ \ } } }	 }
 } } | rÐ t	 ‚ n  | | d | | | d !j
 | | f d d ƒ} | |	 d |	 | | d !j
 | | f d d ƒ} | |
 d |
 | d !} | | | f S(   sÐ  
    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`
    i   i   i   i   i   R   R   (   R   R   R   R    R   R8   t   maxt   mint	   iddp_asvdR%   R   (   R   R   R   R   R:   t   winitR	   R   R5   R6   R7   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR?   !  s    <	*	22c         C   s¦   t  j | d d | t | | ƒ d d d ƒ} t j |  | | | | ƒ \ } } } } | d k rn t ‚ n  | | | |  j | | | f d d ƒ} | | | f S(   së  
    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`
    i   i   R   R   i    (   R   R8   R>   R    t   iddp_ridR%   R   (   R   R   R   R+   R   R   R   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRA   K  s    2'	+c         C   s4   t  j |  | | | ƒ \ } } } | r0 t ‚ n  | S(   sQ  
    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    t   idd_findrankR%   (   R   R   R   R+   R   R<   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRB   q  s    !	c         C   sÆ   t  j |  | | | | ƒ \ } } } } }	 }
 |
 r< t ‚ n  |	 | d | | | d !j | | f d d ƒ} |	 | d | | | d !j | | f d d ƒ} |	 | d | | d !} | | | f S(   sÚ  
    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`
    i   R   R   (   R    t	   iddp_rsvdR%   R   (   R   R   R   R+   R,   R   R5   R6   R7   R	   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRC   “  s    #-	22c         C   sž   t  j |  ƒ }  |  j \ } } t | | | ƒ } t j |  | | ƒ \ } } | | k ru t  j g  d d d d ƒ} n | j | | | f d d ƒ} | | f S(   sg  
    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`
    t   dtypet   float64R   R   (   R   R   R   t	   iddr_aidiR    t   iddr_aidt   arrayR   (   R   R   R   R   R	   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRG   Ã  s    c         C   s   t  j |  | | ƒ S(   sO  
    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    RF   (   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRF   à  s    c   
      C   sÁ   t  j |  ƒ }  |  j \ } } t  j d | d | d | d | d | d d d d ƒ} t | | | ƒ } | | | j *t j |  | | ƒ \ } } } }	 |	 d	 k r´ t ‚ n  | | | f S(
   s±  
    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`
    i   i   i   i   i   id   R   R   i    (	   R   R   R   R8   RF   R   R    t	   iddr_asvdR%   (
   R   R   R   R   R	   t   w_R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRI   ù  s    A!	c         C   sS   t  j |  | | | ƒ \ } } | | | |  j | | | f d d ƒ} | | f S(   sž  
    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`
    R   R   (   R    t   iddr_ridR   (   R   R   R+   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRK     s    +c   	      C   sI   t  j |  | | | | ƒ \ } } } } | d k r< t ‚ n  | | | f S(   s¿  
    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`
    i    (   R    t	   iddr_rsvdR%   (	   R   R   R+   R,   R   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRL   A  s    #'	c         C   s   t  j |  | | ƒ S(   s  
    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    t   idz_frm(   R   R	   R
   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRM   n  s    c         C   s   t  j |  | | | ƒ S(   sí  
    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    t   idz_sfrm(   R   R   R	   R
   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRN   ‹  s    c         C   s   t  j |  ƒ S(   sC  
    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    t   idz_frmi(   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRO   ¨  s    c         C   s   t  j |  | ƒ S(   s•  
    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    t	   idz_sfrmi(   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRP   º  s    c         C   sx   t  j | ƒ } t j |  | ƒ \ } } } | j d } | j j ƒ  | | |  j | | | f d d ƒ} | | | f S(   s¡  
    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`
    i   R   R   (   R   R   R    t   idzp_idR   R   R   R   (   R   R   R   R   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRQ   Ó  s
    4c         C   sr   t  j |  ƒ }  t j |  | ƒ \ } } |  j d } |  j j ƒ  | | |  j | | | f d d ƒ} | | f S(   sT  
    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`
    i   R   R   (   R   R   R    t   idzr_idR   R   R   R   (   R   R   R   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRR   ï  s
    4c         C   sR   t  j |  ƒ }  | j d k r1 t j |  | | ƒ S|  d d … t  j | ƒ f Sd S(   sv  
    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`
    i    N(   R   R   R   R    t   idz_reconidR    (   R!   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRS     s    c         C   s   t  j |  | ƒ S(   s9  
    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    t   idz_reconint(   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRT   !  s    c         C   s"   t  j |  ƒ }  t j |  | | ƒ S(   sQ  
    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    t   idz_copycols(   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRU   3  s    c         C   sL   t  j |  ƒ }  t j |  | | ƒ \ } } } } | r? t ‚ n  | | | f S(   s  
    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    t
   idz_id2svdR%   (   R!   R   R   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRV   M  s
    !	c         C   s%   t  j |  | | | | ƒ \ } } | S(   s  
    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    t	   idz_snorm(   R   R   t   matvecaR,   R-   R.   R/   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRW   p  s    !c         C   s   t  j |  | | | | | | ƒ S(   s/  
    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    t   idz_diffsnorm(   R   R   RX   t   matveca2R,   R2   R-   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRY     s    'c         C   sI   t  j |  ƒ }  t j |  | ƒ \ } } } } | r< t ‚ n  | | | f S(   sž  
    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    t   idzr_svdR%   (   R   R   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR[   ¾  s
    	c         C   sÛ   t  j | ƒ } | j \ } } t j |  | ƒ \ } } } } } }	 |	 rQ t ‚ n  | | d | | | d !j | | f d d ƒ}
 | | d | | | d !j | | f d d ƒ} | | d | | d !} |
 | | f S(   s¹  
    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`
    i   R   R   (   R   R   R   R    t   idzp_svdR%   R   (   R   R   R   R   R   R5   R6   R7   R	   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR\   Ú  s    $	22c   	      C   s¸   t  j | ƒ } | j \ } } t | ƒ \ } } t  j | d | d | d d d d d ƒ} t j |  | | | ƒ \ } } } | | | |  j | | | f d d ƒ} | | | f S(   s»  
    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`
    i   i   RD   t
   complex128R   R   (   R   R   R   RO   R8   R    t   idzp_aidR   (	   R   R   R   R   R:   R	   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR^   þ  s    /!+c         C   s   t  j | ƒ } | j \ } } t | ƒ \ } } t  j | | | d | d d d d d ƒ} t j |  | | | ƒ \ } } | S(   sh  
    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
    i   RD   R]   R   R   (   R   R   R   RO   R8   R    t   idz_estrank(   R   R   R   R   R:   R	   R<   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR_     s    /c         C   sc  t  j | ƒ } | j \ } } t j | ƒ \ } } t  j t t | | ƒ d d | d | d d t | | ƒ d d | d | d ƒ d t  j d d	 ƒ} t j	 |  | | | ƒ \ } } }	 }
 } } | rÙ t
 ‚ n  | | d | | | d !j | | f d d	 ƒ} | |	 d |	 | | d !j | | f d d	 ƒ} | |
 d |
 | d !} | | | f S(
   sÓ  
    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`
    i   i   i   i   i   i   RD   R   R   (   R   R   R   R    RO   R8   R=   R>   R]   t	   idzp_asvdR%   R   (   R   R   R   R   R:   R@   R	   R   R5   R6   R7   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyR`   ;  s    <*	22c         C   s©   t  j | d d | t | | ƒ d d t  j d d ƒ} t j |  | | | | ƒ \ } } } } | rq t ‚ n  | | | |  j | | | f d d ƒ} | | | f S(   sì  
    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`
    i   i   RD   R   R   (   R   R8   R>   R]   R    t   idzp_ridR%   R   (   R   R   R   RX   R   R   R   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRa   e  s    #'	+c         C   s4   t  j |  | | | ƒ \ } } } | r0 t ‚ n  | S(   sR  
    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    t   idz_findrankR%   (   R   R   R   RX   R   R<   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRb     s    !	c         C   sÆ   t  j |  | | | | ƒ \ } } } } }	 }
 |
 r< t ‚ n  |	 | d | | | d !j | | f d d ƒ} |	 | d | | | d !j | | f d d ƒ} |	 | d | | d !} | | | f S(   sÛ  
    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`
    i   R   R   (   R    t	   idzp_rsvdR%   R   (   R   R   R   RX   R,   R   R5   R6   R7   R	   R)   R&   R'   R(   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRc   ¯  s    #-	22c         C   sž   t  j |  ƒ }  |  j \ } } t | | | ƒ } t j |  | | ƒ \ } } | | k ru t  j g  d d d d ƒ} n | j | | | f d d ƒ} | | f S(   sj  
    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`
    RD   R]   R   R   (   R   R   R   t	   idzr_aidiR    t   idzr_aidRH   R   (   R   R   R   R   R	   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRe   ß  s    c         C   s   t  j |  | | ƒ S(   sO  
    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    Rd   (   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRd   ü  s    c   
      C   sÉ   t  j |  ƒ }  |  j \ } } t  j d | d | d | d | d | d d | d d d	 d
 d ƒ} t | | | ƒ } | | | j *t j |  | | ƒ \ } } } }	 |	 r¼ t ‚ n  | | | f S(   s´  
    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`
    i   i   i   i   i   i
   iZ   RD   R]   R   R   (	   R   R   R   R8   Rd   R   R    t	   idzr_asvdR%   (
   R   R   R   R   R	   RJ   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRf     s    :!	c         C   sS   t  j |  | | | ƒ \ } } | | | |  j | | | f d d ƒ} | | f S(   sŸ  
    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`
    R   R   (   R    t   idzr_ridR   (   R   R   RX   R   R   R   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRg   ;  s    +c   	      C   sC   t  j |  | | | | ƒ \ } } } } | r6 t ‚ n  | | | f S(   sÀ  
    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    t	   idzr_rsvdR%   (	   R   R   RX   R,   R   R&   R'   R(   R)   (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyRh   _  s    #'	(>   t   __doc__t   scipy.linalg._interpolativet   linalgt   _interpolativeR    t   numpyR   t   RuntimeErrorR%   R   R   R   R   R   R   R   R   R   R   R"   R#   R$   R*   R0   R3   R4   R9   R;   R?   RA   RB   RC   RG   RF   RI   RK   RL   RM   RN   RO   RP   RQ   RR   RS   RT   RU   RV   RW   RY   R[   R\   R^   R_   R`   Ra   Rb   Rc   Re   Rd   Rf   Rg   Rh   (    (    (    sB   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/_interpolative_backend.pyt   <module>    sp   													# .		$			*	&	"	0			$	$	-										# .		$			*	(	"	0			&	$