o
    ʩZhI                     @   sH  d 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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ZddlZ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"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(G dd  d Z)G d!d" d"Z*G d#d$ d$Z+G d%d& d&Z,dS )'z"Test functions for matrix module

    )assert_equalassert_array_equalassert_array_max_ulpassert_array_almost_equalassert_raisesassert_)arangeaddfliplrflipudzerosoneseyearraydiaghistogram2dtrimask_indicestriu_indicestriu_indices_fromtril_indicestril_indices_fromvanderNc                 C   s   t | }t||}|S N)r   r	   outer)ndata r   W/var/www/html/lang_env/lib/python3.10/site-packages/numpy/lib/tests/test_twodim_base.pyget_mat   s   r   c                   @   sT   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d ZdS )TestEyec                 C   sx   t tdtg dg dg dg dg t tdddtg dg dg dg dgd t tdd	ktdtd d S )
N      r   r   r   r   r#   r   r   r   r   r#   r   r   r   r   r#   fdtype   r#   )r   r   r   boolselfr   r   r   
test_basic   s&   
zTestEye.test_basicc                 C   sb   t ttdtdtddgddgg t ttdtdtddtg dg dg d S )	N   r(   r#   r   r!   )Mkr$   r%   )r   r   npZuint64intr   r,   r   r   r   test_uint64)   s   ( zTestEye.test_uint64c                 C   s`   t tdddtg dg dg dg dg t tdddtg dg d	g dg dg d S )
Nr!   r#   r1   r$   r%   r&   r   r   r   r   r"   r   r   r   r,   r   r   r   	test_diag/   s   zTestEye.test_diagc                 C   sV   t tddtg dg dg dg dg t td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%   r8   r,   r   r   r   test_2d<   s   

zTestEye.test_2dc                 C   s^   t tddddtg dg dg dg t tddddtg d	g d	g d
g dg d S )Nr*   r!   r/   r5   r%   r&   r6   r<   r:   r;   r8   r,   r   r   r   test_diag2dH   s   zTestEye.test_diag2dc                 C   s0  t tdddddgddgg t tdddddgddgg t tdddddgddgg t tdddddgddgg t tdddddgddgddgg t tdddddgddgddgg t tdddddgddgddgg t tdddddgddgddgg t tdddddgddgddgg d S )Nr/   r#   r   r7   r>   r*   r   r   r,   r   r   r   test_eye_boundsT   s   $$$$(zTestEye.test_eye_boundsc                 C   s$   t tddddddgddgg d S )Nr/   ZS3r(      1    rA   r,   r   r   r   test_strings_   s   zTestEye.test_stringsc                 C   s$   t tddtdddgddgg d S )Nr/   r(   TF)r   r   r+   r,   r   r   r   	test_boolc   s   $zTestEye.test_boolc                 C   s\   t dddd}t ddddd}t|| |jjsJ |jjr J |jjr&J |jjs,J d S )Nr!   r*   r7   r5   F)r1   order)r   r   flagsc_contiguousf_contiguous)r-   Zmat_cZmat_fr   r   r   
test_orderf   s   
zTestEye.test_orderN)__name__
__module____qualname__r.   r4   r9   r=   r?   rB   rE   rF   rL   r   r   r   r   r       s    r    c                   @   s6   e Zd Zdd ZdddZdd Zdd	 Zd
d ZdS )TestDiagc                 C   s   dt d d}td}tdD ]
}|| |||f< qtt|| td}| }tdD ]}|| |||d f< || ||d |f< q/tt|dd| tt|dd| d S )	Nd      l)rR   rR   )   rT   r/   r5   r>   )r   astyper   ranger   r   copy)r-   valsbr1   cr   r   r   test_vectorq   s   zTestDiag.test_vectorNc                 C   s   |d u rdt d d d}td}tdD ]
}|||f ||< qtt|| |d }tdD ]}|||d f ||< q1tt|d|d d  tdD ]}||d |f ||< qNtt|d	|d d  d S )
NrQ   rR   r#   rS   )rR   r   r*   r/   r>   )r   rU   r   rV   r   r   )r-   rX   rY   r1   r   r   r   test_matrix   s   zTestDiag.test_matrixc                 C   s(   t dtd d ddd}| | d S )NrQ   rR   r#   rG   rS   )rH   r)   )r   r   r\   )r-   rX   r   r   r   test_fortran_order   s   zTestDiag.test_fortran_orderc                 C   s   ddgddgddgg}t t|ddg  t t|dddg t t|ddddg t t|d	dddg t t|d
ddg t t|ddg  d S )Nr#   r/   r*   r!   rR      r5   r   r7   r>   r@   )r   r   )r-   Ar   r   r   test_diag_bounds   s   zTestDiag.test_diag_boundsc                 C   s   t ttdggg d S )Nr#   )r   
ValueErrorr   r,   r   r   r   test_failure   s   zTestDiag.test_failurer   )rM   rN   rO   r[   r\   r]   r`   rb   r   r   r   r   rP   p   s    
	rP   c                   @      e Zd Zdd ZdS )
TestFliplrc                 C   sn   t tttd td}|d d d d df }tt|| g dg dg}g dg dg}tt|| d S )Nr!   r7   r   r#   r/   r*   r!   rR   )r/   r#   r   )rR   r!   r*   )r   ra   r
   r   r   r   r-   arY   r   r   r   r.      s   zTestFliplr.test_basicNrM   rN   rO   r.   r   r   r   r   rd          rd   c                   @   rc   )
TestFlipudc                 C   s^   t d}|d d dd d f }tt|| g dg dg}g dg dg}tt|| d S )Nr!   r7   re   rf   )r   r   r   rg   r   r   r   r.      s   zTestFlipud.test_basicNri   r   r   r   r   rk      rj   rk   c                   @   s^   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	e
jdddgdd ZdS )TestHistogram2dc                 C   s
  t g d}t g d}tddd}tddd}t||||fd }t g dg dg dg d	g d
g dg dg dg dg	}t|j| t|||d }t|j| tttdttd\}}}t|tdd t|tddd t|tddd d S )N)g̙
}?g%?g$F?g;cjY?gI+?)gp5x?g?_?gp?gbd?gg<=?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#   r   r   r   r   r   r   r   	      )	r   r2   linspacer   r   TlistrV   r   )r-   xyZxedgesZyedgesHanswerr   r   r   test_simple   s8   
 zTestHistogram2d.test_simplec                 C   s   t g d}t g d}t||dddgddggdd\}}}t g d	g d
g dg dg dg dg}t||d d t|tddd t|tddd d S )N)r#   r#   r/   r*   r!   r!   r!   rR   )r#   r*   r/   r   r#   r/   r*   r!   )r^   rR   r   r^   rR   T)rV   density)        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#   g       @r*   rT   )r   r   r   r   r2   rp   r-   rs   rt   ru   xedyedrv   r   r   r   	test_asym   s"   zTestHistogram2d.test_asymc                 C   sh   t g d}t g d}t||g dg dgdd\}}}t g dg dg dgd }t||d	 d S )
N)	r#   r/   r*   r#   r/   r*   r#   r/   r*   )	r#   r#   r#   r/   r/   r/   r*   r*   r*   )r#   r/   r*   rR   T)rx   )r#   r#         ?)r   r         ?g      "@r*   )r   r   r   r{   r   r   r   test_density   s   zTestHistogram2d.test_densityc                 C   sD   t jdd d }t||dddgddgfd\}}}t|d d S )NrQ         ?g    .A)r!   rR   r   r#   )rV   )r2   randomZrandr   r   )r-   rru   r|   r}   r   r   r   test_all_outliers   s   "z!TestHistogram2d.test_all_outliersc                 C   sZ   t g g ddgddgfd\}}}t|tdgg t g g dd\}}}t|td d S )Nr   r#   Zbinsry   r!   )r!   r!   )r   r   r   r2   r   )r-   rh   Zedge1Zedge2r   r   r   
test_empty   s    zTestHistogram2d.test_emptyc                 C   s   t g d}t g d}d}t|||df\}}}t g dg dg dg dg dg dg dg dg dg d	g
}t|| t|t g d
 t||d|f\}}}t g dg dg dg dg}t|| t|t g d
 d S )N)r   g<D瑷?g ?g!,3{?glyT?gf.?r#   )r   g(@TT\?gIZ?gYN?gK?~?g&W-U?r#   )r   g?g?g333333?g?r   g333333?gffffff?g?g?r#   r!   )g       @ry   ry   ry   )ry   r   ry   ry   )ry   ry   ry   ry   )r   ry   ry   ry   )ry   ry   ry   r   )ry   r   r   g      ?r#   )
r   r   ry   r   ry   ry   ry   ry   ry   ry   )
ry   ry   ry   ry   r   ry   ry   ry   ry   ry   )
ry   r   ry   ry   r   ry   ry   ry   ry   ry   )
ry   ry   ry   ry   ry   ry   ry   ry   ry   r   )r   r   r   )r-   rs   rt   edgesru   ZxeZyerv   r   r   r   test_binparameter_combination   sB   

z-TestHistogram2d.test_binparameter_combinationc                 C   s   G dd d}ddg}| }t ||}t||f||fi fk t ||}t||f||fi fk t |||d}t||f||ft|df t |||dgd}t||f||ft|dgdf ttt |||gd t |||d}t||f||ft|df d S )Nc                   @   rc   )z5TestHistogram2d.test_dispatch.<locals>.ShouldDispatchc                 S   s
   |||fS r   r   )r-   functiontypesargskwargsr   r   r   __array_function__  s   
zHTestHistogram2d.test_dispatch.<locals>.ShouldDispatch.__array_function__N)rM   rN   rO   r   r   r   r   r   ShouldDispatch  rj   r   r#   r/   r   rR   )weights)r   r   dictr   	Exception)r-   r   ZxyZs_dr   r   r   r   test_dispatch  s   

  zTestHistogram2d.test_dispatch)x_leny_len)rm   ro   )      c                 C   sT   t |t |}}tjtdd t|| W d    d S 1 s#w   Y  d S )Nz"x and y must have the same length.)match)r2   r   pytestZraisesra   r   )r-   r   r   rs   rt   r   r   r   test_bad_length,  s   "zTestHistogram2d.test_bad_lengthN)rM   rN   rO   rw   r~   r   r   r   r   r   r   markZparametrizer   r   r   r   r   rl      s    
rl   c                   @   rc   )TestTric                 C   sD   t g dg dg dg}ttd| ttdtd|t d S )Nr:   r#   r#   r   r#   r#   r#   r*   r(   )r   r   r   r+   rU   )r-   outr   r   r   
test_dtype5  s   zTestTri.test_dtypeN)rM   rN   rO   r   r   r   r   r   r   4  rj   r   c                  C   s~   t jd t jd  D ]2} t jd| d}t |}t |}t|ddgddgg t||j t|j|j t|j|j q
d S )NAllFloat
AllInteger)r/   r/   r(   r#   r   )	r2   	typecodesr   triltriur   rq   r   r)   )r)   rh   rY   rZ   r   r   r   test_tril_triu_ndim2=  s   

r   c                  C   s
  t jd t jd  D ]x} t jddgddggddgddggddgddggg| d}t jddgddggddgddggddgddggg| d}t jddgddggddgddggddgddggg| d}t |}t |}t|| t|| t|j|j t|j|j q
d S )Nr   r   r#   r   r(   )r2   r   r   r   r   r   r   r)   )r)   rh   Za_tril_desiredZa_triu_desiredZa_triu_observedZa_tril_observedr   r   r   test_tril_triu_ndim3I  s:   



r   c                  C   sn   t ddt jgg dt jddgg} t g dg dt jddgg}|j}tt | | tt | | d S )Nr#   r   r:   r   )r2   r   infrq   r   r   r   )arrZout_trilZout_triur   r   r   test_tril_triu_with_infb  s   


r   c                  C   s   t jd D ]"} | dkrqt jd| d}tt |j|j tt |j|j qt jddgddggd	d}tt |j|j tt |j|j t jdd
d}tt |j|j tt |j|j d S )NZAllV)r*   r*   r(   z2001-01-01T12:00z2002-02-03T13:56z2004-01-01T12:00z2003-01-03T13:45Z
datetime64zf4,f4)r2   r   r   r   r   r)   r   r   )rZ   r   r   r   r   test_tril_triu_dtypeo  s    
r   c                  C   s\   t dtj} tddd}t||  tg d t dtjd}t|| tg d d S )Nr*   rn   )r   r#   r/   r!   rR      r#   )r#   r/   rR   )r   r2   r   r   reshaper   r   )iurh   iu1r   r   r   test_mask_indices  s
   r   c                  C   sL  t d} t ddd}t ddd}t dddd}tg dg dg d	g d
g}tdddd}t||  tg d t|| tg d d|| < t|tg dg dg dg dg d||< t|tg dg dg dg dg d||< t|tg dg dg dg dg d||< t|tg dg dg dg dg d S )Nr!   r/   r5   rR   mr1   r   r#   r/   r*   r!   rR   r^   rT   r   rn   rm   ro                  r#      )
r#   rR   r^   rn   rm   ro   r   r   r   r   )
r#   r^   rT   ro   r   r   r         r   r7   )r7   r/   r*   r!   )r7   r7   rT   r   )r7   r7   r7   r   r7   r7   r7   r7   )r7   r/   r*   r!   rR   )r7   r7   r   rn   rm   )r7   r7   r7   r   r   )r7   r7   r7   r7   r   )r   r   r   r!   )r   r   r   r   )r   r   r   r!   rR   )r   r   r   r   rm   )r   r   r   r   r   )r   r2   r   r   r   r   )Zil1Zil2Zil3Zil4rh   rY   r   r   r   test_tril_indices  s`   


