a
    IbJ                     @   sT  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m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vanderN)requires_array_functionc                 C   s   t | }t||}|S N)r   r	   outer)ndata r   ]/var/www/html/barcode/barcode/lib/python3.9/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$   r2   r%   r&   r'   r   r   r   r   r#   r   r   r   r-   r   r   r   	test_diag5   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&   r9   r-   r   r   r   test_2dB   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"   r0   r6   r&   r'   r7   r=   r;   r<   r9   r-   r   r   r   test_diag2dN   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 )Nr0   r$   r   r8   r?   r+   r   r   r-   r   r   r   test_eye_boundsZ   s    $$$$zTestEye.test_eye_boundsc                 C   s$   t tddddddgddgg d S )Nr0   ZS3r)      1    rB   r-   r   r   r   test_stringse   s    zTestEye.test_stringsc                 C   s$   t tddtdddgddgg d S )Nr0   r)   TF)r   r   r,   r-   r   r   r   	test_booli   s    zTestEye.test_boolc                 C   s\   t dddd}t ddddd}t|| |jjs4J |jjr@J |jjrLJ |jjsXJ d S )Nr"   r+   r8   r6   F)r2   order)r   r   flagsc_contiguousf_contiguous)r.   Zmat_cZmat_fr   r   r   
test_orderl   s    
zTestEye.test_orderN)__name__
__module____qualname__r/   r5   r:   r>   r@   rC   rF   rG   rM   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)rS   rS   )   rU   r0   r6   r?   )r   astyper   ranger   r   copy)r.   valsbr2   cr   r   r   test_vectorw   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 ||< qbtt|d|d d  tdD ]}||d |f ||< qtt|d	|d d  d S )
NrR   rS   r$   rT   )rS   r   r+   r0   r?   )r    rV   r   rW   r   r   )r.   rY   rZ   r2   r   r   r   test_matrix   s    zTestDiag.test_matrixc                 C   s(   t dtd d ddd}| | d S )NrR   rS   r$   rH   rT   )rI   r*   )r   r    r]   )r.   rY   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$   r0   r+   r"   rS      r6   r   r8   r?   rA   )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_failure)N)rN   rO   rP   r\   r]   r^   ra   rc   r   r   r   r   rQ   v   s
   
	rQ   c                   @   s   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"   r8   r   r$   r0   r+   r"   rS   )r0   r$   r   )rS   r"   r+   )r   rb   r
   r   r    r   r.   arZ   r   r   r   r/      s    zTestFliplr.test_basicNrN   rO   rP   r/   r   r   r   r   rd      s   rd   c                   @   s   e Zd Zdd ZdS )
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"   r8   re   rf   )r    r   r   rg   r   r   r   r/      s    zTestFlipud.test_basicNri   r   r   r   r   rj      s   rj   c                   @   sb   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	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   r3   linspacer   r   TlistrW   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$   r0   r+   r"   r"   r"   rS   )r$   r+   r0   r   r$   r0   r+   r"   )r_   rS   r   r_   rS   T)rW   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+   rU   )r   r   r   r   r3   ro   r.   rr   rs   rt   xedyedru   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$   r0   r+   r$   r0   r+   r$   r0   r+   )	r$   r$   r$   r0   r0   r0   r+   r+   r+   )r$   r0   r+   rS   T)rw   )r$   r$         ?)r~   r~         ?g      "@r+   )r   r   r   rz   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 )NrR         ?g    .A)r"   rS   r   r$   )rW   )r3   randomZrandr   r   )r.   rrt   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binsrx   r"   )r"   r"   )r   r   r   r3   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       @rx   rx   rx   )rx   r   rx   rx   )rx   rx   rx   rx   )r   rx   rx   rx   )rx   rx   rx   r   )rx   r   r~   g      ?r$   )
r   r   rx   r   rx   rx   rx   rx   rx   rx   )
rx   rx   rx   rx   r   rx   rx   rx   rx   rx   )
rx   r   rx   rx   r   rx   rx   rx   rx   rx   )
rx   rx   rx   rx   rx   rx   rx   rx   rx   r   )r   r   r   )r.   rr   rs   edgesrt   ZxeZyeru   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                   @   s   e Zd Zdd ZdS )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)rN   rO   rP   r   r   r   r   r   ShouldDispatch   s   r   r$   r0   r   rS   )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)rl   rn   )      c                 C   sR   t |t | }}tjtdd t|| W d    n1 sD0    Y  d S )Nz"x and y must have the same length.)match)r3   r   pytestZraisesrb   r   )r.   r   r   rr   rs   r   r   r   test_bad_length3  s
    zTestHistogram2d.test_bad_lengthN)rN   rO   rP   rv   r}   r   r   r   r   r   r   r   markZparametrizer   r   r   r   r   rk      s   

