3
KdG                 @   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
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 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assert_warns)mgridogridndenumeratefill_diagonaldiag_indicesdiag_indices_from	index_expndindexr_s_ix_c               @   sh   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jddddgdd Zdd ZdS )TestRavelUnravelIndexc          #   C   s  t tjdd%d& tt t tjdd'dd( W d Q R X t tjdd)dd* tt tjdd+d W d Q R X tt tjdd,d W d Q R X tt tjdd-d W d Q R X t tjd.d/d t tjdd0d1 t tjd2d3d tttjd4d5 tttjdd6 tttjdd7 tttjd9d: tttjd;d< tttjd>d? tttjd@dA tttjdBdC t tjdGdHdddg t tjdddgdIdM tj	dddgdddgg}t tj|dNdddg t tj|dOdddddg t tj|dPdddddg t tj|dQdRdd!ddg t tjdSdTd$ t tjtj	dddgdUdddgdddgg t tjtj	dddgdVdddddgdddgg t tjd$dWddddg d S )XN      r   )indicesZdims)r   shape)r   hape)r         ^   )ZimsB   g      ?      皙?                    )   %   F)order      clip)mode      wrap      	   iU  )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   )r6   r   )r   r   )r   r   )r   r   r6   )r   r6   )r   r   )r   r   )r   r   )r!   r"   )r   r   r#   r%   *   .   )r   r    r#   )r   r    r#   r#   r%   r7   r8   )r%   r#   )r%   r#   )r   r#   )r   r   )r-   r1   )r    r   r   r   )r#   r%   r3   r4   )r%   r#   )r%   r#   )r#   r%   r3   r4   )
r   npunravel_indexr	   DeprecationWarningr   	TypeErrorravel_multi_index
ValueErrorarray)selfarr rB   U/var/www/html/virt/lib64/python3.6/site-packages/numpy/lib/tests/test_index_tricks.py
test_basic   sV    



z TestRavelUnravelIndex.test_basicc             C   s  d}d}t t|tjg d t t|tjf d	 t t|tjtjg d
 ttj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jg tjg fd ttjtjg tdtjg tdfdg  ttj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$   )dtypeabc)rE   r    r$   )rE   r    r$   )rE   r    r$   )rE   r    r$   )rE   r    )rE   r    )r$   r    )r$   r    )r$   r    )r   r<   r9   r:   r?   r   intr=   )r@   Zmsg1Zmsg2rB   rB   rC   test_empty_indicesN   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 j|dddg ttt jdd d
gd
gf}t jt jj	d }tt j||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   r0   r   iK	  i  r   r'   r%   x   $   
  r3   r#   l   z l   nm     r+   r)   )r*   )r'   r%   rL   rM   rN   r3   r#   l            l               )rP   rQ   )
r9   intpint64r   r=   r   r>   r:   Ziinfomax)r@   rA   Z	dummy_arrZhalf_maxrB   rB   rC   test_big_indicesb   s"    

z&TestRavelUnravelIndex.test_big_indicesc          
   C   s  xt jt jt jt jt jt jgD ]v}t jddddddgddddddgg|d}d}d	|d  |d  }tt j	||| t|t j
|| |d d|d   }tt j	||d
d| t|t j
||d
d t jddddddgddddddgddddddgg|d}d}dd	|d  |d   |d  }tt j	||| t|t j
|| |d d|d d	|d     }tt j	||d
d| t|t j
||d
d q W d S )Nr   r   r   r    r   r#   )rF   r$   r3   r)   )r*   r4   rE   )r$   r3   )r$   r3   rE   )r9   Zint16Zuint16Zint32Zuint32rS   Zuint64r?   r   r=   r:   )r@   rF   Zcoordsr   ZuncoordsrB   rB   rC   test_dtypesz   s.    &,  z!TestRavelUnravelIndex.test_dtypesc             C   sx   t tjddddgddd	tjddd
dgd t tjddddgddd	tjddddgd tttjddddgd d S )Nr$   r   r   r   r    r%   r2   r1   )r.   r#   raiser-   r   r5   )r   r    r%   r2   )r   r    r%   r2   r5   )r   r    r%   r2   )r1   rW   r-   rW   )r   r    r%   r2   r5   )r   r    r%   r2   )r   r9   r=   r   r>   )r@   rB   rB   rC   test_clipmodes   s    z$TestRavelUnravelIndex.test_clipmodesc             C   s2   t jdddgd\}}t|jj t|jj d S )Nr   r   r    r   r$   )r   r$   )r9   r:   r   flagsZ	writeable)r@   xyrB   rB   rC   test_writeability   s    z'TestRavelUnravelIndex.test_writeabilityc             C   sB   t jdf }t|f  ttdt jdgf  ttdt jdgf  d S )Nr   z0d arrayzout of boundsr   )r9   r:   r   r   r>   )r@   rZ   rB   rB   rC   test_0d   s
    