r   c                   @   rc   )TestTriuIndicesc                 C   sL  t d}t ddd}t ddd}t dddd}tg dg dg d	g d
g}tdddd}t|| tg d t|| tg d d||< t|tg dg dg dg dg d||< t|tg dg dg dg dg d||< t|tg dg dg dg dg d||< t|tg dg dg dg dg d S )Nr!   r/   r5   rR   r   r   r   r   r   r   r#   r   )
r#   r/   r*   r!   r^   rT   r   ro   r   r   )r#   r/   r*   r!   rR   rT   r   rn   rm   r   r   r   r   r   r7   r   )rR   r7   r7   r7   )rn   rm   r7   r7   )r   r   r   r7   )r7   r7   r7   r7   r7   )r^   r7   r7   r7   r7   )ro   r   r7   r7   r7   )r   r   r   r7   r7   r   )r7   r7   r   r   )rR   r7   r7   r   )r7   r7   r   r   r   )r^   r7   r7   r   r   )ro   r   r7   r7   r   )r   r2   r   r   r   r   )r-   r   Ziu2Ziu3Ziu4rh   rY   r   r   r   test_triu_indices  s`   


z!TestTriuIndices.test_triu_indicesN)rM   rN   rO   r   r   r   r   r   r     rj   r   c                   @   rc   )TestTrilIndicesFromc                 C   (   t tttd t tttd d S N)r/   )r/   r/   r/   )r   ra   r   r2   r   r,   r   r   r   test_exceptions     z#TestTrilIndicesFrom.test_exceptionsNrM   rN   rO   r   r   r   r   r   r     rj   r   c                   @   rc   )TestTriuIndicesFromc                 C   r   r   )r   ra   r   r2   r   r,   r   r   r   r     r   z#TestTriuIndicesFrom.test_exceptionsNr   r   r   r   r   r     rj   r   c                   @   s   e Zd Zdd Zdd ZdS )
TestVanderc                 C   s   t g d}t|}t g dg dg dg dg}t||d d dd f  |jd }tdD ]}t||d}t||d d || |f  q2d S )	N)r   r#   r>   r*   rz   )r#   r#   r#   r#   r#   )r   ir!   r>   r#   )Q      rn   r*   r#   r#   r^   N)r2   r   r   r   shaperV   )r-   rZ   vZpowersr   r   r   r   r   r.     s   

 zTestVander.test_basicc                 C   s|   t g dtjd}t|}t g dg dg dg}t|| t ddg}t|dd	}t g d
g dg}t|| d S )N)ro   r   r(   )y   ro   r#   )   r   r#   )   r   r#         ?      ?      ?      r*   r   )y               @r   r#   )y              r   r#   )r   r2   Zint8r   r   )r-   rZ   r   expectedr   r   r   test_dtypes  s   


zTestVander.test_dtypesN)rM   rN   rO   r.   r   r   r   r   r   r     s    r   )-__doc__Znumpy.testingr   r   r   r   r   r   numpyr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r    rP   rd   rk   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s,     LX/|	
/2