U
    O8c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   D/tmp/pip-unpacked-wheel-fd_gsd75/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   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 t tddktdtd d S )N      r   fdtype   )r   r   r   boolselfr   r   r   
test_basic   s&    






zTestEye.test_basicc                 C   sj   t ttdtdtddgddgg t ttdtdtddtddddgddddgg d S )N   r%   r#   r   r"   )Mk)r   r   npZuint64intr   r)   r   r   r   test_uint64/   s    ( zTestEye.test_uint64c              
   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#   r.   r   r   r   r   r)   r   r   r   	test_diag5   s    





zTestEye.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   r4   r)   r   r   r   test_2dB   s    




zTestEye.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 )Nr'   r"   r,   r2   r   r#   r4   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 )Nr,   r#   r   r3   r7   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 )Nr,   ZS3r%      1    r:   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 )Nr,   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s4t|jjr@t|jjrLt|jjsXtd S )Nr"   r'   r3   r2   F)r.   order)r   r   flagsc_contiguousAssertionErrorf_contiguous)r*   Zmat_cZmat_fr   r   r   
test_orderl   s    
zTestEye.test_orderN)__name__
__module____qualname__r+   r1   r5   r6   r8   r;   r>   r?   rF   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)rL   rL   )   rN   r,   r2   r7   )r   astyper   ranger   r   copy)r*   valsbr.   cr   r   r   test_vectorw   s    zTestDiag.test_vectorNc                 C   s   |d k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 )
NrK   rL   r#   rM   )rL   r   r'   r,   r7   )r    rO   r   rP   r   r   )r*   rR   rS   r.   r   r   r   test_matrix   s    zTestDiag.test_matrixc                 C   s(   t dtd d ddd}| | d S )NrK   rL   r#   r@   rM   )rA   r&   )r   r    rV   )r*   rR   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"   rL      r2   r   r3   r7   r9   )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)rG   rH   rI   rU   rV   rW   rZ   r\   r   r   r   r   rJ   v   s
   
	rJ   c                   @   s   e Zd Zdd ZdS )
TestFliplrc                 C   sv   t tttd td}|d d d d df }tt|| dddgdddgg}dddgdddgg}tt|| d S Nr"   r3   r   r#   r,   r'   rL   )r   r[   r
   r   r    r   r*   arS   r   r   r   r+      s    zTestFliplr.test_basicNrG   rH   rI   r+   r   r   r   r   r]      s   r]   c                   @   s   e Zd Zdd ZdS )
TestFlipudc                 C   sf   t d}|d d dd d f }tt|| dddgdddgg}dddgdddgg}tt|| d S r^   )r    r   r   r_   r   r   r   r+      s    zTestFlipud.test_basicNra   r   r   r   r   rb      s   rb   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 dddddg}t dddd	d
g}tddd}tddd}t||||fd }t dddddddddg	dddddddddg	dddddddddg	dddddddddg	dddddddddg	dddddddddg	dddddddddg	dddddddddg	dddddddddg	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 )Ng̙
}?g%?g$F?g;cjY?gI+?gp5x?g?_?gp?gbd?gg<=?r   r#   
   	      )	r   r/   linspacer   r   TlistrP   r   )r*   xyZxedgesZyedgesHanswerr   r   r   test_simple   s8    
 zTestHistogram2d.test_simplec                 C   s   t ddddddddg}t ddddddddg}t||dddgddggd	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dddddgg}t||d d t|tddd t|tddd d S )Nr#   r,   r'   r"   rL   r   )rX   rL   rX   T)rP   density        g       @rN   )r   r   r   r   r/   rg   r*   rj   rk   rl   xedyedrm   r   r   r   	test_asym   s*        zTestHistogram2d.test_asymc              
   C   s   t dddddddddg	}t dddddddddg	}t||ddddgddddggdd\}}}t dddgdddgdddggd	 }t||d d S )
