o
    ha                     @   s  d dl Z d dlZd dl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% d dl&m'Z' G d	d
 d
Z(G dd dZ)G dd dZ*G dd dZ+G dd dZ,G dd dZ-G dd dZ.G dd dZ/G dd dZ0G dd dZ1G dd dZ2G dd  d Z3d!d" Z4d#d$ Z5d%d& Z6d'd( Z7G d)d* d*Z8e j9j:e j9;d+e j9<d,ed-fed-fe%d.fe"d-fe#d-feed/ffeed/ffgd0d1 Z=dS )2    N)arange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kron
block_diaghelmerthilbert
invhilbertpascal	invpascalfiedlerfiedler_companioneigvalsconvolution_matrix)condc                   @   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   sZ   t g d}t|g dg dg dg t g dg d}t|g dg dg dg d S )N         )r$   r#   r$   r%   r$   r#   )r#         )r$   r#   r'   r   r   selfy r-   \/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/linalg/tests/test_special_matrices.py
test_basic       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 )N      ?      @y      ?      ?r   r#   )r   r   r   r   conj)r+   dataxtcol0r-   r-   r.   test_complex_01   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.
      Nr)   )r+   r6   r-   r-   r.   test_scalar_00%   s   
zTestToeplitz.test_scalar_00c                 C   s0   t g d}t|d}t|dgdgdgg d S Nr"   r#   r$   r%   r   r   r   r+   cr6   r-   r-   r.   test_scalar_01,   s   
zTestToeplitz.test_scalar_01c                 C   s4   t g d}t|t d}t|dgdgdgg d S r<   r=   r>   r-   r-   r.   test_scalar_021   s   zTestToeplitz.test_scalar_02c                 C   s6   t g d}t|t dg}t|dgdgdgg d S r<   r=   r>   r-   r-   r.   test_scalar_036   s   zTestToeplitz.test_scalar_03c                 C   s*   t g d}td|}t|g dg d S )N)r9   r$   r%   r#   r"   r=   )r+   rr6   r-   r-   r.   test_scalar_04;   s   
zTestToeplitz.test_scalar_04N)
__name__
__module____qualname__r/   r8   r;   r@   rA   rB   rD   r-   r-   r-   r.   r!      s    r!   c                   @      e Zd Zdd ZdS )
TestHankelc                 C   sZ   t g d}t|g dg dg dg t g dg d}t|g dg dg dg d S )Nr"   r$   r%   r   )r%   r   r   r%   r'   r(   )r$   r%   r'   )r   r   r*   r-   r-   r.   r/   B   r0   zTestHankel.test_basicNrE   rF   rG   r/   r-   r-   r-   r.   rI   A       rI   c                   @   rH   )TestCirculantc                 C   s,   t g d}t|g dg dg dg d S )Nr"   )r#   r%   r$   )r$   r#   r%   r&   )r   r   r*   r-   r-   r.   r/   J   s    zTestCirculant.test_basicNrL   r-   r-   r-   r.   rN   I   rM   rN   c                   @   rH   )TestHadamardc                 C   s~   t d}t|dgg t dtd}t|ddgddgg t d}t|g dg dg d	g d
g ttt d ttt d d S )Nr#   r$   dtyper1         r'   r#   r#   r#   r#   )r#   r#   rT   )r#   r#   rT   rT   )r#   rT   rT   r#   r   r(   )r   r   floatassert_raises
ValueErrorr*   r-   r-   r.   r/   Q   s   
zTestHadamard.test_basicNrL   r-   r-   r-   r.   rO   O       rO   c                   @      e Zd Zdd Zdd ZdS )
TestLesliec                 C   sH   t ttddgddggg d t ttddgddg t ttdgg  d S )Nr#   r$   rK   )rV   rW   r   r+   r-   r-   r.   test_bad_shapese   s   zTestLeslie.test_bad_shapesc                 C   s:   t g dddg}tg dg dg dg}t|| d S )Nr"         ?      ?r1          @r2   )r]           ra   )ra   r^   ra   )r   r   r   )r+   aexpectedr-   r-   r.   r/   j   s   zTestLeslie.test_basicNrE   rF   rG   r\   r/   r-   r-   r-   r.   rZ   c       rZ   c                   @   rY   )TestCompanionc                 C   s.   t ttg d t ttdg t ttg  d S )N)r   r'   r(   r#   )rV   rW   r   r[   r-   r-   r.   r\   t   s   zTestCompanion.test_bad_shapesc                 C   s   t g d}tddgddgg}t|| t g d}tddgddgg}t|| t d	d
g}tddgddgfddgddgfg}t|| d S )Nr"          g      r1   ra   )r`         @g      $      rh   r_   )g      @rh   g      @g            )r   r   r   )r+   r?   rc   r-   r-   r.   r/   y   s0   

