ó
Ë½÷Xc           @   s•   d  d l  j j Z d  d l Z d  d l m Z m Z m	 Z	 d  d l
 m Z d  d l Z d  d l m Z m Z m Z d „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   hilbertt   svdvalst   norm(   t   aslinearoperator(   t   assert_t   assert_allcloset   assert_raisesc         C   s   d  S(   N(    (   t   s(    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt   _debug_print&   s    t   TestInterpolativeDecompositionc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         c   s/   x( t  j t  j g D] } |  j | f Vq Wd  S(   N(   t   npt   float64t
   complex128t   check_id(   t   selft   dtype(    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt   test_id,   s    c         C   sÏ  d } d } t  | ƒ j | ƒ } t j | t j ƒ rC | d" } n  t | ƒ } t j j | d t ƒ} y! t j	 | | k  ƒ d d } Wn | } n Xt
 d | ƒ t
 d | ƒ t
 d	 | ƒ d
 } t
 d ƒ t
 d ƒ t
 d ƒ t
 d ƒ t j ƒ  }	 t j | | d t ƒ\ }
 } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | | ƒ \ }
 } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | | ƒ \ }
 } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ | }
 t
 d ƒ t j ƒ  }	 t j | |
 d t ƒ\ } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | |
 ƒ \ } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | |
 ƒ \ } } t j ƒ  |	 } t j | d  d  … | |
  f | | ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t j | |
 d t ƒ\ } } t j | | ƒ } t j | |
 | ƒ } t t j | | d  d  … | |
  f | ƒ ƒ t t j | j | ƒ | | ƒ ƒ t
 d ƒ t
 d ƒ t
 d ƒ t
 d ƒ t j ƒ  }	 t j | | d t ƒ\ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | | ƒ \ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | | ƒ \ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ | }
 t
 d ƒ t j ƒ  }	 t j | |
 d t ƒ\ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | |
 ƒ \ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t
 d ƒ t j ƒ  }	 t j | |
 ƒ \ } } } t j ƒ  |	 } t j | t j t j | ƒ | j j ƒ  ƒ ƒ } t
 | | t j | | | ƒ f ƒ t t j | | | ƒ ƒ t j | |
 d t ƒ\ } } t j | d  d  … | |
  f | | ƒ \ } } } | j t j | ƒ j | j j ƒ  ƒ ƒ } t t j | | | ƒ ƒ t | ƒ } t j | ƒ } t t j | | d d ƒ ƒ | j ƒ  } | d  d  … d f c d 9<t | | ƒ } t j | | ƒ } t t j | | d d ƒ ƒ t j d d d g d d d g d d d g g d | ƒ} x¸ | | g D]ª } t | ƒ } d } t j j | t | d ƒ | ƒ } t j  | | ƒ } t j  | | ƒ } t | | k ƒ t | | d  k ƒ t | | d! k ƒ t | | d! k ƒ qWd  S(#   Ni,  gê-™—q=i   y              ð?t
   compute_uvi    s$   Hilbert matrix dimension:        %8is&   Working precision:               %8.2es$   Rank to working precision:       %8is   %8.2e (s) / %5ss)   -----------------------------------------s   Real ID routiness   Calling iddp_id / idzp_id  ...t   rands   Calling iddp_aid / idzp_aid ...s   Calling iddp_rid / idzp_rid ...s   Calling iddr_id / idzr_id  ...s   Calling iddr_aid / idzr_aid ...s   Calling iddr_rid / idzr_rid ...s   SVD routiness   Calling iddp_svd / idzp_svd ...s    Calling iddp_asvd / idzp_asvd...s    Calling iddp_rsvd / idzp_rsvd...s   Calling iddr_svd / idzr_svd ...s!   Calling iddr_asvd / idzr_asvd ...s!   Calling iddr_rsvd / idzr_rsvd ...gíµ ÷Æ°>g333333ó?R   g•Ö&è.>i   i
   i   y      ð?      ð?(!   R    t   astypeR
   t
   issubdtypet   complexfloatingR   t   linalgt   svdt   Falset   nonzeroR   t   timet   clockt
   pymatrixidt   interp_decompt   reconstruct_matrix_from_idt   allcloseR   t   reconstruct_interp_matrixt   reconstruct_skel_matrixt   dott   diagt   Tt   conjt	   id_to_svdR   t   estimate_spectral_normt   copyt   estimate_spectral_norm_difft   arrayt   matrix_rankR   t   estimate_rank(   R   R   t   nt   epst   At   Lt   St   rankt   fmtt   t0t   kt   idxt   projt   tt   Bt   Pt   Ut   Vt   Upt   Spt   VpR   t
   norm_2_estt   Mt   MLt   rank_tolt   rank_npt   rank_estt
   rank_est_2(    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyR   0   s   !




!)#
)#
)#
)#
)#
)#-"



!0#
0#
0#
!0#
0#
0#2*9"c         C   sï   t  j d ƒ t t j t  j d ƒ d d g d ƒ ƒ t  j d ƒ t  j d ƒ } t t j | d d g d ƒ ƒ t j j d ƒ t  j ƒ  t  j d ƒ } t j j d ƒ t  j t j j d	 ƒ ƒ t  j d ƒ } t | | ƒ t | | ƒ d  S(
   Nt   defaulti   g#Š$•ì?gƒ<Páç£ä?g-Cëâ6?iÒ  gdb©äRè?gä2@å±?i7   (   R   t   seedR   R
   R   R   t   randomR   (   R   t   x1t   x2t   x3(    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt	   test_randæ   s    (
c         C   s8   t  d ƒ j t j ƒ } t t t j | d d t ƒd  S(   Ni   gíµ ÷Æ°>R   (	   R    R   R
   t   float32R   t
   ValueErrorR   R   R   (   R   R/   (    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt   test_badcallù   s    c         C   s6   t  j d ƒ } t t ƒ  t j | d ƒ Wd  QXd  S(   Ni   i   (   i   i   (   R
   t   onesR   RO   R   R   (   R   t   a(    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt   test_rank_too_largeý   s    (   t   __name__t
   __module__R   R   RM   RP   RS   (    (    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyR	   +   s
   		¶		(   t   scipy.linalg.interpolativeR   t   interpolativeR   t   numpyR
   t   scipy.linalgR    R   R   t   scipy.sparse.linalgR   R   t   numpy.testingR   R   R   R   t   objectR	   (    (    (    sD   /tmp/pip-build-7oUkmx/scipy/scipy/linalg/tests/test_interpolative.pyt   <module>   s   	