B
    `*                 @   s   d dl m  mZ d dlZd dlmZmZm	Z	 d dl
mZ d dl mZ d dlZd dlZd dlmZmZ d dlmZ dd ZG d	d
 d
eZdS )    N)hilbertsvdvalsnorm)aslinearoperator)interp_decomp)assert_assert_allclose)raisesc             C   s   d S )N )sr
   r
   T/home/dcms/DCMS/lib/python3.7/site-packages/scipy/linalg/tests/test_interpolative.py_debug_print)   s    r   c               @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )TestInterpolativeDecompositionc             C   s$   xt jt jgD ]}| | qW d S )N)npfloat64Z
complex128check_id)selfdtyper
   r
   r   test_id/   s    z&TestInterpolativeDecomposition.test_idc          	   C   s  d}d}t ||}t|tjr,|d }t|}tjj|dd}yt||k d d }W n t	k
rv   |}Y nX t
d|  t
d|  t
d	|  d
}t
d t
d t
d t
d t }	tj||dd\}
}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| t
d t }	t||\}
}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| t
d t }	t||\}
}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| |}
t
d t }	tj||
dd\}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| t
d t }	t||
\}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| t
d t }	t||
\}}t |	 }t|d d |d |
 f ||}t
||t|||f  tt||| tj||
dd\}}t||}t||
|}tt||d d |d |
 f | tt|||| t
d t
d t
d t
d t }	tj||dd\}}}t |	 }t|tt||j }t
||t|||f  tt||| t
d t }	t||\}}}t |	 }t|tt||j }t
||t|||f  tt||| t
d t }	t||\}}}t |	 }t|tt||j }t
||t|||f  tt||| |}
t
d t }	tj||
dd\}}}t |	 }t|tt||j }t
||t|||f  tt||| t
d t }	t||
\}}}t |	 }t|tt||j }t
||t|||f  tt||| t
d t }	t||
\}}}t |	 }t|tt||j }t
||t|||f  tt||| tj||
dd\}}t|d d |d |
 f ||\}}}|t||j }tt||| t|}t|}tt||d d | }|d d df  d9  < t|| }t||}tt||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|t|d | }t||}t||}t||k t||d! k t||d" k t||d" k q"W d S )#Ni,  g-q=y      ?      ?F)Z
compute_uvr   z$Hilbert matrix dimension:        %8iz&Working precision:               %8.2ez$Rank to working precision:       %8iz%8.2e (s) / %5sz)-----------------------------------------zReal ID routineszCalling iddp_id / idzp_id  ...)randzCalling iddp_aid / idzp_aid ...zCalling iddp_rid / idzp_rid ...zCalling iddr_id / idzr_id  ...zCalling iddr_aid / idzr_aid ...zCalling iddr_rid / idzr_rid ...zSVD routineszCalling iddp_svd / idzp_svd ...z Calling iddp_asvd / idzp_asvd...z Calling iddp_rsvd / idzp_rsvd...zCalling iddr_svd / idzr_svd ...z!Calling iddr_asvd / idzr_asvd ...z!Calling iddr_rsvd / idzr_rsvd ...gư>g333333?   )r   g&.>   
      ) r   astyper   Z
issubdtypeZcomplexfloatingr   linalgsvdZnonzero
IndexErrorr   time
pymatrixidr   Zreconstruct_matrix_from_idallcloser   reconstruct_interp_matrixreconstruct_skel_matrixdotZdiagTZconjZ	id_to_svdr   Zestimate_spectral_normcopyZestimate_spectral_norm_diffarrayZmatrix_rankr   Zestimate_rank)r   r   nepsALSZrankfmtt0kidxprojtBPUVZUpZSpZVpr   Z
norm_2_estMZMLZrank_tolZrank_npZrank_estZ
rank_est_2r
   r
   r   r   3   s   
""""""&      (
&z'TestInterpolativeDecomposition.check_idc             C   s   t d ttt dddgd t d t d}tt|ddgd tjd t   t d}tjd t tjd	 t d}t|| t|| d S )
Ndefaultr   g#$?g<P?g-C6?i  gdbR?g2@吱?7   )r   seedr   r   r    r   randomr   )r   x1Zx2Zx3r
   r
   r   	test_rand   s    





z(TestInterpolativeDecomposition.test_randc             C   s(   t dtj}tttj|ddd d S )N   gư>F)r   )r   r   r   float32assert_raises
ValueErrorr   r   )r   r)   r
   r
   r   test_badcall   s    z+TestInterpolativeDecomposition.test_badcallc          	   C   s.   t d}tt t|d W d Q R X d S )N)r      r   )r   Zonesr?   r@   r   r   )r   ar
   r
   r   test_rank_too_large   s    

z2TestInterpolativeDecomposition.test_rank_too_largec             C   s   d}t jdd}t||\}}}t||jd k t||}t|||}t	||
| t||\}}t||}t|||}t	||
| d S )Ng-q=      r   )r   r:   r   r   r   r   shaper!   r"   r   r#   )r   r(   r)   r.   r/   r0   r3   r2   r
   r
   r   test_full_rank  s    z-TestInterpolativeDecomposition.test_full_rankc       	      C   s   t jt jg}ddg}ddg}xt|||D ]\}}}t jddddddgddddddgddddddgddddddgddddddgg|dd}| }t|j||d	 t	t 
|| q,W d S )
NTFr   g?r   C)r   order)r   )r   Zfloat_Zcomplex_	itertoolsproductr&   r%   r   r$   r   Zarray_equal)	r   ZdtypesZrandsZepssr   r(   r   r)   r2   r
   r
   r   test_bug_9793  s    
z,TestInterpolativeDecomposition.test_bug_9793N)
__name__
__module____qualname__r   r   r<   rA   rD   rH   rN   r
   r
   r
   r   r   .   s    7r   )Zscipy.linalg.interpolativer   Zinterpolativer   numpyr   Zscipy.linalgr   r   r   Zscipy.sparse.linalgr   r   r   rL   Znumpy.testingr   r   Zpytestr	   r?   r   objectr   r
   r
   r
   r   <module>   s   