zTestCompanion.test_basicNrd   r-   r-   r-   r.   rf   r   re   rf   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   sZ   t tdddgddgddggg dg}t|g dg d	g d
g dg dg dg d S )Nr$   r#   r%   r'   r(      r"   )r#   r   r   r   r   r   r   )r   r#   r   r   r   r   r   )r   r   r#   r$   r   r   r   )r   r   r%   r'   r   r   r   )r   r   r(   rl   r   r   r   )r   r   r   r   r#   r$   r%   )r   r   r   r+   r5   r-   r-   r.   r/      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   rQ   rU   boolrm   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#                 ?r   )r   npr   r   )r+   actualdesiredr-   r-   r.   test_mixed_dtypes   s   zTestBlockDiag.test_mixed_dtypesc                 C   sJ   t d}t|jd t|dgg t ddgd}t|g dg dg d S )Nr#   r#   r#   r$   r%   r'   rJ   )r   r   r'   )r   r   shaper   r+   rb   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#   )rV   rW   r   r[   r-   r-   r.   test_bad_arg   s   zTestBlockDiag.test_bad_argc                 C   s"   t  }t|jd t|jd d S )Nr$   r   )r   r   ndimnbytesrw   r-   r-   r.   test_no_args   s   zTestBlockDiag.test_no_argsc              	   C   s\   t ddgddggg ddgddgddgg}t|g d	g d
g dg dg dg dg d S )Nr#   r   r$   r%   r'   r(   rl      r#   r   r   r   )r   r#   r   r   )r   r   r   r   )r   r   r$   r%   )r   r   r'   r(   )r   r   rl   r}   )r   r   rw   r-   r-   r.   test_empty_matrix_arg   s   

z#TestBlockDiag.test_empty_matrix_argc              	   C   sn   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|g dg dg dg dg dg dg d S )Nr#   r   r$   r%   r'   r(   rl   r}   int32rP   )r#   r   r   r   r   r   )r   r#   r   r   r   r   )r   r   r   r   r   r   )r   r   r$   r%   r   r   )r   r   r'   r(   r   r   )r   r   rl   r}   r   r   )r   rq   zerosr   rw   r-   r-   r.   test_zerosized_matrix_arg   s   

z'TestBlockDiag.test_zerosized_matrix_argN)rE   rF   rG   r/   ro   rt   rx   ry   r|   r   r   r-   r-   r-   r.   rk      s    	rk   c                   @   sD   e Zd Zejjdd Zejddd Zejddd Z	dS )	TestKronc                 C   sZ   t jdd ttddgddggtg dg W d    d S 1 s&w   Y  d S )Nz`kron`matchr#   r$   r%   r'   r#   r#   r#   )pytestdeprecated_callr   rq   r   r[   r-   r-   r.   test_dep   s   *"zTestKron.test_depzignore::DeprecationWarningc                 C   s   t tddgddggtg dg}t|tg dg d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#   r$   r%   r'   r   )r#   r#   r#   r$   r$   r$   )r%   r%   r%   r'   r'   r'   r9      r:         (   !   ,   )r   r   r   )r+   rb   m1m2rc   r-   r-   r.   r/      s   $
zTestKron.test_basicc                 C   s2   t d}t d}t||}t|t d d S )N)r   r$   )r#   r%   )r   rl   )rq   emptyr   r
   )r+   r   r   rb   r-   r-   r.   
