o
    DfO                     @   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 s)w   Y  tt tjddd W d    n1 sDw   Y  tt tjddd	 W d    n1 s_w   Y  tt tjddd
 W d    n1 szw   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      )   ^   )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#   )r3   wrap)   r2   r2   )r'   r   r#   r   )r(   r*      	   iU  )r   npunravel_indexr   	TypeErrorravel_multi_index
ValueErrorarray)selfarr rE   Z/home/ubuntu/webapp/venv/lib/python3.10/site-packages/numpy/lib/tests/test_index_tricks.py
test_basic   sj   



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)   rE   dtyperH   r'   abc)r)   r'   )r   r?   r=   r>   rB   r   intr@   )rC   msg1msg2rE   rE   rF   test_empty_indicesF   s:   
z(TestRavelUnravelIndex.test_empty_indicesc                 C   s   t jt jkr(d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   r7   r   iK	  i  r   )r,   r*   x   $   i
  r;   r(   l   z l   nm )l    l       r.   r/   )
r=   intpint64r   r@   r   rA   r>   iinfomax)rC   rD   	dummy_arrhalf_maxrE   rE   rF   test_big_indicesZ   s.   

z&TestRavelUnravelIndex.test_big_indicesc                 C   sp  t jt jt jt jt jt jfD ]}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   rI   )r)   r;   r;   r   r   r)   r.   r/   )r   r'   r   r   r<   r)   )r)   r;   rH   rH   r   )r=   int16uint16int32uint32rV   uint64rB   r   r@   r>   )rC   rJ   coordsr   uncoordsrE   rE   rF   test_dtypesr   s:     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*   r:   r9   r4   )r   r   r(   r   )r9   raiser3   rd   )r   r   r   r   )r   r=   r@   r   rA   rC   rE   rE   rF   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   flags	writeable)rC   xyrE   rE   rF   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   rE   z0d arrayzout of boundsr   )r=   r>   r   r   rA   rC   rj   rE   rE   rF   test_0d   s   
zTestRavelUnravelIndex.test_0dr5   )r3   r9   rd   c                 C   st   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    d S 1 s3w   Y  d S )N)r'   r   rI   r   r   r   r4   r   )r'   r   )r=   r@   zerosrU   r   r   rA   )rC   r5   resrE   rE   rF   test_empty_array_ravel   s   
"z,TestRavelUnravelIndex.test_empty_array_ravelc                 C   sz   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    d S 1 s6w   Y  d S )Nr   rI   ro   r'   c                 s   s    | ]}|j d kV  qdS )rp   N)r   ).0arE   rE   rF   	<genexpr>   s    zATestRavelUnravelIndex.test_empty_array_unravel.<locals>.<genexpr>r   )r=   r>   rq   rU   lenallr   rA   )rC   rr   rE   rE   rF   test_empty_array_unravel   s   
"z.TestRavelUnravelIndex.test_empty_array_unravelN)__name__
__module____qualname__rG   rP   r[   rc   rf   rl   rn   pytestmarkparametrizers   ry   rE   rE   rE   rF   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%   )rH   )   r      ggfffff?gqq?)r	   r   r   r   )rC   ru   brE   rE   rF   rG      s   zTestGrid.test_basicc                 C   s8   t jdddd\}}t|d t|tddd d d S )Nr   rH   T)retstepg9/?y              I@r2   )r=   linspacer   r   r	   )rC   rk   strE   rE   rF   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   r   r   r%   g?)r   rH   rH   )r   r   r   r   rH   dr   r   )r	   r   r   r   r=   onesr   )rC   cr   rE   rE   rF   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|| q"d S )Nr"   r   r   r   r   )r	   r
   r=   broadcast_arrayszipr   )rC   	grid_fullgrid_sparsegrid_broadcastfr   rE   rE   rF   test_sparse   s   