rk   c                   @   s   e Zd Zdd ZdS )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,   rV   )r.   outr   r   r   
test_dtype<  s    zTestTri.test_dtypeN)rN   rO   rP   r   r   r   r   r   r   ;  s   r   c                  C   s~   t jd t jd  D ]d} 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)r0   r0   r)   r$   r   )	r3   	typecodesr   triltriur   rp   r   r*   )r*   rh   rZ   r[   r   r   r   test_tril_triu_ndim2D  s    

r   c                  C   s
  t jd t jd  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 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)   )r3   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_ndim3P  s8    



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   )r3   r   infrp   r   r   r   )arrZout_trilZout_triur   r   r   test_tril_triu_with_infi  s    


r   c                  C   s   t jd 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)r3   r   r   r   r   r*   r   r   )r[   r   r   r   r   test_tril_triu_dtypev  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+   rm   )r   r$   r0   r"   rS      r$   )r$   r0   rS   )r   r3   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"   r0   r6   rS   mr2   r   r$   r0   r+   r"   rS   r_   rU   r   rm   rl   rn                  r$      )
r$   rS   r_   rm   rl   rn   r   r   r   r   )
r$   r_   rU   rn   r   r   r         r   r8   )r8   r0   r+   r"   )r8   r8   rU   r   )r8   r8   r8   r   r8   r8   r8   r8   )r8   r0   r+   r"   rS   )r8   r8   r   rm   rl   )r8   r8   r8   r   r   )r8   r8   r8   r8   r   )r   r   r   r"   )r   r   r   r   )r   r   r   r"   rS   )r   r   r   r   rl   )r   r   r   r   r   )r   r3   r   r   r   r   )Zil1Zil2Zil3Zil4rh   rZ   r   r   r   test_tril_indices  s`    


r   c                   @   s   e Zd Zdd ZdS )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"   r0   r6   rS   r   r   r   r   r   r   r$   r   )
r$   r0   r+   r"   r_   rU   r   rn   r   r   )r$   r0   r+   r"   rS   rU   r   rm   rl   r   r   r   r   r   r8   r   )rS   r8   r8   r8   )rm   rl   r8   r8   )r   r   r   r8   )r8   r8   r8   r8   r8   )r_   r8   r8   r8   r8   )rn   r   r8   r8   r8   )r   r   r   r8   r8   r   )r8   r8   r   r   )rS   r8   r8   r   )r8   r8   r   r   r   )r_   r8   r8   r   r   )rn   r   r8   r8   r   )r   r3   r   r   r   r   )r.   r   Ziu2Ziu3Ziu4rh   rZ   r   r   r   test_triu_indices  s`    


z!TestTriuIndices.test_triu_indicesN)rN   rO   rP   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )TestTrilIndicesFromc                 C   s(   t tttd t tttd d S N)r0   )r0   r0   r0   )r   rb   r   r3   r   r-   r   r   r   test_exceptions  s    z#TestTrilIndicesFrom.test_exceptionsNrN   rO   rP   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )TestTriuIndicesFromc                 C   s(   t tttd t tttd d S r   )r   rb   r   r3   r   r-   r   r   r   r     s    z#TestTriuIndicesFrom.test_exceptionsNr   r   r   r   r   r     s   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  qdd S )	N)r   r$   r?   r+   ry   )r$   r$   r$   r$   r$   )r   ir"   r?   r$   )Q      rm   r+   r$   r$   r_   N)r3   r   r   r   shaperW   )r.   r[   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)rn   r   r)   )y   rn   r$   )   r   r$   )   r   r$         ?      ?      ?      r+   r   )y               @r   r$   )y              r   r$   )r   r3   Zint8r   r   )r.   r[   r   expectedr   r   r   test_dtypes  s    


zTestVander.test_dtypesN)rN   rO   rP   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   r3   Znumpy.core.tests.test_overridesr   r   r    r!   rQ   rd   rj   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s,    LX/}	
/2