B
    `h                 @   s  d dl Z d dlZd dlmZmZmZmZmZmZ d dl	m
Z
mZmZmZ d dl mZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d dl*m+Z+ d	d
 Z,G dd de-Z.G dd de-Z/G dd de-Z0G dd de-Z1G dd de-Z2G dd de-Z3G dd de-Z4G dd de-Z5G dd de-Z6G dd dZ7G dd  d Z8G d!d" d"e-Z9G d#d$ d$e-Z:G d%d& d&e-Z;G d'd( d(e-Z<d)d* Z=d+d, Z>d-d. Z?d/d0 Z@G d1d2 d2ZAdS )3    N)arangeaddarrayeyecopysqrt)assert_equalassert_array_equalassert_array_almost_equalassert_allclose)raises)fft)comb)toeplitzhankel	circulanthadamardlesliedft	companiontritriutrilkron
block_diaghelmerthilbert
invhilbertpascal	invpascalfiedlerfiedler_companioneigvalsconvolution_matrix)condc             C   s   t | }t||}|S )N)r   r   outer)ndata r(   W/home/dcms/DCMS/lib/python3.7/site-packages/scipy/linalg/tests/test_special_matrices.pyget_mat   s    r*   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestTric          
   C   s~   t tdtddddgddddgddddgddddgg t tdddtddddgddddgddddgddddggd d S )N      r   f)dtype)r   r   r   )selfr(   r(   r)   
test_basic   s    



zTestTri.test_basicc          
   C   s   t tdddtddddgddddgddddgddddgg t tdddtddddgddddgddddgddddgg d S )Nr,   r-   )kr   )r   r   r   )r0   r(   r(   r)   	test_diag$   s    



zTestTri.test_diagc          	   C   sj   t tddtdddgdddgdddgdddgg t tddtddddgddddgddddgg d S )Nr,      r-   r   )r   r   r   )r0   r(   r(   r)   test_2d.   s    
zTestTri.test_2dc          	   C   sr   t tddddtddddgddddgddddgg t tddddtdddgdddgdddgdddgg d S )Nr5   r,      )r2   r-   r   )r   r   r   )r0   r(   r(   r)   test_diag2d7   s    
zTestTri.test_diag2dN)__name__
__module____qualname__r1   r4   r6   r9   r(   r(   r(   r)   r+      s   

	r+   c               @   s   e Zd Zdd Zdd ZdS )TestTrilc             C   sb   dt d d}| }x4tdD ](}x"t|d dD ]}d|||f< q8W q$W tt|| d S )Nd      lr-   r   )r*   astyper   ranger   r   )r0   abr2   r@   r(   r(   r)   r1   B   s    zTestTril.test_basicc             C   s   dt d d}| }x4tdD ](}x"t|d dD ]}d|||f< q8W q$W tt|dd| | }x<tdD ]0}x*tt|d dfdD ]}d|||f< qW qtW tt|d	d| d S )
Nr>   r?   r.   r5   r   r7   )r2   r-   r8   )r*   rA   r   rB   r   r   max)r0   rC   rD   r2   r@   r(   r(   r)   r4   J   s    zTestTril.test_diagN)r:   r;   r<   r1   r4   r(   r(   r(   r)   r=   A   s   r=   c               @   s   e Zd Zdd Zdd ZdS )TestTriuc             C   sb   dt d d}| }x4tdD ](}x"t|d dD ]}d|||f< q8W q$W tt|| d S )Nr>   r?   r@   r-   r   )r*   rA   r   rB   r   r   )r0   rC   rD   r2   r@   r(   r(   r)   r1   Y   s    zTestTriu.test_basicc             C   s   dt d d}| }x<tdD ]0}x*tt|d dfdD ]}d|||f< q@W q$W tt|dd| | }x4tdD ](}x"t|d dD ]}d|||f< qW q|W tt|d	d| d S )
Nr>   r?   r.   r-   r   r7   )r2   r5   r8   )r*   rA   r   rB   rE   r   r   )r0   rC   rD   r2   r@   r(   r(   r)   r4   a   s    zTestTriu.test_diagN)r:   r;   r<   r1   r4   r(   r(   r(   r)   rF   X   s   rF   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 )TestToeplitzc             C   sl   t dddg}t|dddgdddgdddgg t dddgdddg}t|dddgdddgdddgg d S )Nr-   r7   r5   r,   r?   )r   r	   )r0   yr(   r(   r)   r1   q   s    "zTestToeplitz.test_basicc             C   sj   dt d d }t|}t|}t|| |d d df }t|| t|ddd f |dd    d S )Ng      ?g      @y      ?      ?r   r-   )r   r   r   r	   Zconj)r0   r'   xtZcol0r(   r(   r)   test_complex_01w   s    

zTestToeplitz.test_complex_01c             C   s2   t d}t|dgg t dd}t|dgg dS )z*Scalar arguments still produce a 2D array.
      N)r   r	   )r0   rJ   r(   r(   r)   test_scalar_00   s    
zTestToeplitz.test_scalar_00c             C   s2   t dddg}t|d}t|dgdgdgg d S )Nr-   r7   r5   )r   r   r	   )r0   crJ   r(   r(   r)   test_scalar_01   s    
zTestToeplitz.test_scalar_01c             C   s6   t dddg}t|t d}t|dgdgdgg d S )Nr-   r7   r5   )r   r   r	   )r0   rO   rJ   r(   r(   r)   test_scalar_02   s    zTestToeplitz.test_scalar_02c             C   s8   t dddg}t|t dg}t|dgdgdgg d S )Nr-   r7   r5   )r   r   r	   )r0   rO   rJ   r(   r(   r)   test_scalar_03   s    zTestToeplitz.test_scalar_03c             C   s.   t dddg}td|}t|dddgg d S )NrL   r7   r5   r-   )r   r   r	   )r0   rrJ   r(   r(   r)   test_scalar_04   s    
zTestToeplitz.test_scalar_04N)
r:   r;   r<   r1   rK   rN   rP   rQ   rR   rT   r(   r(   r(   r)   rG   o   s   rG   c               @   s   e Zd Zdd ZdS )
TestHankelc             C   sl   t dddg}t|dddgdddgdddgg t dddgdddg}t|dddgdddgdddgg d S )Nr-   r7   r5   r   r,   r?   )r   r	   )r0   rH   r(   r(   r)   r1      s    "zTestHankel.test_basicN)r:   r;   r<   r1   r(   r(   r(   r)   rU      s   rU   c               @   s   e Zd Zdd ZdS )TestCirculantc             C   s4   t dddg}t|dddgdddgdddgg d S )Nr-   r7   r5   )r   r	   )r0   rH   r(   r(   r)   r1      s    zTestCirculant.test_basicN)r:   r;   r<   r1   r(   r(   r(   r)   rV      s   rV   c               @   s   e Zd Zdd ZdS )TestHadamardc          	   C   s   t d}t|dgg t dtd}t|ddgddgg t d}t|ddddgddddgddddgddddgg ttt d ttt d	 d S )
Nr-   r7   )r/   g      ?g      r,   r3   r   r?   )r   r	   floatassert_raises
ValueError)r0   rH   r(   r(   r)   r1      s    

zTestHadamard.test_basicN)r:   r;   r<   r1   r(   r(   r(   r)   rW      s   rW   c               @   s   e Zd Zdd Zdd ZdS )
TestLesliec             C   sj   t ttddgddggdddg t ttdddgddgddgg t ttddgddg t ttdgg  d S )Nr-   r7   r5   r,   r?   )rY   rZ   r   )r0   r(   r(   r)   test_bad_shapes   s      zTestLeslie.test_bad_shapesc             C   sB   t dddgddg}tdddgdd	d	gd	dd	gg}t|| d S )
Nr-   r7   r5   g      ?g      ?g      ?g       @g      @g        )r   r   r	   )r0   rC   expectedr(   r(   r)   r1      s
    
zTestLeslie.test_basicN)r:   r;   r<   r\   r1   r(   r(   r(   r)   r[      s   r[   c               @   s   e Zd Zdd Zdd ZdS )TestCompanionc             C   sH   t ttddgddgg t ttdddg t ttdg t ttg  d S )Nr-   r7   r   r,   r?   )rY   rZ   r   )r0   r(   r(   r)   r\      s    zTestCompanion.test_bad_shapesc             C   s\   t dddg}tddgddgg}t|| t dd	d
g}tdd	gddgg}t|| d S )Nr-   r7   r5   g       g      g      ?g        g       @g      @g      $g      )r   r   r	   )r0   rO   r]   r(   r(   r)   r1      s    
zTestCompanion.test_basicN)r:   r;   r<   r\   r1   r(   r(   r(   r)   r^      s   r^   c               @   sL   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d Z
dS )TestBlockDiagc             C   s   t tdddgddgddggdddgg}t|dddddddgdddddddgdddddddgdddddddgdddddddgdddddddgg d S )Nr7   r-   r5   r,   r?      r   )r   r   r	   )r0   rI   r(   r(   r)   r1      s    *zTestBlockDiag.test_basicc             C   s4   t dgg}t|jt t dgg}t|jt d S )Ng      ?T)r   r   r/   rX   bool)r0   rI   r(   r(   r)   
test_dtype   s    zTestBlockDiag.test_dtypec             C   s6   t dggdgg}tddgddgg}t|| d S )Nr-   y              ?r   )r   npr   r	   )r0   actualZdesiredr(   r(   r)   test_mixed_dtypes   s    zTestBlockDiag.test_mixed_dtypesc             C   sN   t d}t|jd t|dgg t ddgd}t|dddgdddgg d S )Nr-   )r-   r-   r7   r5   r,   r   )r   r   shaper	   )r0   rC   r(   r(   r)   test_scalar_and_1d_args   s
    z%TestBlockDiag.test_scalar_and_1d_argsc             C   s   t ttdggg d S )Nr-   )rY   rZ   r   )r0   r(   r(   r)   test_bad_arg  s    zTestBlockDiag.test_bad_argc             C   s"   t  }t|jd t|jd d S )Nr7   r   )r   r   ndimnbytes)r0   rC   r(   r(   r)   test_no_args  s    zTestBlockDiag.test_no_argsc             C   st   t ddgddggg ddgddgddgg}t|ddddgddddgddddgddddgddddgddddgg d S )	Nr-   r   r7   r5   r,   r?   r`      )r   r	   )r0   rC   r(   r(   r)   test_empty_matrix_arg  s    



z#TestBlockDiag.test_empty_matrix_argc             C   s   t ddgddggg gddgddgddggtjddgd	d
}t|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ddddddgg d S )Nr-   r   r7   r5   r,   r?   r`   rl   int32)r/   )r   rc   zerosr	   )r0   rC   r(   r(   r)   test_zerosized_matrix_arg  s    z'TestBlockDiag.test_zerosized_matrix_argN)r:   r;   r<   r1   rb   re   rg   rh   rk   rm   rp   r(   r(   r(   r)   r_      s   	r_   c               @   s   e Zd Zdd ZdS )TestKronc          
   C   s   t tddgddggtdddgg}t|tddddddgddddddgg tddgddgg}tdgdgg}t ||}tddgddgd	d
gddgg}t|| d S )Nr-   r7   r5   r,   rL      rM         (   !   ,   )r   r   r	   )r0   rC   m1m2r]   r(   r(   r)   r1   ,  s    &
zTestKron.test_basicN)r:   r;   r<   r1   r(   r(   r(   r)   rq   *  s   rq   c               @   s   e Zd Zdd Zdd ZdS )TestHelmertc             C   sZ   xTt ddD ]F}t|dd}t|}t||j|dd t|j||dd qW d S )Nr-   rl   T)fullg-q=)atol)rB   r   rc   r   r   dotT)r0   r&   HZIdr(   r(   r)   test_orthogonality>  s
    
zTestHelmert.test_orthogonalityc             C   s   xt ddD ]}t|dd}t|}xt|dd d d f j|jfD ]T}t|t||fd|  }t||j| t|j|t|d dd qBW qW d S )Nr7   rl   T)r{   r-   g-q=)r|   )rB   r   r~   rc   r   r{   r   r}   )r0   r&   ZH_fullZ	H_partialUCr(   r(   r)   test_subspaceE  s    "zTestHelmert.test_subspaceN)r:   r;   r<   r   r   r(   r(   r(   r)   rz   <  s   rz   c               @   s   e Zd Zdd ZdS )TestHilbertc             C   sX   t dddgdddgdddgg}ttd| ttddgg td}t|jd	 d S )
Ng      ?g      ?gUUUUUU?g      ?g?r5   r-   r   )r   r   )r   r
   r   r	   r   rf   )r0   h3Zh0r(   r(   r)   r1   Q  s    
zTestHilbert.test_basicN)r:   r;   r<   r1   r(   r(   r(   r)   r   O  s   r   c               @   s   e Zd Zdd Zdd ZdS )TestInvHilbertc          "   C   s  t dgg}ttddd| ttd| t ddgddgg}ttddd| ttd| t dd	d
gd	ddgd
ddgg}ttddd| ttd| t ddddgddddgddddgddddgg}ttddd| ttd| t dddddgdddd d!gddd"d#d$gdd d#d%d&gdd!d$d&d'gg}ttd(dd| ttd(| t d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9gd*d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIgd+d;dJdKdLdMdNdOdPdQdRdSdTdUdVdWdXgd,d<dKdYdZd[d\d]d^d_d`dadbdcdddedfgd-d=dLdZdgdhdidjdkdldmdndodpdqdrdsgd.d>dMd[dhdtdudvdwdxdydzd{d|d}d~dgd/d?dNd\didudddddddddddgd0d@dOd]djdvdddddddddddgd1dAdPd^dkdwdddddddddddgd2dBdQd_dldxdddddddddddgd3dCdRd`dmdydddddddddddgd4dDdSdadndzdddddddddddgd5dEdTdbdod{dddddddddddgd6dFdUdcdpd|dddddddddddgd7dGdVdddqd}dddddddddddgd8dHdWdedrd~dddddddddddgd9dIdXdfdsddddddddddddgg}ttddd| ttd|tddč d S )Nr-   T)exactr,   i   r7   	   irt      iL   r5      i   iti  iti  iP  ii
     ii  iiv  i  i,i i  ii6 i4i|  i  ixiD  r?   i!  ip]i) i2@il%lPAy l   g
 lP= l   /w$l:R
l   xDulm7l   O@l>/,	l   t:l`j! l   < i y ǐl    r	 l@u\ l    Dbl`Hhl    Pz6 l }% l    l&W lc( l    hx l4z l    d~I
 l8wl8Z l    @u8! l`6al   @iLU l RKl   8H,!l`g`36 l   g0 l *?*^B l   ;t$ l}|l   @bskl C{'"il   `>9&%lmq>l   3CM@;l 86`T l   Pm;,
 l    pM6=l 0	 l    nC l YJVrl     <_l L^Vl    R8l uxbl    eH  lEIBQxl    HvYPl x(6$l     7	l >u1l   Dcf$l l@QM l   8ItlHv0"Qsl   N
:v l@ s/V| l   #& lp-N$v  l   5  l@,@VK-
 l   8_DdYI l B _, l   qkl    O9x&lY)lx l    pd lgsxmU l    D0FZD lK|y#l_y l    xbr l&V% l    lny?Cce l@M=p- l    @@|%6 lh\bC l   @/.L l BAyks'9 l   | l
LjYl   iYn\"%l #5Eyl    X(l@T'3?l   @,3l Hx+/S l   pO3^#
 l    @+aF}lcJ{
;_l    P8Xy8Qo&l BIhNl    `@
oc#ldLq,Ol    pFYRal Ii9Ml     R/$Ll@<8zG 0 l   $9@t)l4l   07$$Tv0l l7>?l   "`-:M=l (^@b)l   6a;:BMlb-Kx?|#l   Z$M~ll l    l>cTAl@8HV-:vl    h{d*U lzaC<C l    dYwMfl RyUC#h.l    @)]loz+%l   @e4jT l GU
 l   `i
t,@ l Y,ch8 l   E@3I3Tl X=&@El   ~Sil    p}v l`Xfz~A`si l    86Jpsbv l $JY'ipl     tk(0lu1@<fl   w2T.g] l %\n l    PYHull ZR@
Rl   LwJl    L#(S.,# l2F=EgJl    @}ll`L\kl   @i7Qt0"l 8B3\f	l   p1&S,l     @Y?l }xl]R l   /"}+
    g-q=)rtol)r   r	   r   r
   r   rA   rX   )r0   Zinvh1Zinvh2Zinvh3Zinvh4Zinvh5Zinvh17r(   r(   r)   r1   _  s(   




zTestInvHilbert.test_basicc             C   sR   xLt ddD ]>}t|}t|}t|}t||t|d| d| d qW d S )Nr-   rL   gV瞯<)r|   r   )rB   r   r   r$   r   r}   r   )r0   r&   rC   rD   rO   r(   r(   r)   test_inverse  s
    zTestInvHilbert.test_inverseN)r:   r;   r<   r1   r   r(   r(   r(   r)   r   ]  s    r   c               @   s  e Zd ZdedggedggfdeddgddggeddgddggfdedddgdddgdddggedddgdddgdddggfdeddddgddddgddddgddddggeddddgddddgddddgddddggfgZd	d
 Zdd Zdd Zdd ZdS )