zTestGrid.test_sparsezstart, stop, step, expected)NrH   r   )   rH   )ir   N)i     c                 C   sJ   t ||||||f }t ||| }t|j|d  t|j|d  d S )Nr   r   )r	   r   size)rC   startstopstepexpectedgrid
grid_smallrE   rE   rF   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s&J |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   rJ   float64r   )rC   grid64grid32rE   rE   rF   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oHt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   rJ   r   r   )rC   r   grid128
grid128c_a
grid128c_brE   rE   rF   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oDtjkn   t|| tddtd }tddtdf d }t|j|j  koqtj	kn   t|| d S )Nr%   g333333?y              @y        ffffff
@r   )
r   r	   r=   	complex64r   rJ   r   r   clongdoubler   )rC   grid64_agrid64_b	grid128_a	grid128_brE   rE   rF   test_accepts_npcomplexfloating  s   ""
"z'TestGrid.test_accepts_npcomplexfloatingN)rz   r{   r|   rG   r   r   r   r}   r~   r   r   r   r   r   rE   rE   rE   rF   r      s    	
r   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=   rB   r   )rC   r   r   rE   rE   rF   test_1d1  s   
zTestConcatenator.test_1dc                 C   s"   t dddf }t|jdk d S )Ng333333$@r   rH   f8)r   r   rJ   rC   grE   rE   rF   test_mixed_type7     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=   rB   r   rJ   r   rE   rE   rF   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   rT   y              Y@)d   )r   r   r   r=   r   r   rE   rE   rF   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)   rH   )rH   r)   )r=   randomrandr   r   r   r   )rC   r   r   r   rE   rE   rF   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'   rg   )r   r   r=   rB   re   rE   rE   rF   rn   T  s    $zTestConcatenator.test_0dN)	rz   r{   r|   r   r   r   r   r   rn   rE   rE   rE   rF   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=   rB   r   listr   rC   ru   rE   rE   rF   rG   [  s   zTestNdenumerate.test_basicN)rz   r{   r|   rG   rE   rE   rE   rF   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   rE   rE   rF   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   rE   rE   rF   test_simple_1h  s   :>z!TestIndexExpression.test_simple_1N)rz   r{   r|   r   r   rE   rE   rE   rF   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   rI   )r=   r   ranger   rJ   rU   rB   r   r   rE   rE   rF   r   p  s   zTestIx_.test_regression_1c                    s   d}t tjfD ]> tj fdd|D  }tt||D ](\\}}t|j | tt	fddt|jD  tt
|jtj qqd S )N)r#   r)   r'   r   c                    s   g | ]} |qS rE   rE   )rt   sz)funcrE   rF   
<listcomp>      z0TestIx_.test_shape_and_dtype.<locals>.<listcomp>c                 3   s$    | ]\}}| kr|d kV  qdS )r   NrE   )rt   jsh)krE   rF   rv     s   " z/TestIx_.test_shape_and_dtype.<locals>.<genexpr>)r   r=   r   r   	enumerater   r   r   r   rx   
issubdtyperJ   integer)rC   sizesarraysru   r   rE   )r   r   rF   test_shape_and_dtype|  s    zTestIx_.test_shape_and_dtypec                 C   s,   g d}t |\}tt |d | d S )N)TFTTr   )r=   nonzeror   r   )rC   bool_aint_arE   rE   rF   	test_bool  s   zTestIx_.test_boolc                 C   s"   g dg dg}t ttj| d S )Nrg   r#   r)   r(   )r   rA   r=   r   )rC   idx2drE   rE   rF   test_1d_only  r   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   )rC   length_of_vectorrj   outrE   rE   rF   test_repeated_input  s   

zTestIx_.test_repeated_inputN)rz   r{   r|   r   r   r   r   r   rE   rE   rE   rF   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 )Nrg   r   r   )r   r   r'   r   r   r#   r)   r(   )r   r=   rB   r   )ru   rE   rE   rF   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   <   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=   rq   rM   r   r   rB   r   rE   rE   rF   rG        
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 )NrK   r)   r   r   r   r   r   r   r   r   rE   rE   rF   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 )NrK   r)   Tr   r   r   r   r   r   rE   rE   rF   test_tall_matrix_wrap  s   z&TestFillDiagonal.test_tall_matrix_wrapc                 C   r   )N)r'   rH   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   rE   rE   rF   test_wide_matrix  r   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=   rq   rM   r   rB   r   where)rC   ru   irE   rE   rF   test_operate_4d_array  s   
 z&TestFillDiagonal.test_operate_4d_arrayc                 C   F   t dt}ttd t|d W d    d S 1 sw   Y  d S )Nr'   at least 2-dr)   r=   rq   rM   r   rA   r   r   rE   rE   rF   test_low_dim_handling  s   "z&TestFillDiagonal.test_low_dim_handlingc                 C   r   )N)r'   r'   r*   r'   equal lengthr   r   r   rE   rE   rF   test_hetero_shape_handling  s   "z+TestFillDiagonal.test_hetero_shape_handlingN)
rz   r{   r|   rG   r   r   r   r   r   r   rE   rE   rE   rF   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<   rH   r   r:   )r2            r   )r   r   r'   r#   )r)   r   r*   r;   )r<   rH   r   r:   )r2   r   r   r   r   r'   )r   r   r   r   r   )r   r=   rB   r   rq   rM   )diru   d3rE   rE   rF   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 )Nr8   r#   )r=   r   r   r   r   )rC   rj   rr   rE   rE   rF   test_diag_indices_from  s   z*TestDiagIndicesFrom.test_diag_indices_fromc                 C   sB   t d}ttd t| W d    d S 1 sw   Y  d S )Nr*   r   )r=   r   r   rA   r   rm   rE   rE   rF   test_error_small_input	  s   

"z*TestDiagIndicesFrom.test_error_small_inputc                 C   sD   t dt}ttd t| W d    d S 1 sw   Y  d S )N)r'   r'   r   r'   r   )r=   rq   rM   r   rA   r   rm   rE   rE   rF   test_error_shape_mismatch  s   
"z-TestDiagIndicesFrom.test_error_shape_mismatchN)rz   r{   r|   r   r   r   rE   rE   rE   rF   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 rE   rE   )rt   ixerE   rE   rF   r     r   z test_ndindex.<locals>.<listcomp>rg   )r'   rE   r   )r   r   r   r=   rq   r   r   )rj   r   rE   rE   rF   test_ndindex  s   


r  )#r}   numpyr=   numpy.testingr   r   r   r   r   r   r   numpy.lib._index_tricks_implr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rE   rE   rE   rF   <module>   s     $8 .u**G