Nr#   r,   r'   rL   T)ro         ?      ?g      "@)r   r   r   rq   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 )NrK         ?g    .A)r"   rL   r   r#   )rP   )r/   randomZrandr   r   )r*   rrl   rr   rs   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binsrp   r"   )r"   r"   )r   r   r   r/   r   )r*   r`   Zedge1Zedge2r   r   r   
test_empty   s     zTestHistogram2d.test_emptyc                 C   sp  t dddddddg}t ddd	d
dddg}d}t|||df\}}}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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ddddg t||d|f\}}}t ddddddddddg
ddddddddddg
ddddddddddg
ddddddddddg
g}t|| t|t dddddg d S )Nr   g<D瑷?g ?g!,3{?glyT?gf.?r#   g(@TT\?gIZ?gYN?gK?~?g&W-U?)r   g?g?g333333?g?ru   g333333?gffffff?g?g?r#   r"   g       @rp   rx   rv   ru   g      ?)r   r   r   )r*   rj   rk   edgesrl   ZxeZyerm   r   r   r   test_binparameter_combination   sN    
 
 











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)rG   rH   rI   r   r   r   r   r   ShouldDispatch   s   r   r#   r,   r|   rL   )weights)r   r   dictr   	Exception)r*   r   ZxyZs_drz   r   r   r   test_dispatch  s    

 zTestHistogram2d.test_dispatch)x_leny_len)rd   rf   )      c              	   C   s>   t |t | }}tjtdd t|| W 5 Q R X d S )Nz"x and y must have the same length.)match)r/   r   pytestZraisesr[   r   )r*   r   r   rj   rk   r   r   r   test_bad_length3  s
    zTestHistogram2d.test_bad_lengthN)rG   rH   rI   rn   rt   rw   r{   r}   r   r   r   r   markZparametrizer   r   r   r   r   rc      s   

rc   c                   @   s   e Zd Zdd ZdS )TestTric                 C   sJ   t dddgdddgdddgg}ttd| ttdtd|t d S )Nr#   r   r'   r%   )r   r   r   r(   rO   )r*   outr   r   r   
test_dtype<  s    
zTestTri.test_dtypeN)rG   rH   rI   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)r,   r,   r%   r#   r   )	r/   	typecodesr   triltriur   rh   r   r&   )r&   r`   rS   rT   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%   )r/   r   r   r   r   r   r   r&   )r&   r`   Za_tril_desiredZa_triu_desiredZa_triu_observedZa_tril_observedr   r   r   test_tril_triu_ndim3P  s8    



r   c                  C   st   t ddt jgdddgt jddgg} t dddgdddgt jddgg}|j}tt | | tt | | d S )Nr#   r   )r/   r   infrh   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)r/   r   r   r   r   r&   r   r   )rT   r   r   r   r   test_tril_triu_dtypev  s     
r   c               	   C   sf   t dtj} tddd}t||  tddddddg t dtjd}t|| tdddg d S )	Nr'   re   r   r#   r,   r"   rL      )r   r/   r   r   reshaper   r   )iur`   iu1r   r   r   test_mask_indices  s
    r   c                  C   s  t d} t ddd}t ddd}t d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dddd}t||  tddd	dddddddg
 t|| tdd	d
dddddddg
 d|| < t|tddddgddd
dgddddgddddgg d||< t|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g d||< t|tddddgddddgddddgddddgg d||< t|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g d S )Nr"   r,   r2   rL   mr.   r   r#   r'   rX   rN   r   re   rd   rf                           r   r3   r   )r   r/   r   r   r   r   )Zil1Zil2Zil3Zil4r`   rS   r   r   r   test_tril_indices  s`    








r   c                   @   s   e Zd Zdd ZdS )TestTriuIndicesc                 C   s  t d}t ddd}t ddd}t d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dddd}t|| tddddd	d
ddddg
 t|| tdddddd
ddddddddg d||< t|tddddgddddgddddgddddgg d||< t|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g d||< t|tddddgddddgddddgddddgg d||< t|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g d S )Nr"   r,   r2   rL   r   r   r#   r'   rX   rN   r   re   rd   rf   r   r   r   r   r   r   r   r   r3   r   r   r   )r   r/   r   r   r   r   )r*   r   Ziu2Ziu3Ziu4r`   rS   r   r   r   test_triu_indices  sn    


     





z!TestTriuIndices.test_triu_indicesN)rG   rH   rI   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)r,   )r,   r,   r,   )r   r[   r   r/   r   r)   r   r   r   test_exceptions  s    z#TestTrilIndicesFrom.test_exceptionsNrG   rH   rI   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   r[   r   r/   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 ddddg}t|}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g}t||d d dd f  |jd }tdD ].}t||d}t||d d || |f  qd S )Nr   r#   r7   r'   r   ir"   Q      re   rX   N)r/   r   r   r   shaperP   )r*   rT   vZpowersr   r   r   r   r   r+     s    
zTestVander.test_basicc                 C   s   t dddgtjd}t|}t dddgdddgdddgg}t|| t d	d
g}t|dd}t dd	dgdd
dgg}t|| d S )Nrf   ir   r%   y   r#         y      ?      ?y      ?      r'   r   y               @y              )r   r/   Zint8r   r   )r*   rT   r   expectedr   r   r   test_dtypes  s    
zTestVander.test_dtypesN)rG   rH   rI   r+   r   r   r   r   r   r     s   r   )/__doc__Znumpy.testingr   r   r   r   r   r   Znumpyr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r/   Znumpy.core.tests.test_overridesr   r   r    r!   rJ   r]   rb   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s,    LX/}	
/2