zTestRavelUnravelIndex.test_0dr.   r-   r1   rW   c             C   s^   t jt jdt jdd|d}|jd	ks*ttt" t jt jd
t jdd|d W d Q R X d S )Nr    r   )rF   r   r   )r.   )r    r   )r   r   r   )r   )r    r   )r   r   r   )r9   r=   zerosrR   r   AssertionErrorr   r>   )r@   r.   resrB   rB   rC   test_empty_array_ravel   s    
z,TestRavelUnravelIndex.test_empty_array_ravelc             C   sd   t jt jdt jdd}t|dks(ttdd |D s>ttt t jdgd	 W d Q R X d S )
Nr   )rF   r   r   r    c             s   s   | ]}|j dkV  qdS )r   N)r   )r   ).0arB   rB   rC   	<genexpr>   s    zATestRavelUnravelIndex.test_empty_array_unravel.<locals>.<genexpr>)r   r   r   )r   r   r   )	r9   r:   r^   rR   lenr_   allr   r>   )r@   r`   rB   rB   rC   test_empty_array_unravel   s
    
z.TestRavelUnravelIndex.test_empty_array_unravelN)__name__
__module____qualname__rD   rI   rU   rV   rX   r\   r]   pytestmarkparametrizera   rg   rB   rB   rB   rC   r      s   >	
r   c               @   sF   e Zd Zdd Zdd Zdd Zdd Zejj	d	ddg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   y              $@g?rE      r      r0   g       @g      "@r5   r5   )rE   )ro   r5   r5   r5   r5   ggfffff?gqq?)r
   r   r   r   )r@   rc   brB   rB   rC   rD      s    zTestGrid.test_basicc             C   s8   t jdddd\}}t|d	 t|tddd d d S )
Nr   rE   T)Zretstepr3   g     H@y              I@r,   g9/?)r9   Zlinspacer   r   r
   )r@   r[   strB   rB   rC   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jdd	  t|d d d df dtjdd	  t|d dd d f tjdd	d
 t|d d d df dtjdd	 d
 t|ddd d f |ddd d f  dtjdd	 d
 t|dd d df |dd d df  dtjdd	 d
 d S )Nr   y              $@r   g?g?rE   ro   r   drp   r5   r5   ru   )r   rE   rE   )r   ro   ro   ru   r5   r5   )r
   r   r   r   r9   onesr   )r@   crt   rB   rB   rC   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| }x t||D ]\}}t|| qFW d S )Nr   y              $@r   r5   ru   r5   ru   )r
   r   r9   Zbroadcast_arrayszipr   )r@   Z	grid_fullZgrid_sparseZgrid_broadcastfrq   rB   rB   rC   test_sparse   s
    
zTestGrid.test_sparsezstart, stop, step, expectedNrE                 $@   ro        c             C   sJ   t ||||||f }t ||| }t|j|d  t|j|d  d S )Nr   r   )r
   r   size)r@   startstopstepexpectedZgridZ
grid_smallrB   rB   rC   test_mgrid_size_none_handling   s    	z&TestGrid.test_mgrid_size_none_handlingr}   rE   )NrE   r|   r   r~   r   )r   ro   Nr   )rh   ri   rj   rD   rs   rx   r{   rk   rl   rm   r   rB   rB   rB   rC   rn      s   	rn   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   s`   t td tjddddddg tjd}t|dd|f }t |ddddddddddddg d S )	Nr   r   r    r   r$   r#   r   )r   r   r    r   r$   r#   )r   r   r9   r?   rv   )r@   rq   rw   rB   rB   rC   test_1d   s     
zTestConcatenator.test_1dc             C   s"   t dddf }t|jdk d S )Ng333333$@r   rE   f8)r   r   rF   )r@   grB   rB   rC   test_mixed_type  s    z TestConcatenator.test_mixed_typec             C   s6   t dtjdgtjdddgdf }t|jdk d S )	Ng333333$@r   r   r    r   g      $@r   g333333$)r   r9   r?   r   rF   )r@   r   rB   rB   rC   test_more_mixed_type  s    $z%TestConcatenator.test_more_mixed_typec             C   s    t ddd }t|jdk d S )Nr   rM   y              Y@d   )r   )r   r   r   )r@   r   rB   rB   rC   test_complex_step  s    z"TestConcatenator.test_complex_stepc             C   s   t jjdd}t j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$   1rE   )r$   rE   )rE   r$   )r9   randomrandr   r   r   r   )r@   rq   rw   rt   rB   rB   rC   test_2d  s    zTestConcatenator.test_2dc             C   sp   t tdtjddf dddg t tdddgtjdf ddddg t ttjddddgf ddddg d S )Nr   r   r   r    )r   r   r9   r?   )r@   rB   rB   rC   r]     s     &zTestConcatenator.test_0dN)	rh   ri   rj   r   r   r   r   r   r]   rB   rB   rB   rC   r      s   r   c               @   s   e Zd Zdd ZdS )TestNdenumeratec             C   s4   t jddgddgg}ttt|dd	ddg d S )Nr   r   r    r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r    r   r   )r   r   )r9   r?   r   listr   )r@   rc   rB   rB   rC   rD   $  s    zTestNdenumerate.test_basicN)rh   ri   rj   rD   rB   rB   rB   rC   r   #  s   r   c               @   s   e Zd Zdd Zdd ZdS )TestIndexExpressionc             C   sJ   t jd}t|d d |td d   t|d d |td d   d S )Nr   r   r5   r5   r5   r5   )r9   aranger   r   r   )r@   rc   rB   rB   rC   test_regression_1+  s    
z%TestIndexExpression.test_regression_1c             C   s   t j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   )r9   r   r   r   r   r   )r@   rc   rB   rB   rC   test_simple_11  s    :z!TestIndexExpression.test_simple_1N)rh   ri   rj   r   r   rB   rB   rB   rC   r   *  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 jtd\}t|jt j t jg \}t|jt j t jt jg t jd\}t|jt j d S )Nr   )rF   )r9   r   ranger   rF   rR   r?   Zfloat32)r@   rc   rB   rB   rC   r   9  s    zTestIx_.test_regression_1c                s   d	}xt tjfD ] tj fdd|D  }xbtt||D ]P\\}}t|j | tt	fddt|jD  ttj
|jtj q<W qW d S )
Nr   r$   r    r   c                s   g | ]} |qS rB   rB   )rb   sz)funcrB   rC   
<listcomp>I  s    z0TestIx_.test_shape_and_dtype.<locals>.<listcomp>c             3   s"   | ]\}}| kr|d kV  qdS )r   NrB   )rb   jsh)krB   rC   rd   L  s    z/TestIx_.test_shape_and_dtype.<locals>.<genexpr>)r   r$   r    r   )r   r9   r   r   	enumeratery   r   r   r   rf   Z
issubdtyperF   integer)r@   sizesZarraysrc   r   rB   )r   r   rC   test_shape_and_dtypeE  s     zTestIx_.test_shape_and_dtypec             C   s0   ddddg}t j|\}tt j|d | d S )NTFr   )r9   Znonzeror   r   )r@   Zbool_aZint_arB   rB   rC   	test_boolO  s    zTestIx_.test_boolc             C   s&   dddgdddgg}t ttj| d S )Nr   r   r    r   r$   r#   )r   r>   r9   r   )r@   Zidx2drB   rB   rC   test_1d_onlyT  s    zTestIx_.test_1d_onlyc             C   sR   d}t j|}t||}t|d j|df t|d jd|f t|j|f d S )Nr$   r   r   )r9   r   r   r   r   )r@   Zlength_of_vectorrZ   outrB   rB   rC   test_repeated_inputX  s    