test_empty   s   


zTestKron.test_emptyN)
rE   rF   rG   r   markthread_unsafer   filterwarningsr/   r   r-   r-   r-   r.   r      s    



r   c                   @   rY   )TestHelmertc                 C   sV   t ddD ]#}t|dd}t|}t||j|dd t|j||dd qd S )Nr#   r}   Tfull-q=atol)ranger   rq   r   r
   dotT)r+   nHIdr-   r-   r.   test_orthogonality   s   
zTestHelmert.test_orthogonalityc                 C   s   t ddD ]E}t|dd}t|}|dd d d f j|jfD ]*}t|t||fd|  }t||j| t|j|t|d dd qqd S )Nr$   r}   Tr   r#   r   r   )r   r   r   rq   r   r   r
   r   )r+   r   H_full	H_partialUCr-   r-   r.   test_subspace   s    "zTestHelmert.test_subspaceN)rE   rF   rG   r   r   r-   r-   r-   r.   r      s    r   c                   @   rH   )TestHilbertc                 C   sR   t g dg dg dg}ttd| ttddgg td}t|jd d S )	N)r1   r^   UUUUUU?)r^   r   r]   )r   r]   g?r%   r#   r1   r   )r   r   )r   r	   r   r   r   rv   )r+   h3h0r-   r-   r.   r/     s   zTestHilbert.test_basicNrL   r-   r-   r-   r.   r     rX   r   c                   @   rY   )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 g dg d	g d
g}ttddd| ttd| t g dg dg dg dg}ttddd| ttd| t g dg dg dg dg dg}ttddd| ttd| t g dg dg dg dg dg dg dg dg dg dg d g d!g d"g d#g d$g d%g d&g}ttd'dd| ttd'|td(d) d S )*Nr#   Texactr'   i   r$   )	   r   )r      L)r   r      r%   )      t)r   i  t  )r   r   iP  )r   r   r   i
  )     v  )r   i  , i  )r   r   i6 4|  )r   r   r   i  x)r   r   r   r   iD  r(   )i!  p]) 2@l%PAy    g
 P=    /w$:R
   xDum7   O@>/,	   t:`j!    < )r   i y ̌    r	 @u\     Db`Hh    Pz6  }%     l&W c(     hx 4z     d~I
 8wl8Z     @u8! `6a)r   r   l   @iLU  RK   8H,!`g`36    g0  *?*^B    ;t$ }|   @bsk C{'"i   `>9&%mq>   3CM@; 86`T    Pm;,
 )r   r   r   l    pM6= 0	     nC  YJVr     <_ L^V    R8 uxb    eH  EIBQx    HvYP x(6$     7	 >u1)r   r   r   r   l   Dcf$l @QM    8ItHv0"Qs   N
:v @ s/V|    #& p-N$v     5  @,@VK-
    8_DdYI  B _,    qk)r   r   r   r   r  l    O9x&Y)lx     pd gsxmU     D0FZD K|y#l_y     xbr &V%     lny?Cce @M=p-     @@|%6 h\bC )r   r   r   r   r  r  l   @/.L  BAyks'9    | 
LjY   iYn\"% #5Ey    X(@T'3?   @,3 Hx+/S    pO3^#
 )r   r   r   r   r  r  r  l    @+aF}cJ{
;_    P8Xy8Qo& BIhN    `@
oc#dLq,O    pFYRa Ii9M     R/$L@<8zG 0 )r   r   r   r   r  r  r  r#  l   $9@t)4   07$$Tv0 l7>?   "`-:M= (^@b)   6a;:BMb-Kx?|#   Z$M~ll )r   r   r   r   r  r  r  r$  r,  l    l>cTA@8HV-:v    h{d*U zaC<C     dYwMf RyUC#h.    @)]oz+%)r   r   r   r   r  r  r  r%  r-  r4  l   @e4jT  GU
    `i
t,@  Y,ch8    E@3I3T X=&@E   ~Si)r   r   r   r   r  r  r  r&  r.  r5  r;  l    p}v `Xfz~A`si     86Jpsbv  $JY'ip     tk(0u1@<f)r   r   r   r   r	  r  r  r'  r/  r6  r<  rA  l   w2T.g]  %\n     PYHul ZR@
R   LwJ)r   r   r   r   r
  r  r  r(  r0  r7  r=  rB  rF  l    L#(S.,# 2F=EgJ    @}l`L\k)r   r   r   r   r  r  r   r)  r1  r8  r>  rC  rG  rJ  l   @i7Qt0" 8B3\f	   p1&S,)r   r   r   r   r  r  r!  r*  r2  r9  r?  rD  rH  rK  rM  l     @Y? }xl]R )r   r   r   r  r  r  r"  r+  r3  r:  r@  rE  rI  rL  rN  rO  l   /"}+
    r   )rtol)r   r   r   r	   r
   astyperU   )r+   invh1invh2invh3invh4invh5invh17r-   r-   r.   r/     sd   zzTestInvHilbert.test_basicc                 C   sN   t ddD ]}t|}t|}t|}t||t|d| d| d qd S )Nr#   r9   gV瞯<)r   rQ  )r   r   r   r    r
   r   r   )r+   r   rb   br?   r-   r-   r.   test_inverse  s   $zTestInvHilbert.test_inverseN)rE   rF   rG   r/   rZ  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g dg dg dgeg dg d	g d
