a
    LfO                     @   s   d dl Z d dlZd dlmZ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 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G dd dZdd Z G dd dZ!dd Z"dS )    N)assert_assert_equalassert_array_equalassert_almost_equalassert_array_almost_equalassert_raisesassert_raises_regex)mgridogridndenumeratefill_diagonaldiag_indicesdiag_indices_from	index_expndindexc_r_s_ix_c                   @   sf   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g ddd Zdd ZdS )TestRavelUnravelIndexc                 C   s  t tddd t tjdddd tt tjddd W d    n1 sR0    Y  tt tjddd W d    n1 s0    Y  tt tjddd	 W d    n1 s0    Y  tt tjddd
 W d    n1 s0    Y  t tddd t tddd t tddd tttjdd tttjdd tttjdd tttjdd tttjdd tttjdd tttjdd tttjdd t tddg d t tg ddd tg dg dg}t t|dg d t tj|dddg d t tj|ddd g d! t tj|d"d#d g d$ t td%d&d' t ttg ddg dg dg t tjtg ddddg dg dg t td'd&g d% d S )(N   )r   r      r   )indicesshape)r   hape)r      )   ^   )Zims)dims)r   B   g      ?   )r   )r   r   )r   r#   )r   r   )皙?g        .   )r"         )r   r   r"   )r&   r'   r'   )r"      r   )   r'   )   )   %   Forder)   r+      )r"   r'   clipmode)r*         r"   r"   )r2   wrap)   r1   r1   )r&   r   r"   r   )r'   r)      	   iU  )r   npunravel_indexr   	TypeErrorravel_multi_index
ValueErrorarray)selfarr rD   Z/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/lib/tests/test_index_tricks.py
test_basic   sb    
,
,
,
,z TestRavelUnravelIndex.test_basicc                 C   s  d}d}t t|tjg d t t|tjdd t t|tjtg d tttjg tddg g g g t t|tjg g fd t t|tjg dgfd t t|tjtg tg fd tttjg tdtjg tdfdg  tttjg g gtddg  d S )	Nz9indices must be integral: the provided empty sequence waszonly int indices permitted)
   r&   r(   rD   dtyperG   r&   abc)r(   r&   )r   r>   r<   r=   rA   r   intr?   )rB   Zmsg1Zmsg2rD   rD   rE   test_empty_indicesF   s:    
z(TestRavelUnravelIndex.test_empty_indicesc                 C   s   t jt jkrPddgddgddgddgdd	gddgd
dgf}tt |dddg ttt jdd d
gd
gf}t t jj	d }tt ||dfd
g ttt j||d df tt j||dfddd
g ttt j||d dfdd d S )Nr      r&   r(   u   r6   r   iK	  i  r   )r+   r)   x   $   i
  r:   r'   l   z l   nm )l    l       r-   r.   )
r<   intpint64r   r?   r   r@   r=   Ziinfomax)rB   rC   Z	dummy_arrZhalf_maxrD   rD   rE   test_big_indicesZ   s.    
z&TestRavelUnravelIndex.test_big_indicesc                 C   sr  t jt jt jt jt jt jfD ]N}t jg dg dg|d}d}d|d  |d  }tt 	||| t|t 
|| |d d|d   }tt j	||d	d
| t|t j
||d	d
 t jg dg dg dg|d}d}dd|d  |d   |d  }tt 	||| t|t 
|| |d d|d d|d     }tt j	||d	d
| t|t j
||d	d
 qd S )N)r   r   r   r   r&   r"   )r   r'   r   r&   r   r   rH   )r(   r:   r:   r   r   r(   r-   r.   )r   r&   r   r   r;   r(   )r(   r:   rG   rG   r   )r<   Zint16Zuint16Zint32Zuint32rS   Zuint64rA   r   r?   r=   )rB   rI   Zcoordsr   ZuncoordsrD   rD   rE   test_dtypesr   s8    
  z!TestRavelUnravelIndex.test_dtypesc                 C   sd   t tjg ddddtg dd t tjg ddddtg dd tttjg dd d S )N)r(   r   r!   r   )r"   r&   r)   r9   r8   r3   )r   r   r'   r   )r8   raiser2   rW   )r   r   r   r   )r   r<   r?   r   r@   rB   rD   rD   rE   test_clipmodes   s    z$TestRavelUnravelIndex.test_clipmodesc                 C   s0   t g dd\}}t|jj t|jj d S )Nr   r   r&   )r"   r(   )r<   r=   r   flagsZ	writeable)rB   xyrD   rD   rE   test_writeability   s    z'TestRavelUnravelIndex.test_writeabilityc                 C   sB   t dd}t|d ttdt jdgd ttdt jdgd d S )Nr   rD   z0d arrayzout of boundsr   )r<   r=   r   r   r@   rB   r\   rD   rD   rE   test_0d   s    
