ó
Ê½÷Xc           @` s'  d  d l  m Z m Z m Z d  d l Z d  d l m Z m Z m	 Z	 m
 Z
 d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l m Z d Z e j e ƒ Z e j j Z e j j Z xe e d ƒ D]W Z e d	 e ƒ Z e e j Z e e e j d
 7Z e e d	 e ƒ e d	 e ƒ 7Z qÌ We d	 e ƒ Z d Z e Z  d Z" d „  Z# d „  Z$ d „  Z% d „  Z& e' d k r#e j j( e e ƒ Z) e ƒ  Z* e e e d e  d e d e d e" ƒZ+ e+ d  Z, e+ d Z- e+ d Z. e+ d Z/ e+ d Z0 e j1 e e j ƒ Z2 e2 d k rd Z3 n d Z3 e4 d ƒ e4 d e3 ƒ e4 d e e/ f ƒ e4 d e ƒ  e* ƒ e4 d  e0 e- e. f ƒ e4 d! ƒ e4 d" e e, ƒ e e e, e ƒ e e j e e, e ƒ f ƒ e4 d# ƒ e4 d$ e e) ƒ e e e) e ƒ f ƒ e4 d% ƒ e4 d& e e) e, ƒ ƒ e4 d% ƒ n  d S('   i    (   t   divisiont   print_functiont   absolute_importN(   t   assert_t   assert_equalt   assert_almost_equalt   assert_array_almost_equal(   t   xrange(   t   lsqr(   t   timei#   i   t   sizeg      à?g»½×Ùß|Û=c          C` sd   t  j j t t ƒ }  t t t d t d t d t d t ƒ} | d } t	 t
 |  | ƒ d k  ƒ d  S(   Nt   showt   atolt   btolt   iter_limi    gñhãˆµøä>(   t   npt   linalgt   solvet   Gt   bR   R   t   tolt   maxitR   t   norm(   t   svxt   Xt   xo(    (    sI   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/linalg/isolve/tests/test_lsqr.pyt
   test_basic    s    '
c          C` s†   t  j d d g ƒ }  t  j d d g ƒ } t  j d d g ƒ } t j j | |  | f f d d ƒ} t  j d g ƒ } t | | ƒ d  S(   Ni    i   iÿÿÿÿt   shapei   i   (   i   i   (   R   t   arrayt   scipyt   sparset
   coo_matrixt   asarrayR   (   t   rowt   colt   valt   AR   (    (    sI   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/linalg/isolve/tests/test_lsqr.pyt   test_gh_2466'   s    $c    
   
   C` s  d }  t  j j |  |  ƒ } | j ƒ  } t j d d ƒ Ó xË t d ƒ D]½ } t j j | d ƒ } | j	 |  ƒ } d | | d k <| | d  d  … t j
 f } t | | d t ƒ} t | d d ƒ | d } t | | ƒ t j j | | ƒ j ƒ  }	 t | |	 ƒ qG WWd  QXd  S(	   Ni
   t   invalidt   raisei   gñhãˆµøä>i    R   i   (   R   R   t   eyet   toarrayR   t   errstatet   ranget   randomt   RandomStatet   randt   newaxisR   R   R   R   R   R   t   ravel(
   t   nt   A_sparset   A_denset   seedt   rngt   betaR   t   outputt   solutiont   reference_solution(    (    sI   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/linalg/isolve/tests/test_lsqr.pyt   test_well_conditioned_problems0   s    
c          C` s¬   t  j d d g g ƒ }  d } t |  | ƒ d } t t |  j | ƒ | ƒ d ƒ t  j d ƒ }  t  j d ƒ } t |  | ƒ d } t t |  j | ƒ | j ƒ  ƒ d ƒ d  S(   Ng      ð?g       @g      @i    i
   i   (   i
   i   (	   R   R   R   R   R   t   dotR(   t   onesR0   (   R$   R   t   x(    (    sI   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/linalg/isolve/tests/test_lsqr.pyt   test_b_shapesN   s     t   __main__R   R   R   R   i   i   i   i   g›+¡†›„=t   Not   Yest   LSQRs   Is linear operator symmetric? s   n: %3g  iterations:   %3gs   Norms computed in %.2fs by LSQRs*    ||x||  %9.4e  ||r|| %9.4e  ||Ar||  %9.4e s!   Residual norms computed directly:s)    ||x||  %9.4e  ||r|| %9.4e  ||Ar||  %9.4es   Direct solution norms:s    ||x||  %9.4e  ||r|| %9.4e t    s"    || x_{direct} - x_{LSQR}|| %9.4e (5   t
   __future__R    R   R   t   numpyR   t   numpy.testingR   R   R   R   t   scipy._lib.sixR   t   scipy.sparseR   t   scipy.sparse.linalgR   R	   R1   R(   R   R,   t   normalR   R   t   jjt   ggt   Tt   hhR   R   t   FalseR   t   NoneR   R   R%   R:   R>   t   __name__R   R   t   ticR   R   t   phiot   psiot   kt   chiot   amaxt   mgt   symt   print(    (    (    sI   /tmp/pip-build-7oUkmx/scipy/scipy/sparse/linalg/isolve/tests/test_lsqr.pyt   <module>   sf   "$						'




	

 
(