gfdeg dg dg dg dgeg dg dg dg dgfgZdd Zdd Zdd Zdd ZdS )
TestPascalr#   r$   r   r%   r   r"   )r#   r%   rl   )r#   r   r   )r#   r#   r   )r#   r$   r#   r'   rS   )r#   r$   r%   r'   )r#   r%   rl   r9   )r#   r'   r9   r:   r~   )r#   r#   r   r   )r#   r$   r#   r   )r#   r%   r%   r#   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upperFr   )r   r]  )r   r   r   r	   r+   r   symlowr-   r-   r.   
check_case  s   zTestPascal.check_casec                 C   s$   | j D ]\}}}| ||| qd S N)casesrb  r_  r-   r-   r.   
test_cases  s   zTestPascal.test_casesc                 C   s&   t d}|d tddddksJ d S )N2   )rT   rT   b   1   Tr   )r   r   r+   pr-   r-   r.   test_big  s   zTestPascal.test_bigc                 C   s\   t d}td|dd |dddd t d}td|dd d	|dd d
d d S )N"   r$   rT   zn = 34err_msg#   r`   r1   zn = 35)r   r   itemri  r-   r-   r.   test_threshold  s   "*zTestPascal.test_thresholdN)	rE   rF   rG   r   rd  rb  re  rk  rr  r-   r-   r-   r.   r[    sD    


r[  c                  C   sn   dd } g d}g d}|D ]}|D ]}dD ]}| ||| qqqg d}|D ]}|D ]}| ||d q+q'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=%rrn  )r   r   rR  objectr   r   r   )r   r]  r   iprj  er-   r-   r.   check_invpascal  s   z'test_invpascal.<locals>.check_invpascal)	symmetricr\  r^  )r#   r$   r(      )TF)   rl  rp  rf  Tr-   )rv  kindsnsr   r]  r   r-   r-   r.   test_invpascal  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g d}t d	} | |}t|}t|| d S )
Nr$   r1   rR   r   )scaler`   sqrtn)r   r#   r$   r%   r'   r(   r   r#      )r   r   r	   r   r   r   )mrc   r5   mxfxr-   r-   r.   test_dft  s   

r  c               	   C   s~   t g } t| jd t dg} t| tdgg t tdd} tg dg dg dg d	g d
g dg}t| | d S )Nr   g     ^@ra   r#   r}   )r   r#   r$   r%   r'   r(   )r#   r   r#   r$   r%   r'   )r$   r#   r   r#   r$   r%   )r%   r$   r#   r   r#   r$   )r'   r%   r$   r#   r   r#   )r(   r'   r%   r$   r#   r   )r   r   sizer   rq   r   r   )fdesr-   r-   r.   test_fiedler  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 g d} t| tg d tt	 t g d W d    n1 sIw   Y  t g d} tt
| tg d d S )	Nr   r1   r`   rg   )r   r`   r2   )r   r#   r$   )r1   g      0g     U@g      fg     @Z@)g      @rh   r2   r1   )r   r   r  r   rq   r   r	   r   rV   rW   r   )fcr-   r-   r.   test_fiedler_companion+  s   

r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zej	
d
ddgej	
dg dej	
dg dej	
dg d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.ri   g@rp   rj   g@)rq   linspace)r+   r   cpxr5   r-   r-   r.   create_vector@  s   z#TestConvolutionMatrix.create_vectorc                 C   sB   t jtdd tg dd W d    d S 1 sw   Y  d S )Nzn must be a positive integerr   r"   r   r   r   rW   r   r[   r-   r-   r.   
test_bad_nG     "z TestConvolutionMatrix.test_bad_nc                 C   s>   t jtdd tg d W d    d S 1 sw   Y  d S )Nzlen\(a\)r   r'   r  r[   r-   r-   r.   test_empty_first_argL  s   "z*TestConvolutionMatrix.test_empty_first_argc                 C   sB   t jtdd tdddd W d    d S 1 sw   Y  d S )Nzmode.*must be one ofr   ru   r'   zinvalid argument)moder  r[   r-   r-   r.   test_bad_modeQ  r  z#TestConvolutionMatrix.test_bad_moder  FTna)r#   r$   r   nvr  )Nr   validsamec           
      C   sh   |  ||}|  ||}|d u rt||}t||}nt|||}t|||}|| }	t||	 d S rc  )r  rq   convolver   r	   )
r+   r  r  r  r  rb   vy1Ay2r-   r-   r.   test_against_numpy_convolveV  s   z1TestConvolutionMatrix.test_against_numpy_convolveN)rE   rF   rG   __doc__r  r  r  r  r   r   parametrizer  r-   r-   r-   r.   r  ;  s    r  r(   zf, argsr-   )r(   r  r   c           	         s   t jd}d}d}|||f }thv r;d}tjt|d |g R   W d    d S 1 s4w   Y  d S |g R  }t  fdd|d|D }||j	d d |j	d	d   }t
|| d S )
Nl   ! )r$   r%   r9   z:Beginning in SciPy 1.17, multidimensional input will be...r   c                    s   g | ]
}|g R  qS r-   r-   ).0rb   argsr  r-   r.   
<listcomp>~  s    ztest_batch.<locals>.<listcomp>rT   rm  )rq   randomdefault_rngr   r   warnsFutureWarningasarrayreshaperv   r
   )	r  r  rngbatch_shaper  r  messageresrefr-   r  r.   
test_batchg  s    

""r  )>r   numpyrq   r   r   r   r   r   numpy.testingr   r   r	   r
   r   rV   	scipy.fftr   scipy.specialr   scipy.linalgr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   numpy.linalgr    r!   rI   rN   rO   rZ   rf   rk   r   r   r   r   r[  r|  r  r  r  r  r   r   	fail_slowr  r  r-   r-   r-   r.   <module>   sL    P/D )3,