zTestRavelUnravelIndex.test_0dr4   )r2   r8   rW   c                 C   sr   t jt jdt jdd|d}|jdks*J tt, t jt jdt jdd|d W d    n1 sd0    Y  d S )N)r&   r   rH   r   r   r   r3   r   )r&   r   )r<   r?   zerosrR   r   r   r@   )rB   r4   resrD   rD   rE   test_empty_array_ravel   s    
z,TestRavelUnravelIndex.test_empty_array_ravelc                 C   sx   t t jdt jdd}t|dks(J tdd |D s>J tt t dgd W d    n1 sj0    Y  d S )Nr   rH   ra   r&   c                 s   s   | ]}|j d kV  qdS )rb   N)r   ).0arD   rD   rE   	<genexpr>       zATestRavelUnravelIndex.test_empty_array_unravel.<locals>.<genexpr>r   )r<   r=   rc   rR   lenallr   r@   )rB   rd   rD   rD   rE   test_empty_array_unravel   s
    
z.TestRavelUnravelIndex.test_empty_array_unravelN)__name__
__module____qualname__rF   rM   rU   rV   rY   r^   r`   pytestmarkparametrizere   rl   rD   rD   rD   rE   r      s   7	
	r   c                   @   s^   e Zd Zdd Zdd Zdd Zdd Zej	d	d
dgdd Z
dd Zdd Zdd ZdS )TestGridc                 C   s   t ddd }t ddd }t|jdk t|jdk t|d dk t|d d t|d dk t|d |d  dd t|d |d d	 d t|d |d  d
d d S )Nr!   r                 $@r$   )rG   )   r      ggfffff?gqq?)r	   r   r   r   )rB   rg   brD   rD   rE   rF      s    zTestGrid.test_basicc                 C   s8   t jdddd\}}t|d t|tddd d d S )Nr   rG   T)Zretstepg9/?y              I@r1   )r<   Zlinspacer   r   r	   )rB   r]   strD   rD   rE   test_linspace_equivalence   s    
z"TestGrid.test_linspace_equivalencec                 C   sV  t ddddddf }t ddddddf }t|jdk t|jd	k t|d
 d
d d f tdd  t|d d d d
f dtdd  t|d
 dd d f tddd t|d d d df dtdd d t|d
dd d f |d
d
d d f  dtdd d t|dd d df |dd d d
f  dtdd d d S )Nr!   r   rt   r   r$   g?)r   rG   rG   )r   ru   ru   r   rG   drv   ru   )r	   r   r   r   r<   onesr   )rB   cr{   rD   rD   rE   test_nd   s    $&$($$zTestGrid.test_ndc                 C   s\   t ddddddf }tddddddf }tj| }t||D ]\}}t|| qDd S )Nr!   r   rt   rz   r   )r	   r
   r<   Zbroadcast_arrayszipr   )rB   Z	grid_fullZgrid_sparseZgrid_broadcastfrw   rD   rD   rE   test_sparse   s
    
zTestGrid.test_sparsezstart, stop, step, expected)NrG   rt   )   rG   )iru   N)i     c                 C   sJ   t ||||||f }t ||| }t|j|d  t|j|d  d S )Nr   r   )r	   r   size)rB   startstopstepexpectedgridZ
grid_smallrD   rD   rE   test_mgrid_size_none_handling   s    	z&TestGrid.test_mgrid_size_none_handlingc                 C   s   t dddf }t tdtdtdf }t|| |jtjksLJ |jtjks\J t ddd }t tdtdtd }t|jtjk t|| d S )Nr$   Q?)r	   r<   float32r   rI   float64r   )rB   grid64Zgrid32rD   rD   rE   test_accepts_npfloating   s    "
 z TestGrid.test_accepts_npfloatingc                 C   s   t dddf }t tdtdtdf }t|jtjk t|| t dtdd }t dtddf }t|j|j  kotjkn   t||d  t ddd }t tdtdtd }t|jtjk t|| d S )Nr$   r   r   r   y        333333@)r	   r<   
longdoubler   rI   r   r   )rB   r   Zgrid128Z
grid128c_aZ
grid128c_brD   rD   rE   test_accepts_longdouble  s     
"z TestGrid.test_accepts_longdoublec                 C   s   t tdddf tddtdf  t tddd tddtd  tddd }tdddf d }t|j|j  kotjkn   t|| tddtd }tddtdf d }t|j|j  kotj	kn   t|| d S )Nr$   g333333?y              @y        ffffff
@r   )
r   r	   r<   	complex64r   rI   r   r   Zclongdoubler   )rB   Zgrid64_aZgrid64_bZ	grid128_aZ	grid128_brD   rD   rE   test_accepts_npcomplexfloating  s    ""
"z'TestGrid.test_accepts_npcomplexfloatingN)rm   rn   ro   rF   ry   r~   r   rp   rq   rr   r   r   r   r   rD   rD   rD   rE   rs      s   	
rs   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S )TestConcatenatorc                 C   sD   t td tg d td}t|dd|f }t |g 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   r   r<   rA   r|   )rB   rw   r}   rD   rD   rE   test_1d1  s    
zTestConcatenator.test_1dc                 C   s"   t dddf }t|jdk d S )Ng333333$@r   rG   f8)r   r   rI   rB   grD   rD   rE   test_mixed_type7  s    z TestConcatenator.test_mixed_typec                 C   s4   t dtdgtg ddf }t|jdk d S )Ng333333$r   )r   r&   r"   g      $@r   )r   r<   rA   r   rI   r   rD   rD   rE   test_more_mixed_type;  s    "z%TestConcatenator.test_more_mixed_typec                 C   sB   t ddd }t|jdk t ddtd }t|jdk d S )Nr   rQ   y              Y@)d   )r   r   r   r<   r   r   rD   rD   rE   test_complex_step?  s    z"TestConcatenator.test_complex_stepc                 C   s   t jdd}t jdd}td||f }t|jdk t|d d d df | t|d d dd f | t||f }t|jdk t|d dd d f | t|dd d d f | d S )Nr(   1)r(   rG   )rG   r(   )r<   randomrandr   r   r   r   )rB   rw   r}   r{   rD   rD   rE   test_2dH  s    zTestConcatenator.test_2dc                 C   sb   t tdtddf g d t tg dtdf g d t ttdg df g d d S )Nr   r   r   r   r   r   r&   )r   r   r   r&   rZ   )r   r   r<   rA   rX   rD   rD   rE   r`   T  s     zTestConcatenator.test_0dN)	rm   rn   ro   r   r   r   r   r   r`   rD   rD   rD   rE   r   0  s   	r   c                   @   s   e Zd Zdd ZdS )TestNdenumeratec                 C   s0   t ddgddgg}ttt|g d d S )Nr   r   r&   r"   )))r   r   r   ))r   r   r   )r   r&   ))r   r   r"   )r<   rA   r   listr   rB   rg   rD   rD   rE   rF   [  s    zTestNdenumerate.test_basicN)rm   rn   ro   rF   rD   rD   rD   rE   r   Z  s   r   c                   @   s   e Zd Zdd Zdd ZdS )TestIndexExpressionc                 C   sJ   t d}t|d d |td d   t|d d |td d   d S )Nr   r!   )r<   aranger   r   r   r   rD   rD   rE   test_regression_1b  s    
z%TestIndexExpression.test_regression_1c                 C   s   t jddd}t|d d d dddgf |td d d dddgf   t|d d d dddgf |td d d dddgf   d S )Nr"   r(   r'   r&   r   r   )r<   r   r   r   r   r   r   rD   rD   rE   test_simple_1h  s    :z!TestIndexExpression.test_simple_1N)rm   rn   ro   r   r   rD   rD   rD   rE   r   a  s   r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestIx_c                 C   sb   t td\}t|jt j t g \}t|jt j t t jg t jd\}t|jt j d S )Nr   rH   )r<   r   ranger   rI   rR   rA   r   r   rD   rD   rE   r   p  s    zTestIx_.test_regression_1c                    s   d}t tjfD ]| tj fdd|D  }tt||D ]P\\}}t|j | tt	fddt|jD  tt
|jtj q8qd S )N)r"   r(   r&   r   c                    s   g | ]} |qS rD   rD   )rf   sz)funcrD   rE   
<listcomp>  ri   z0TestIx_.test_shape_and_dtype.<locals>.<listcomp>c                 3   s"   | ]\}}| kr|d kV  qdS )r   NrD   )rf   jsh)krD   rE   rh     ri   z/TestIx_.test_shape_and_dtype.<locals>.<genexpr>)r   r<   r   r   	enumerater   r   r   r   rk   Z
issubdtyperI   integer)rB   sizesZarraysrg   r   rD   )r   r   rE   test_shape_and_dtype|  s     zTestIx_.test_shape_and_dtypec                 C   s,   g d}t |\}tt |d | d S )N)TFTTr   )r<   Znonzeror   r   )rB   Zbool_aZint_arD   rD   rE   	test_bool  s    zTestIx_.test_boolc                 C   s"   g dg dg}t ttj| d S )NrZ   r"   r(   r'   )r   r@   r<   r   )rB   Zidx2drD   rD   rE   test_1d_only  s    zTestIx_.test_1d_onlyc                 C   sR   d}t |}t||}t|d j|df t|d jd|f t|j|f d S )Nr(   r   r   )r<   r   r   r   r   )rB   Zlength_of_vectorr\   outrD   rD   rE   test_repeated_input  s    

zTestIx_.test_repeated_inputN)rm   rn   ro   r   r   r   r   r   rD   rD   rD   rE   r   o  s
   
r   c                  C   s<   t tg dgddtg dgf } t| g dg d S )NrZ   r   r   )r   r   r&   r   r   r"   r(   r'   )r   r<   rA   r   )rg   rD   rD   rE   test_c_  s    (r   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 )TestFillDiagonalc                 C   s<   t dt}t|d t|t g dg dg dg d S )N)r&   r&   r(   r(   r   r   r   r(   r   r   r   r(   r<   rc   rL   r   r   rA   r   rD   rD   rE   rF     s    
zTestFillDiagonal.test_basicc                 C   sf   t dt}t|d t|t g dg dg dg dg dg dg dg dg dg dg
 d S )NrJ   r(   r   r   r   r   r   r   r   r   rD   rD   rE   test_tall_matrix  s    
z!TestFillDiagonal.test_tall_matrixc                 C   sh   t dt}t|dd t|t g dg dg dg dg dg dg dg dg dg dg
 d S )NrJ   r(   Tr   r   r   r   r   r   rD   rD   rE   test_tall_matrix_wrap  s    z&TestFillDiagonal.test_tall_matrix_wrapc                 C   s<   t dt}t|d t|t g dg dg dg d S )N)r&   rG   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   rD   rD   rE   test_wide_matrix  s    
z!TestFillDiagonal.test_wide_matrixc                 C   sD   t dt}t|d t g d}tt |dk||||f d S )N)r&   r&   r&   r&   r"   r   r   )r<   rc   rL   r   rA   r   where)rB   rg   irD   rD   rE   test_operate_4d_array  s    
z&TestFillDiagonal.test_operate_4d_arrayc                 C   sD   t dt}ttd t|d W d    n1 s60    Y  d S )Nr&   at least 2-dr(   r<   rc   rL   r   r@   r   r   rD   rD   rE   test_low_dim_handling  s    z&TestFillDiagonal.test_low_dim_handlingc                 C   sD   t dt}ttd t|d W d    n1 s60    Y  d S )N)r&   r&   r)   r&   equal lengthr   r   r   rD   rD   rE   test_hetero_shape_handling  s    z+TestFillDiagonal.test_hetero_shape_handlingN)
rm   rn   ro   rF   r   r   r   r   r   r   rD   rD   rD   rE   r     s   		r   c               	   C   s   t d} tg dg dg dg dg}d|| < t|tg dg dg d	g d
g t dd}tdt}d||< t|tddgddggddgddggg d S )Nr"   )r   r   r&   r"   )r(   r'   r)   r:   )r;   rG   rv   r9   )r1            r   )r   r   r&   r"   )r(   r   r)   r:   )r;   rG   r   r9   )r1   r   r   r   r   r&   )r   r   r   r   r   )r   r<   rA   r   rc   rL   )Zdirg   Zd3rD   rD   rE   test_diag_indices  s4    

r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestDiagIndicesFromc                 C   s<   t jd}t|\}}t|t d t|t d d S )Nr7   r"   )r<   r   r   r   r   )rB   r\   rr}   rD   rD   rE   test_diag_indices_from  s    z*TestDiagIndicesFrom.test_diag_indices_fromc                 C   s@   t d}ttd t| W d    n1 s20    Y  d S )Nr)   r   )r<   r|   r   r@   r   r_   rD   rD   rE   test_error_small_input	  s    
z*TestDiagIndicesFrom.test_error_small_inputc                 C   sB   t dt}ttd t| W d    n1 s40    Y  d S )N)r&   r&   r   r&   r   )r<   rc   rL   r   r@   r   r_   rD   rD   rE   test_error_shape_mismatch  s    z-TestDiagIndicesFrom.test_error_shape_mismatchN)rm   rn   ro   r   r   r   rD   rD   rD   rE   r     s   r   c                  C   s   t tddd} dd ttdD }t| | t td} t| | t td} t| t td t t } t| dg t td} t| dg t td	g } t| g  d S )
Nr   r   r&   c                 S   s   g | ]\}}|qS rD   rD   )rf   ZixerD   rD   rE   r     ri   z test_ndindex.<locals>.<listcomp>rZ   )r&   rD   r   )r   r   r   r<   rc   r   r   )r\   r   rD   rD   rE   test_ndindex  s    


r   )#rp   numpyr<   Znumpy.testingr   r   r   r   r   r   r   Znumpy.lib._index_tricks_implr	   r
   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   r   r   r   r   r   r   r   rD   rD   rD   rE   <module>   s   $8 .u**G