TestPascalr-   r7   r   r5   r`   r,   rL   rM   c             C   st   t t|| t t|dd| t t|dd|j tt|dd| tt|ddd| tt|ddd|j d S )Nlower)kindupperF)r   )r   r   )r	   r   r~   r
   )r0   r&   symlowr(   r(   r)   
check_case  s    zTestPascal.check_casec             C   s(   x"| j D ]\}}}| ||| qW d S )N)casesr   )r0   r&   r   r   r(   r(   r)   
test_cases%  s    zTestPascal.test_casesc             C   s$   t d}t|d tdddd d S )N2   )r3   r3   b   1   T)r   )r   r   r   )r0   pr(   r(   r)   test_big)  s    zTestPascal.test_bigc             C   sX   t d}td|dd |dddd t d}td|dd |dddd d S )	N"   r7   r3   r8   zn = 34)err_msg#   zn = 35)r   r   item)r0   r   r(   r(   r)   test_threshold-  s    "zTestPascal.test_thresholdN)	r:   r;   r<   r   r   r   r   r   r   r(   r(   r(   r)   r     s.   






r   c              C   s   dd } dddg}dddd	g}x4|D ],}x&|D ]}xd
D ]}| ||| q8W q.W q$W ddddg}x&|D ]}x|D ]}| ||d qpW qfW d S )Nc             S   sR   t | ||d}t| ||d}|t|t}t|t| d| ||f d d S )N)r   r   zn=%d  kind=%r exact=%r)r   )r   r   rA   objectr}   r	   r   )r&   r   r   ipr   er(   r(   r)   check_invpascal:  s
    z'test_invpascal.<locals>.check_invpascalZ	symmetricr   r   r-   r7   r?      )TF   r   r   r   Tr(   )r   kindsnsr&   r   r   r(   r(   r)   test_invpascal8  s    





r   c           	   C   s   t d} tddgddgg}t| | t ddd} t| |d  t ddd} t| |td  tdd	dd
dddd	g}t d} | |}t|}t|| d S )Nr7   g      ?g      r&   )Zscaleg       @Zsqrtnr   r-   r5   r,   r?      )r   r   r
   r   r}   r   )mr]   rI   ZmxZfxr(   r(   r)   test_dftU  s    

r   c              C   s   t g } t| jd t dg} t| tdgg t tdd} t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d	dddddgg}t| | d S )
Nr   g     ^@g        r-   rl   r7   r5   r,   r?   )r    r   sizer	   rc   r   r   )r.   Zdesr(   r(   r)   test_fiedlere  s    
r   c           	   C   s   t g } t| jd t dg} t| jd t ddg} t| tdgg t dddg} t| tdddg tt	 t dddg W d Q R X t dd	d
ddg} tt
| tddddg d S )Nr   g      ?g       @g       g-q=g      @r-   r7   g      0g     U@g      fg     @Z@g      @g      @)r!   r   r   r	   rc   r   r
   r   rY   rZ   r"   )Zfcr(   r(   r)   test_fiedler_companiont  s    

r   c            
   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	j
dddge	j
ddddge	j
ddddge	j
dddddgdd ZdS )TestConvolutionMatrixzL
    Test convolution_matrix vs. numpy.convolve for various parameters.
    c             C   s,   t dd|}|r(|dt dd|  }|S )z/Make a complex or real test vector of length n.g      g@y              ?g      g@)rc   Zlinspace)r0   r&   cpxrI   r(   r(   r)   create_vector  s    z#TestConvolutionMatrix.create_vectorc          	   C   s.   t jtdd tdddgd W d Q R X d S )Nzn must be a positive integer)matchr-   r7   r5   r   )pytestr   rZ   r#   )r0   r(   r(   r)   
test_bad_n  s    z TestConvolutionMatrix.test_bad_nc          	   C   s(   t jtdd tdd W d Q R X d S )Nzone-dimensional)r   r-   r,   )r   r   rZ   r#   )r0   r(   r(   r)   test_bad_first_arg  s    z(TestConvolutionMatrix.test_bad_first_argc          	   C   s(   t jtdd tg d W d Q R X d S )Nzlen\(a\))r   r,   )r   r   rZ   r#   )r0   r(   r(   r)   test_empty_first_arg  s    z*TestConvolutionMatrix.test_empty_first_argc          	   C   s,   t jtdd tdddd W d Q R X d S )Nzmode.*must be one of)r   )r-   r-   r,   zinvalid argument)mode)r   r   rZ   r#   )r0   r(   r(   r)   test_bad_mode  s    z#TestConvolutionMatrix.test_bad_moder   FTnar-   r7   r   nvr   Nr{   ZvalidZsamec       
      C   sh   |  ||}|  ||}|d kr8t||}t||}nt|||}t|||}|| }	t||	 d S )N)r   rc   Zconvolver#   r
   )
r0   r   r   r   r   rC   vy1Ay2r(   r(   r)   test_against_numpy_convolve  s    z1TestConvolutionMatrix.test_against_numpy_convolve)r:   r;   r<   __doc__r   r   r   r   r   r   markZparametrizer   r(   r(   r(   r)   r     s   r   )Br   numpyrc   r   r   r   r   r   r   Znumpy.testingr   r	   r
   r   r   rY   Z	scipy.fftr   Zscipy.specialr   Zscipy.linalgr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   Znumpy.linalgr$   r*   r   r+   r=   rF   rG   rU   rV   rW   r[   r^   r_   rq   rz   r   r   r   r   r   r   r   r   r(   r(   r(   r)   <module>   s<    \(/D )3