zTestIx_.test_repeated_inputN)rh   ri   rj   r   r   r   r   r   rB   rB   rB   rC   r   8  s
   
r   c           
   C   sN   t jt jdddggddt jdddggf } t| ddddddddgg d S )Nr   r   r    r   r   r$   r#   )r9   Zc_r?   r   )rc   rB   rB   rC   test_c_b  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   sB   t jdt}t|d t|t jdddgdddgdddgg d S )Nr    r$   r   )r    r    )r9   r^   rH   r   r   r?   )r@   rc   rB   rB   rC   rD   h  s    
zTestFillDiagonal.test_basicc             C   sz   t jdt}t|d t|t jdddgdddgdddgdddgdddgdddgdddgdddgdddgdddgg
 d S )NrE   r    r$   r   )rE   r    )r9   r^   rH   r   r   r?   )r@   rc   rB   rB   rC   test_tall_matrixq  s    
z!TestFillDiagonal.test_tall_matrixc             C   s|   t jdt}t|dd t|t jdddgdddgdddgdddgdddgdddgdddgdddgdddgdddgg
 d S )NrE   r    r$   Tr   )rE   r    )r9   r^   rH   r   r   r?   )r@   rc   rB   rB   rC   test_tall_matrix_wrap  s    z&TestFillDiagonal.test_tall_matrix_wrapc             C   sl   t jdt}t|d t|t j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 d S )Nr    rE   r$   r   )r    rE   )r9   r^   rH   r   r   r?   )r@   rc   rB   rB   rC   test_wide_matrix  s    
z!TestFillDiagonal.test_wide_matrixc             C   sF   t jdt}t|d t jdddg}tt j|dk||||f d S )Nr    r   r   r   r   )r    r    r    r    )r9   r^   rH   r   r?   r   where)r@   rc   irB   rB   rC   test_operate_4d_array  s    
z&TestFillDiagonal.test_operate_4d_arrayc          
   C   s0   t jdt}ttd t|d W d Q R X d S )Nr    zat least 2-dr$   )r9   r^   rH   r   r>   r   )r@   rc   rB   rB   rC   test_low_dim_handling  s    z&TestFillDiagonal.test_low_dim_handlingc          
   C   s0   t jdt}ttd t|d W d Q R X d S )Nr    r%   zequal lengthr   )r    r    r%   r    )r9   r^   rH   r   r>   r   )r@   rc   rB   rB   rC   test_hetero_shape_handling  s    z+TestFillDiagonal.test_hetero_shape_handlingN)
rh   ri   rj   rD   r   r   r   r   r   r   rB   rB   rB   rC   r   g  s   		r   c           
   C   s   t d} tjddddgddddgd	d
ddgddddgg}d|| < t|tjddddgddddgd	d
ddgddddgg t dd}tjdt}d||< t|tjddgddggddgddggg d S )Nr   r   r   r    r$   r#   r%   r3   r4   rE   rp   r2   r,            r   r   )r   r   r   )r   r9   r?   r   r^   rH   )Zdirc   Zd3rB   rB   rC   test_diag_indices  s&    




r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestDiagIndicesFromc             C   s<   t jjd}t|\}}t|t jd t|t jd d S )Nr   )r   r   )r9   r   r   r   r   )r@   rZ   rrw   rB   rB   rC   test_diag_indices_from  s    z*TestDiagIndicesFrom.test_diag_indices_fromc          	   C   s,   t jd}ttd t| W d Q R X d S )Nr%   zat least 2-d)r9   rv   r   r>   r   )r@   rZ   rB   rB   rC   test_error_small_input  s    
z*TestDiagIndicesFrom.test_error_small_inputc          	   C   s.   t jdt}ttd t| W d Q R X d S )Nr    r   zequal length)r    r    r   r    )r9   r^   rH   r   r>   r   )r@   rZ   rB   rB   rC   test_error_shape_mismatch  s    z-TestDiagIndicesFrom.test_error_shape_mismatchN)rh   ri   rj   r   r   r   rB   rB   rB   rC   r     s   r   c              C   s   t tddd} dd ttjdD }t| | t td} t| | t td	} t| t td t t } t| f g t tf } t| f g t tdg } t| g  d S )
Nr   r   r    c             S   s   g | ]\}}|qS rB   rB   )rb   ixerB   rB   rC   r     s    z test_ndindex.<locals>.<listcomp>r   )r   r   r    )r   r   r    )r    )r   r   r   r9   r^   r   r   )rZ   r   rB   rB   rC   test_ndindex  s    


r   )#rk   Znumpyr9   Znumpy.testingr   r   r   r   r   r   r   r	   Znumpy.lib.index_tricksr
   r   r   r   r   r   r   r   r   r   r   r   rn   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   <module>   s   (4 5:&*G