o
    g1                    @   s  d Z ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddl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 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-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? G dd	 d	Z@G d
d dZAG dd dZBG dd dZCG dd dZDG dd dZEG dd dZFG dd dZGG dd dZHG dd dZIG dd dZJG dd dZKG d d! d!ZLG d"d# d#ZMG d$d% d%ZNdS )&zTests suite for MaskedArray.
Adapted from the original test_ma by Pierre Gerard-Marchant

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: test_extras.py 3473 2007-10-29 15:18:13Z jarrod.millman $

    N)normalize_axis_tuple)assert_warnssuppress_warnings)assert_assert_array_equalassert_equalassert_almost_equal)arrayarangemaskedMaskedArraymasked_arraygetmaskarrayshapenomaskoneszeroscount)#
atleast_1d
atleast_2d
atleast_3dmr_dotpolyfitcovcorrcoefmedianaverageuniquesetxor1d	setdiff1dunion1dintersect1din1dediff1dapply_over_axesapply_along_axiscompress_ndcompress_rowcolsmask_rowcolsclump_maskedclump_unmaskedflatnotmasked_contiguousnotmasked_contiguousnotmasked_edges
masked_allmasked_all_likeisindiagflatndenumeratestackvstack
_covhelperc                   @   sL   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S )TestGenericc                 C   sJ  t dtd}tddgddgtd}t|| tddgddgd}t d|d}td	d	gd
d
g|d}t|| t d|d}td	d	gd	d	ggd
d
gd
d
gg|d}t|| tddddgfg}t d|d}tddgddg|d}t|| t d|d}tddgddg|d}t|| t d
|d}tdggdgg|d}t|| d S )N   dtype   maskr;   abfnamesformatsr   r   r<   r<   r9   r9   r?   rA   barA   bbrA   r<   rF   )r/   floatr	   r   npr;   )selftestcontroldt rT   T/var/www/html/api-tag/env/lib/python3.10/site-packages/numpy/ma/tests/test_extras.pytest_masked_all&   s6   




zTestGeneric.test_masked_allc                 C   s   t ddtfgdffg}t jd|}tt|d t jjj tt|d d t jjj tt	|d d d t|d d j
d t|d d jj
d d S )Nr@   cr<   r<   rF   rT   rO   r;   objectmar/   r   typecorer   lenr   _fill_valuerP   my_dtype
masked_arrrT   rT   rU   "test_masked_all_with_object_nestedD   s   z.TestGeneric.test_masked_all_with_object_nestedc                 C   sr   t dtdffg}t jd|}tt|d t jjj tt	|d d t|d j
d t|d jj
d d S )Nr@   rX   r<   rF   rT   rY   r`   rT   rT   rU   test_masked_all_with_objectP   s   z'TestGeneric.test_masked_all_with_objectc                 C   s   t ddgtd}t|}t ddgddgtd}t|| tddgddgd}t d	d	gd
d
g|d}t|}t ddgd
d
g|d}t|| tddddgfg}t ddgddg|d}t|}t|| d S )Nr<   r9   r:   r=   r?   r@   rA   rB   rE   rF   )
   re   rH   rI   rK   rM   )r	   rN   r0   r   rO   r;   )rP   baserQ   rR   rS   rT   rT   rU   test_masked_all_likeZ   s   

z TestGeneric.test_masked_all_likec           	      C   s   t ddD ]W}t d| D ]N}tj|td}tj||td}td| }|d| @ dk|_d}||D ]}||j|  7 }q3|t	krMt
|  | q|j |_t
|  | qqd S )Nr<      r9   r:   r   )rangerO   r
   intfullr   r>   datasumr+   r   
compressed)	rP   rA   ijkjar?   sslrT   rT   rU   check_clumpn   s   
zTestGeneric.check_clumpc                 C   sV   t td}t|g d< t|}tddtddtddg}t|| | t d S )Nre   r   r<   r9         	   r      rw   rh   rx   )r   rO   r
   r   r*   slicer   ru   rP   r?   rQ   rR   rT   rT   rU   test_clump_masked~   s   
zTestGeneric.test_clump_maskedc                 C   sN   t td}t|g d< t|}tddtddg}t|| | t d S )Nre   rv   rz   rw   rh   rx   )r   rO   r
   r   r+   r{   r   ru   r|   rT   rT   rU   test_clump_unmasked   s   
zTestGeneric.test_clump_unmaskedc                 C   s   t d}t|}t|td|jg tjdtd|_t|td|jg t	||dk |dkB |dkB < t|}t|tddtddg t	|d d < t|}t|g  d S )	Nre   r   r:   rz   rx      rw   ry   )
r
   r,   r   r{   sizerO   r   boolr>   r   )rP   r?   rQ   rT   rT   rU   test_flatnotmasked_contiguous   s   z)TestGeneric.test_flatnotmasked_contiguousN)__name__
__module____qualname__rV   rc   rd   rg   ru   r}   r~   r   rT   rT   rT   rU   r7   $   s    

r7   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d Z	e
jdg dddgg ddgdgfg dg dgdg dgddgg dgg dgfgdd Zd d! ZdS )"TestAveragec                 C   s$  t g dg dd}tdt|dd tdt|g dd t|g dd	d
\}}td| t|dk t|d d < tt|ddjd	g t g dg dd}|dd}t|d d df< tt|ddddg tt|ddjd d	g tddgt|dd t|dd	d\}}t|ddg d S )N)              ?       @      @)TFFFr>   r   r   axis)r   r   r   r   weightsTr   returned      @r9   r<   r   r   r   r   )r	   r   r   r   r   r>   reshape)rP   ottresultwtsrT   rT   rU   test_testAverage1   s    
zTestAverage.test_testAverage1c                 C   sB  g d}g dg dg}t dtjd}tt|ddd tt|d|dd tt dtjdd	t d g}tt|d tjt dd
 d  tt|ddt dd
 d	  tt|ddt|ddt|ddd	 g tt|d |dd tt|d|dg d tt|ddt|ddt|ddd	 g td}g d}g dg dg}t	d}g d}	ttt
||ddd ttt
||ddd ttt
||ddjdg ttt
||	ddd tttt
||ddd t
||}
tt|
d d tt|
ddg d tt|
ddddg tt|
d|dg d d S )Nr   r<   r<   r<   r<   r   r<   r   r   r   r   r<   rw   r:   r   r         @r   r   r   r         (@r<   r   g
@)r   r   r   r   r         $@)r   r   r<   r<   r   r   )r   r<   r<   r<   r<   r<   Tr   )r   r        X@r   r   g      @      @)r   r   r   r   r   r   )r
   rO   float64r   r   r	   addreducer   r   r   r>   r   )rP   w1w2xym1m2m3m4m5zrT   rT   rU   test_testAverage2   sF   & 
zTestAverage.test_testAverage2c                 C   sf  t d}t dd }t||g||ggddd\}}tt|t| t|j|j ttddddgdd\}}tt|t| ttddd	\}}tt|t| ttdtddd
\}}tt|t| tddgddggt}t|ddgddgg}t|dd}	t|	ddg t|dd}
t|
ddg t|d d}
t|
d t|dd}
t|
ddg d S )Nrw   rz   r<   Tr   r9   r9   rz   r   r   r   r   )r   r   r9      Fr         ?r   r   g@      ?r   )r
   r   r   r   r   r	   rN   r   )rP   r?   r@   r1r   r2r   a2da2dma2daa2dmarT   rT   rU   test_testAverage3   s*   
zTestAverage.test_testAverage3c                 C   s   t g ddd}t jj|dgdgdggd}t g ddd}t||ddd}td	gd
gdggdgdgdgg}t|| d S )Nr9   rz   r   rz   r<   FTr   )r   r   rw   )r   r   keepdimsr   r   r   )rO   r	   r   r[   r   r   r   )rP   r   r@   wactualdesiredrT   rT   rU   test_testAverage4   s   "zTestAverage.test_testAverage4c           	      C   s  t dddd}t g dddd}t dd}t jj||d}|d d d d df }t|d	|d
}tg dg dd}t|| t dd}d|d d d d df< d|d< t jj||d}t|d	|d
}tt j	ddgg dd}t|| t dd}t jj||d}|dd d d d f }t|d|d
}tddgddgd}t|| t
jtdd t|d|d
 W d    n1 sw   Y  t
jtdd t|d	|d
 W d    n1 sw   Y  t|d|d
}t|d	|jd
}t|| d S )N   r9   rz   )r   r   r   r   r   r   r   r   r   r   r   r   r   Fr   r   r   r<   r   )      @       @      "@)FFFTr   r   r<   r   r   )TFFr<   r<   r9   g      @g      @zHShape of weights must be consistent with shape of a along specified axis)matchr   r<   r9   )r<   r   )rO   r
   r   r	   rk   r[   r   r   r   nanpytestraises
ValueErrorT)	rP   r   r   mymasubw0r   r   subw1rT   rT   rU   $test_weight_and_input_dims_different   sR   




z0TestAverage.test_weight_and_input_dims_differentc                 C   s@   t tddg}t|d t tg dg dd}t|d d S )Nr<   r9   r   )r<   r9   rz   r   FFTTr   )r   r	   r   rP   r?   rT   rT   rU   test_onintegers_with_mask1  s   
z%TestAverage.test_onintegers_with_maskc                 C   s  t jg dg dgtd}tg dg dg|d}t|}t | }t|j|j t|j|j t|dd}t|jddt|jddd	  }t|j|j t|j|j t|d
d}t|jd
dt|jd
dd	  }t|j|j t|j|j t g dg dg}	t||	d}
t j| |	|  d}t|
j|j t|
j|j t||	dd}t|j|	ddt|j|	ddd	  }t|j|j t|j|j t||	d
d}t|j|	d
dt|j|	d
dd	  }t|j|j t|j|j d S )N)r   r   r   r<   r   r   r<   r   r   r   r:   )r   y      ?       @y      @      @y      @      @y      @       @)y              "@              ?y       @      @y      @      @y      @      @r   r   r   r   r<   )r   r   r   r   r   )r   r   r   r   r   r   r   r   )	rO   r	   r   r   r   rn   r   realimag)rP   r>   r?   avexpectedav0	expected0av1	expected1r   wavwav0wav1rT   rT   rU   test_complex8  sR   
  
zTestAverage.test_complexz<x, axis, expected_avg, weights, expected_wavg, expected_wsumr<   r9   rz   Nr   )rz   r   r<   g      ?r   )r<   r9   r   )r<   rw      r   )r   r   r   r<   rz   )r   r   g      #@)r   r   r   c           
      C   s   t jj||dd}|jt |ksJ t|| t jj|||dd}|jt |ks,J t|| t jj|||ddd\}}	|jt |ksHJ t|| |	jt |ksWJ t|	| d S )NT)r   r   )r   r   r   )r   r   r   r   )rO   r[   r   r   r   )
rP   r   r   expected_avgr   expected_wavgexpected_wsumavgwavgwsumrT   rT   rU   test_basic_keepdimsd  s   



zTestAverage.test_basic_keepdimsc           	      C   sf  t jjt dddg dg dg dgd}tg ddd}tg dg dd}t|d|dd	}t g d
}t|| t|d|dd	}t g d}t|| t jjg dg dd}t|dddt jgd}t|d t jjg dg dg dgg dg dg dgd}t jj|dt jdgdd}t jjdt jt jdgg dd}t|| t	|j
|j
 d S )Nry   rz   r<   r   r   r   r   r   r   )r         Fr   r   )      @g     @g     @)r   g0N@g0N@)r   r   r   r   r   r<   r   r   )r   r   r   r   )r   r   r   r   )FTTF)TFTT)TFTFr   r         @)rO   r[   r	   r
   r   r   r   r   r   r   r>   )	rP   r?   weights_unmaskedweights_maskedavg_unmaskedexpected_unmasked
avg_maskedexpected_maskedavg_expectedrT   rT   rU   test_masked_weights{  sD   




zTestAverage.test_masked_weights)r   r   r   r   r   r   r   r   r   r   r   markparametrizer   r   rT   rT   rT   rU   r      s$    "	3,
r   c                   @   $   e Zd Zdd Zdd Zdd ZdS )TestConcatenatorc                 C   sz   t td tg d td}g d}t||d}t|dd|f }tt|t t |g d t |jt|dd|f  d S )Nr<   r9   rz   r   r   rw   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   
isinstancer   r>   )rP   r@   r   drW   rT   rT   rU   test_1d  s   zTestConcatenator.test_1dc                 C   s0  t jdd}t jdd}t t jddd}t t jddd}t||d}t||d}td||f }t|jdk t|d d d df | t|d d dd f | t|j	t j
d||f  t||f }t|jdk t|d dd d f | t|dd d d f | t|j	t j
||f  d S )Nr   r   r   1)r   re   )re   r   )rO   randomrandroundr   r   r   r   r   r>   r_)rP   a_1a_2m_1m_2b_1b_2r  rT   rT   rU   test_2d  s    zTestConcatenator.test_2dc                 C   sp   t tjjdf }t|jddg t|jd d t ddgtjjf }t|jg d t|jd d ddg d S )Nr<   TFr9   )FFT)r   rO   r[   r   r   r>   rl   )rP   r   rT   rT   rU   test_masked_constant  s   z%TestConcatenator.test_masked_constantN)r   r   r   r  r  r  rT   rT   rT   rU   r     s    r   c                   @      e Zd Zdd Zdd ZdS )TestNotMaskedc                 C   s  t tdddg dg dg dg dg dgd}t|d }t|d	d
g t|d	}t|d	 ddg t|d ddg t|d}t|d	 ddg t|d ddg t|jd }t|d	d
g t|jd	}t|d	 ddg t|d ddg t|jd}t|d	 ddg t|d ddg t|d< t|d	}t|d	 ddg t|d ddg t|d}t|d	 ddg t|d ddg 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<   r<   r   r   r   r      r   r<   r9   rz   r   r<   )rz   rz   rz   r   r   )r   r   r9   r   rz   )r   r9   r   r   r   )r   r   r   r   r   )r<   r<   r9   r   r   )r   r<   r9   r   )r   r   r9   rz   )r   r9   r   r   )r   rO   r
   r   r.   r   rl   r   rP   rl   rQ   rT   rT   rU   
test_edges  s>   




zTestNotMasked.test_edgesc                 C   s,  t tdddg dg dg dgd}t|d }t|tdd	d td
dd tddd g t|d}t|tddd tddd gtddd tddd gtddd tddd gtddd tddd gtddd gtddd gg tddd gg t|d}t|tdd	d gg tddd tddd gg d S )Nr  rz   rx   )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<   r9   rw   rh   )r   rO   r
   r   r-   r   r{   )rP   r?   tmprT   rT   rU   test_contiguous  s:   






zTestNotMasked.test_contiguousN)r   r   r   r  r  rT   rT   rT   rU   r    s    "r  c                   @   s|   e Zd Zdd Zdd Zdd Zejdg dejd	d
ge	j
jdfe	j
jdfgdd Zdd Zdd Zdd ZdS )TestCompressFunctionsc              	   C   s(  t ttdddd}t dt}d|d< t||d}t|}t	|g d	g d
g dgg dg dg dgg t|d}t	|g dg dg dg dgg dg dg dg dgg t|d}t	|g dg dg dgg dg dg dgg dg dg dgg t|d}t|d}t|d}t	|| t	|| t	|| t|d}t	|g d	g d g d
g dgg d!g d"g d#g d$gg dg d%g dg dgg t|d&}t|d'}t|d(}t	|| t	|| t	|| t|d)}t	|g dg dg dgg dg dg dgg t|d*}t	|| t|d+}t	|g d	g d
g dgg d!g d#g d$gg dg dg dgg t|d,}t|d-}t|d.}t	|| t	|| t	|| t|d/}t	|g d	g d g d
g dgg dg d%g dg dgg t|d0}t	|| d S )1N<   rz   r   r   rz   r   r   Tr<   r<   r<   r   )r   r9   rz   r   )re   r         )            )(   *   +   ,   )2   4   5   6   )7   9   :   ;   r   r  )r   rw   rh   rx   ry   )re   r   r   r$  r%  )r&  r  r'  r(  r)  )r*  )   r+  r,  r-  )-   .   /   0   1   )r.  3   r/  r0  r1  )r2  8   r3  r4  r5  r<   )      r  r  r  )   r       !   "   )#   $   %   &   '   rX   r  )r  r9   )r   rh   rx   ry   )r>  r  r  r  )r     r      )r@  rA  rB  rC  )rD  rF  rG  rH  )r7  r9  r:  r;  r8   r  )r  r   )r   r  r   )r  r9   )r<   r  )r  r  r   r9   )r   r  )
rO   r	   listri   r   r   astyper   r'   r   )rP   r   r   r?   a2a3a4rT   rT   rU   test_compress_nd  s   




































	z&TestCompressFunctions.test_compress_ndc                 C   s  t tdddg dg dg dgd}tt|ddgdd	gg tt|d
g dg dg tt|dddgddgdd	gg t |jg dg dg dgd}tt|d
dgdd	gg tt|d
g dg dg tt|dd
dgddgdd	gg t |jg dg dg dgd}tt|d	gg tt|d
g dg tt|ddgdgd	gg t |jg dg dg dgd}tt|jd
 tt|d
jd
 tt|djd
 d S )Nry   rz   r   r   r   r   r   rh   rx   r   r"  )rw   rh   rx   r<   r9   r   r<   r   rw   r   r   )r	   rO   r
   r   r   r(   _datar   rP   r   rT   rT   rU   test_compress_rowcols  s$   " "  z+TestCompressFunctions.test_compress_rowcolsc                 C   sH  t tdddg dg dg dgd}tt|jg dg dg dg tt|djg dg dg dg tt|djg dg dg dg t |jg dg d	g dgd}tt|jg d	g dg d	g tt|djg dg dg dg tt|djg d	g d	g d	g t |jg dg d	g dgd}tt|jg dg dg d
g tt|djg dg dg dg tt|djg d
g d
g d
g t |jg dg d	g dgd}tt|	 t
u  tt|d	 t
u  tt|d	 t
u  tt|j	  tt|dj	  tt|dj	  d S )Nry   rz   r   r   r   r#  r   r<   rR  )r<   r<   r   r   )r	   rO   r
   r   r   r)   r>   rS  r   allr   rT  rT   rT   rU   test_mask_rowcols  sN   
 
 
 z'TestCompressFunctions.test_mask_rowcolsr   )Nr   r<   funcrowcols_axisr   r<   c                 C   sv   t tdddg dg dg dgd}tt |||d}t|t|| W d    d S 1 s4w   Y  d S )Nry   rz   r   r   r   r   )r	   rO   r
   r   r   DeprecationWarningr   r)   )rP   r   rX  rY  r   resrT   rT   rU   #test_mask_row_cols_axis_deprecation  s   
"z9TestCompressFunctions.test_mask_row_cols_axis_deprecationc                 C   s0  t dd}g d}t||ddd}t||ddd}t||dd}t|jddgdd	gg t||dd}t|jg d
g dg dg t||dd}t|t |d	|d	 t||dd}t|t |d	|d	 g d}t||ddd}t||ddd}t||dd}t|jd	dgddgg t||dd}t|jg dg dg d
g t||dd}t|t |d	|d	 t|t|| t||dd}t|t |d	|d	 g d}t||ddd}t||ddd}t||}t|jt t||}t|jt t|g dddd}t|g dddd}t||dd}t|jddgd	d	gg t||dd}t|t |d	|d	 t||dd}t|jg dg dg dg t||dd}t|t |d	|d	 t|g dddd}t|g dddd}t||dd}t|jd	d	gddgg t||}t|t |d	|d	 t||dd}t|jg dg dg dg t||dd}t|t |d	|d	 t|g dddd}t|g dddd}t||dd}t|jdd	gddgg t||dd}t|t |d	|d	 t||dd}t|jg dg d
g dg t||dd}t|t |d	|d	 tt dddddd	gd	d	ggd	d	gd	d	gggd}tt ddddd	d	gd	d	ggd	d	gd	dgggd}t||dd}t|jddgddggd	d	gd	dgggd	d	gd	dggd	d	gd	dgggg t||dd}t|jd	d	gd	dggd	d	gd	d	gggd	d	gd	d	ggd	d	gd	d	gggg t||dd}t|jdd	gd	d	ggdd	gd	d	gggdd	gd	d	ggddgddgggg t||dd}t|jd	d	gd	d	ggd	d	gd	d	gggd	d	gd	d	ggdd	gd	d	gggg tt dddddd	gd	d	ggd	d	gd	d	gggd}d}t||dd}t|jdd	gd	d	ggd	d	gd	d	ggg t||dd}t|jdd	gd	d	ggd	d	gd	d	ggg t||dd}t|jdd	gd	d	ggd	d	gd	d	ggg t||dd}t|jdd	gd	d	ggd	d	gd	d	ggg tt dddddd	gd	d	ggd	d	gd	d	gggd}tt dd	dgd}t||dd}t|jddgddgg t||dd}t|jdd	gd	d	gg d S )Nr<   rh   )r<   r   r   r   r   r   r   r9   rz   T)strictr   r#  r   Fr   r   r   r   r   r<   r   )r   r   r   r   r   r   )r   r   r<   r   r   r   rx   r   )	rO   r
   r   r   r   r   r>   filledr   )rP   nr   r?   r@   rW   rT   rT   rU   test_dot  s   


((((zTestCompressFunctions.test_dotc                 C   sn   t d}t|}ttt||tu  ttt||tu  ttt||tu  ttt||tu  d S )Nrz   )rO   eyer	   r   r\   r   r   rP   r?   r@   rT   rT   rU   test_dot_returns_maskedarray:  s   
z2TestCompressFunctions.test_dot_returns_maskedarrayc                 C   sD   t td}t td}t|||d}t||u  t|| d S )Nrz   )rz   rz   out)r	   rO   rb  r   r   r   r   )rP   r?   rf  r[  rT   rT   rU   test_dot_outC  s
   z"TestCompressFunctions.test_dot_outN)r   r   r   rQ  rU  rW  r   r   r   rO   r[   	mask_rows	mask_colsr\  ra  rd  rg  rT   rT   rT   rU   r     s    p 	o	r   c                   @   r  )TestApplyAlongAxisc                 C   s@   t dddd}dd }t|d|}t|ddgdd	gg d S )
Nr   r9   rz   c                 S   s   | d S Nr<   rT   )r@   rT   rT   rU   myfuncP  s   z*TestApplyAlongAxis.test_3d.<locals>.myfuncr<   r   rh   re   r
   r   r&   r   rP   r?   rl  xarT   rT   rU   test_3dM  s   zTestApplyAlongAxis.test_3dc                 C   sF   t dddd}ddd}t|d|dd}t|dd	gd
dgg d S )Nr   r9   rz   r   c                 S   s   | d|  S rk  rT   )r@   offsetrT   rT   rU   rl  Z  s   z1TestApplyAlongAxis.test_3d_kwargs.<locals>.myfuncr<   )rq  r   rx   r   )r   rm  rn  rT   rT   rU   test_3d_kwargsW  s   
z!TestApplyAlongAxis.test_3d_kwargsN)r   r   r   rp  rr  rT   rT   rT   rU   rj  K      
rj  c                   @   s   e Zd Zdd ZdS )TestApplyOverAxesc                 C   s   t dddd}ttj|ddg}tdgdgdggg}t|| t||d t	< ttj|ddg}td	gd
gdggg}t|| d S )Nr  r9   rz   r   r   r!  \   |   r   r-  )
r
   r   r%   rO   rm   r	   r   r   rM  r   )rP   r?   rQ   ctrlrT   rT   rU   
test_basicc  s   
zTestApplyOverAxes.test_basicN)r   r   r   rx  rT   rT   rT   rU   rt  a  s    rt  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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g ddd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2S )3
TestMedianc                 C   s4   t jjt jt jgt jt jggdd}t|t j d S )Nr  r   )rO   r[   r   infr   rP   rrT   rT   rU   test_pytypeo  s   $zTestMedian.test_pytypec                 C   s   t jjt jt jt jgt jt jggdd}t|t j t jjt jt jt jgt jt jggd d}t|t j t jjt jjt jt jgt jt jggdddd}t|jd t jjt jjt jt jgt jt jggddd d}t|jd d S )Nr  r   Tr   )rO   r[   r   r   rz  r   r>   r{  rT   rT   rU   test_infs  s8   



zTestMedian.test_infc                 C   sl  t d}tt j|d ttt j|tu td}tt j|d ttt j|tu d}tt j|d ttt j|tu t d	dd}tt jj|dd	t j|dd	 tt jj|d
d	t j|d
d	 tt jj|d
d	tu t d	dd}tt jj|dd	t j|dd	 tt jj|d
d	t j|d
d	 tt jj|d
d	tu d S )Nry   r   rx   r   r   r   H   r   r   r<   g      R@)
rO   r
   r   r[   r   r   r\   r   ri   r   rT  rT   rT   rU   test_non_masked  s"   
    zTestMedian.test_non_maskedc                 C   s  t tddgd dgd  d}ttj|d ttj|jdd tttj|t	u t td	
d
ddgd dgd  d}ttj|d ttj|jdd tttj|t	u tjj|ddd}t|ddg t|jdd tt|t	u  dS )z5test the examples given in the docstring of ma.medianrx   r   r   r<   r   r   rT   shape mismatchre   r9   r   rw   r   r  Tr   overwrite_inputr   r   r8   N)r	   rO   r
   r   r[   r   r   r   r\   r   r   )rP   r   ma_xrT   rT   rU   test_docstring_examples  s   "*z"TestMedian.test_docstring_examplesc                 C   s   d}t dD ]q}dD ]l}td||d}tt | |ddg}|D ] \}}ztjj|||d W q! tyA   t|||||f w t|d  |gddg}|D ]$\}}ztjj|||d W n tj	j
yk   Y qQw t|||||f q
qd S )	Nz5mask = %s, ndim = %s, axis = %s, overwrite_input = %sr   )FTr<   )ndminr>   FTr  )ri   r	   	itertoolsproductrO   r[   r   	ExceptionAssertionError
exceptions	AxisError)rP   msgr  r>   r   argsr   overrT   rT   rU   test_axis_argument_errors  s,   z$TestMedian.test_axis_argument_errorsc                 C   sD   t ddd}ttj|d t ddd}ttj|tjj d S )Nr<   Fr   T)r	   r   rO   r[   r   r   rT  rT   rT   rU   test_masked_0d  s   zTestMedian.test_masked_0dc                 C   s  t tddd}ttj|tjj ttj|jdd tt	tj|tjj
ju  t tddd}ttj|d ttj|jdd tt	tj|tu t tdg dd}ttj|d	 ttj|jdd tt	tj|tu t tdg d
d}ttj|d ttj|jdd tt	tj|tu t tdg dd}ttj|d ttj|jdd tt	tj|tu t tdg dd}ttj|d ttj|jdd tt	tj|tu t tdg dd}ttj|d	 ttj|jdd tt	tj|tu t tdg dd}ttj|d	 ttj|jdd tt	tj|tu d S )Nr   Tr   rT   r  Fr   r   r   )r   r<   r<   r<   r<   r   )r   r<   r<   r   r   r   r   rw   r   r   )r	   rO   r
   r   r[   r   r   r   r   r\   r]   MaskedConstantr   rT  rT   rT   rU   test_masked_1d  s@   zTestMedian.test_masked_1dc                 C   sB   t tjtg dg ddjtjtg dg ddj d S )Nr   r   r   rR  )r   rO   r[   r   r	   r   rP   rT   rT   rU   test_1d_shape_consistency  s   z$TestMedian.test_1d_shape_consistencyc                 C   s   d\}}t tdd|}t |d d< |dd < t tj||ftd}|d d  |d d df< tt|}td|D ]}tj	
| || |d d |f< q<tt|d d df d tt|d tt|dd	t| tt|jdd	t| d S )
N)e   r@        r   re   r:   r   r<   r   )r   rO   linspacer   emptyrN   r
   r^   ri   r  shuffler   r   r   r   )rP   r`  pr   r   idxro   rT   rT   rU   r    s   zTestMedian.test_2dc                 C   s   t tddd}t |d d< |dd < tt|d tttj	|t
u tt|ddg d tttj	j|ddt
u  tt|d	dg d
 tttj	j|d	dt
u  tt|d	djg d d S )Nr@  re   rz         -@r   r   )      +@r  g      /@r<   )
r   r   r   re   r$  r  r)  r   r   r   )
r<   r<   r<   r   r   r   r   r<   r<   r<   )r   rO   r
   r   r   r   r   r   r\   r[   r   r>   rT  rT   rT   rU   test_2d_waxis  s   zTestMedian.test_2d_waxisc                 C   s   t jdddd}t||d dk< tt|dddgdd	gddgd
d	gg d|_tt|dddgddgddgg t jdddd}t||d dk< tt|dddgddgddgg d S )Nr  rz   r   r9   r   r   ry   rw   r&  r(  )r   rz   r9   c   re   r   r$  r%  r   rx   r  r'  )rO   r[   r
   r   r   r   r   r   rT  rT   rT   rU   rp    s   ("&zTestMedian.test_3dc                 C   sL   t tddd}t |d d< |dd < tt|ddt|dd d S )Nr@  re   rz   r  r  r   r<   )r   rO   r
   r   r   r   r   rT  rT   rT   rU   test_neg_axis  s   zTestMedian.test_neg_axisc                 C   s   dD ]?}t t|}t |d d< |dd < t td}t||d}|dkr.t|d nt|d t||u  tt|t	u  qd S )	N)r@        >@r   g      ?@rz   r  rT   re  r@  r  g      .@)
r   rO   r
   r   r   r   r   r   r\   r   )rP   vr   rf  r|  rT   rT   rU   test_out_1d  s   
zTestMedian.test_out_1dc                 C   s  dD ]}}t t|dd}t |d d< |dd < t td}t|d|d}|dkrMt d	gd g d
 d	gd  dgd dgd  dgd  d}nt d	gd g d d	gd  dgd dgd  dgd  d}t|| t||u  tt	|t
u  qd S )N)r*  g      D@r@  r  re   r  rz   r  r<   )r   rf  r@  r   )re   r$  r  r)  TFr   r   )r  g     1@g     5@g     9@)r   rO   r
   r   r   r   r   r   r   r\   r   )rP   r  r   rf  r|  erT   rT   rU   test_out,  s    
zTestMedian.test_outr   )Nr<   rX   r   )r  r  )argnames	argvaluesc                    s   t jdtd}t jdt |jd d d f  }|t j}t j|t	|< t
t |j|d|d u r:dj }nt|j t	 fddtjD }t
t |}t|d|d	}||u sdJ t|j| d S )
N)rz   r   rh   r   r:   )r      r   rX   c                 3   s&    | ]}| v r
d nj | V  qdS )r<   N)r   ).0ro   	axis_normr  rT   rU   	<genexpr>R  s    
z/TestMedian.test_keepdims_out.<locals>.<genexpr>T)r   r   rf  )rO   r   r   r  r	   r   rM  intpr   tupler   r   ndimr   ri   r  r   r   )rP   r   r>   r   	shape_outrf  r   rT   r  rU   test_keepdims_out=  s   $zTestMedian.test_keepdims_outc                 C   sF   ddgddgddgg}t j|d}ddg}tt jj|dd| d S )Nr   r   r   r   r   )rO   r[   masked_equalr   r   )rP   rl   rb   r   rT   rT   rU   $test_single_non_masked_value_on_axisY  s   z/TestMedian.test_single_non_masked_value_on_axisc                 C   s  dt jdtdfD ]}t jdt jdgg dg}||_t jj|d d}tt 	| t
|t j t jj| dd}tt 	| t
|t j t jj|dd}tt|t t
|dt jdg t jj|dd}tt|t t
|t jd	g t jj|d
d}tt|t t
|t jd	g q	t jdt jdgg dg}t jj|d d d	f< t
t jj|d dt j t
t jj|dddt jdg t
t jj|ddt jdg d S )NFrw   r:   r<   rz   r   r   r   r9   r  r   )rO   r   r   r[   r	   r   r>   r   r   isscalarr   ravelr   r\   r   r   )rP   r>   dmr|  rT   rT   rU   test_nanb  s.    zTestMedian.test_nanc                 C   s   t jt d}t jt d}t j|d< t jj|d< tt jj|d|d| t jt d}tt jj|d|d| t jt d	}tt jj||d| d S )
N)r   rz   r   r9   r<   rG   r   re  rz   r<   rT   )	rO   r[   r   r   r   r   r   r   r   )rP   or  rT   rT   rU   test_out_nan  s   
zTestMedian.test_out_nanc                 C   s  t jt jdtd}t jj|d d d< t j|d< tt j|t j tt jj|ddt j t jt jdtd	ddd}t |j
d dk|_| }t j|d	< t j|d
< tt j|t j tt t j| t jj|dd}t j|d< t j|d< tt j|d| t jj|dd}t j|d< t j|d< tt j|d| t jj|dd}t j|d< t j|d< tt j|d| d S )Nr  r:   rz   r9   r   r   r   r<   r   )r<   r<   r9   r9   rz   r   r<   rz   rK  )rO   r[   r   r
   rN   r   r   r   r   r   r   r>   copyr   r  r   )rP   r?   aorigr@   rT   rT   rU   test_nan_behavior  s0   
 







zTestMedian.test_nan_behaviorc                 C   s   t jg dg dgt jd}t jj||dkd}tt jj|ddd tt jj|ddjd tt jj|d	d|d	  tt j|d d S )
N)rz   rz      r:   rz   r   r<   r   r  Fr   )rO   r	   uint8r[   r   r   r   r>   r   rT   rT   rU   test_ambigous_fill  s   zTestMedian.test_ambigous_fillc                 C   s  t jt j fD ]v}t |t jgt jt jgg}t jj|t |d}tt jj|dd|t jg tt jj|dd|t jg tt j|| t t jt j|gt jt j|gg}t jj|t |d}t	t jj|dd| t	t jj|ddj
d t	t jj|dd|d  t	t j|| t ||g||gg}tt j|| tt jj|dd| tt jj|dd| t j|d| dgdt jt jd	gd
t jt j|ggt jd}t jj|t |d}|dkrtt jj|dddd| dg tt j|d ntt jj|dddd| dg tt j|d tt jj|dddd|g tddD ]P}tddD ]G}t t jg| |g|  gd }t jj|t |d}tt j|| tt jj|dd| tt jj|ddt jg| |g|   q4q-qd S )Nr   r   r   r<   Frh   ir  r   r   r:   r   r   r   g      @g      $g      "g      r  re   r9   )rO   rz  r	   r   r[   r   isnanr   r   r   r>   float32ri   )rP   rz  r?   ro   rp   rT   rT   rU   test_special  sR   "
  "zTestMedian.test_specialc                 C   s  t jt jg td}t !}|t tt j	|t j
 t|jd jtu  W d    n1 s2w   Y  t jt jg tdd}t (}|t tddt tt j	|t j
 t|jd jtu  W d    n1 sqw   Y  t jt jg tdd}tt jj	|dd| tt jj	|d	d| t jt jt j
tdd}tjd
d$}tddt tt jj	|dd| t|d jtu  W d    d S 1 sw   Y  d S )Nr:   r   rz   )r;   r  always r9   r   r<   T)record)rO   r[   r   r	   rN   r   r  RuntimeWarningr   r   r   r   logcategorywarningsfilterwarningsr   catch_warnings)rP   r?   r   r@   rT   rT   rU   
test_empty  s,   

"zTestMedian.test_emptyc                 C   sX   t jt d}ttt j|tt	 t j
|d< ttt j|tt	 d S )Nr   r9   )rO   r[   r   r
   r   r\   r   rM  rZ   rN   r   )rP   r  rT   rT   rU   test_object  s   
 zTestMedian.test_objectN)r   r   r   r}  r~  r  r  r  r  r  r  r  r  rp  r  r  r  r   r   r   r  r  r  r  r  r  r  r  r  rT   rT   rT   rU   ry  n  s8    &

	#	+ry  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 )TestCovc                 C   s   t tjd| _d S Nr   )r	   rO   r  r  rl   r  rT   rT   rU   setup_method  s   zTestCov.setup_methodc                 C   s   | j }tt|ddd jtj tt||ddd jtj |dk}tttj||ddd 	t
|dd  tttj|||ddd 	t
t| | f d S )NTrowvarr<   F)r   r  r   r  )rl   r   r6   r;   rO   r  r   r[   r   rM  r   r   r5   )rP   r   r>   rT   rT   rU   test_covhelper
  s,   zTestCov.test_covhelperc                 C   sZ   | j }tt|t| ttj|ddt|dd ttj|dddt|ddd d S )NFr  Tr  bias)rl   r   rO   r   rT  rT   rT   rU   test_1d_without_missing  s   zTestCov.test_1d_without_missingc                 C   sb   | j dd}tt|t| ttj|ddt|dd ttj|dddt|ddd d S )Nrz   r   Fr  Tr  )rl   r   r   rO   r   rT  rT   rT   rU   test_2d_without_missing&  s   zTestCov.test_2d_without_missingc                 C   s>  | j }t|d< || 8 }| }tt|t| ttj|ddt|dd ttj|dddt|ddd zt|dd W n	 tyJ   Y nw |dd }tt||d d d t||d d d  ttj||d d d ddt||d d d dd ttj||d d d dddt||d d d ddd d S )Nr  Fr  Tr  allow_maskedr<   )rl   r   meanrn   r   rO   r   r   )rP   r   nxrT   rT   rU   test_1d_with_missing.  s,   ,zTestCov.test_1d_with_missingc                 C   s6  | j }t|d< |dd}tt|t}t||j	}||
dd d d f  d}tt|t||jd d  |d   tt|ddtj|dd|jd  |  t|j	|}||
d d}tt|d	d
tj|d	d
|jd d  |d   tt|d	ddtj|d	dd|jd  |  d S )Nr  rz   r   r<   r   r   Tr  Fr  r  )rl   r   r   rO   logical_notr   rM  rj   r   r   r  r_  r   r   r   )rP   r   validfracxfrT   rT   rU   test_2d_with_missingF  s8    zTestCov.test_2d_with_missingN)	r   r   r   r  r  r  r  r  r  rT   rT   rT   rU   r    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 )TestCorrcoefc                 C   s(   t tjd| _t tjd| _d S r  )r	   rO   r  r  rl   data2r  rT   rT   rU   r  ^  s   zTestCorrcoef.setup_methodc                 C   s   | j | j}}t|}t||}t P}td ttt|dd |	td t
tj|ddt|dd t
t|dd| t
t||dd| t
t|dd| t
t||dd| W d    d S 1 shw   Y  d S )Nr  r  ddofbias and ddof have no effectr   rz   rl   r  rO   r   r   r  simplefilterr   rZ  filterr   )rP   r   r   r   	expected2suprT   rT   rU   	test_ddofb  s   

"zTestCorrcoef.test_ddofc                 C   s   | j | j}}t|}t 7}td ttt||dd ttt||dd ttt|dd |	td t
t|dd| W d    d S 1 sIw   Y  d S )Nr  TFr  r  r<   r  )rP   r   r   r   r  rT   rT   rU   	test_biasr  s   

"zTestCorrcoef.test_biasc                 C   s   | j }tt|t| ttj|ddt|dd t }|td ttj|dddt|ddd W d    d S 1 s@w   Y  d S )NFr  r  Tr  )rl   r   rO   r   r   r  rZ  rP   r   r  rT   rT   rU   r    s   
"z$TestCorrcoef.test_1d_without_missingc                 C   s   | j dd}tt|t| ttj|ddt|dd t }|td ttj|dddt|ddd W d    d S 1 sDw   Y  d S )Nrz   r   Fr  r  Tr  )rl   r   r   rO   r   r   r  rZ  r  rT   rT   rU   r    s   
"z$TestCorrcoef.test_2d_without_missingc              	   C   s  | j }t|d< || 8 }| }tt|t| ttj|ddt|dd t }|t	d ttj|dddt|ddd W d    n1 sMw   Y  zt|dd W n	 t
yc   Y nw |dd }tt||d d d t||d d d  ttj||d d d ddt||d d d dd t ?}|t	d tt||d d d t||d d d dd	 tt||d d d t||d d d d
d W d    d S 1 sw   Y  d S )Nr  Fr  r  Tr  r  r<   r  r9   r  )rl   r   r  rn   r   rO   r   r   r  rZ  r   )rP   r   r  r  rT   rT   rU   r    sB   
,"z!TestCorrcoef.test_1d_with_missingc                 C   s$  | j }t|d< |dd}t|}t|}t|d dd df |d dd df  t Z}|td tt|ddd dd df |d dd df  tt|ddd dd df |d dd df  tt|ddd dd df |d dd df  W d    d S 1 sw   Y  d S )	Nr  rz   r   r  r  r  r<   r  )	rl   r   r   r   rO   r   r   r  rZ  )rP   r   rQ   rR   r  rT   rT   rU   r    s$   
*"z!TestCorrcoef.test_2d_with_missingN)
r   r   r   r  r  r  r  r  r  r  rT   rT   rT   rU   r  \  s    r  c                   @   r  )TestPolynomialc                 C   s  t jd}t jddd}tt||dt ||d |t}t|d< |t}t |d< |d< t||d d df dd	d
\}}}}}t j|dd  |dd df 	 dd	d
\}}	}
}}t
|||||f||	|
||fD ]	\}}t|| qpt||d d df dd	d
\}}}}}t j|dd |dddf dd	d
\}}	}
}}t
|||||f||	|
||fD ]	\}}t|| qt||dd	d
\}}}}}t j|dd |ddd d f dd	d
\}}	}
}}t
|||||f||	|
||fD ]	\}}t|| qt jdd }| }|dd }|dd }|dd }t||dd	|d\}}}}}t j||dd	|d\}}	}
}}t|| t
|||||f||	|
||fD ]
\}}t|| qMd S )Nre   r>  r  r9   rz   r   rE   r  r  Trk   r<   )rk   r   )rO   r  r  r   r   r   viewr   r   rn   zipr  r   )rP   r   r   CRKSDrW   r|  rq   rs   r  r?   a_r   woxsyswsrT   rT   rU   test_polyfit  s@   

&"&&0&4&
&zTestPolynomial.test_polyfitc                 C   s   t jd}t jddd}t j|d< t j|d< |t}|t}t|d< t|d< t||ddd	\}}}}}t j|d
d |d
dd d f ddd	\}}	}
}}t	|||||f||	|
||fD ]	\}}t
|| qbd S )Nre   r>  r  r9   r   r  rz   Tr  r<   )rO   r  r  r   r   r  r   r   r   r  r   )rP   r   r   r  r  r  r   r  rW   r|  rq   rs   r  r?   r  rT   rT   rU   test_polyfit_with_masked_NaNs  s   



4&z,TestPolynomial.test_polyfit_with_masked_NaNsN)r   r   r   r  r  rT   rT   rT   rU   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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!d" Zd#S )$TestArraySetOpsc                 C   sn   g d}t |ddd}tt|d t t|d tg dg dd t|d g d	 t|d
 g d d S )Nr<   r<   r<   r9   r9   rz   Treturn_indexreturn_inverser   r   r   r   r<   )r   rz   r   r9   )r   r   r   r<   r<   r9   )r   r   r  r   r   r   r  rT   rT   rU   test_unique_onlist  s   z"TestArraySetOps.test_unique_onlistc                 C   s   t g dg dd}t|ddd}t|d t g dg dd t|d	 g d
 t|d g d d|_t g dg ddd}t|ddd}t|d t g dg dd t|d	 g d
 t|d g d d S )Nr
  )r   r   r<   r   r<   r   r   Tr  r   )r<   r9   rz   r  r   r   r   r<   r<   )r   rz   r   r9   r9   )r   r   rz   r<   rz   r9   rz   )rl   r>   
fill_value)r   r   r   r  r  rT   rT   rU   test_unique_onmaskedarray  s   z)TestArraySetOps.test_unique_onmaskedarrayc                 C   s   t g ddd}t|ddd}t|d t dgdgd t|d dg t|d g d t}t|ddd}t|d t t t|d dg t|d dg d S )	Nr#  Tr   r  r   r<   r9   r   )r   r   r   r   r  rT   rT   rU   test_unique_allmasked  s   z%TestArraySetOps.test_unique_allmaskedc                 C   sd   t tdg dd}tg dg dd}t|}t|| t|d|d t|j|j d S )Nr   r<   r   r   r   r<   r   )r<   r<   r<   r   )r<   r   r   r<   r   )r   rO   r
   r	   r$   r   r_  r>   )rP   r   rR   rQ   rT   rT   rU   test_ediff1d+  s   
zTestArraySetOps.test_ediff1dc                 C      t tdg dd}t|td}tg dg dd}t|| t|d|d t|j|j t|g dd}tg d	g d
d}t|| t|d|d t|j|j d S )Nr   r  r   )to_begin)r   r<   r<   r<   r   )r<   r<   r   r   r<   r   r   )r<   r9   rz   r<   r<   r<   r   )r   r   r   r<   r   r   r<   	r   rO   r
   r$   r   r	   r   r_  r>   rP   r   rQ   rR   rT   rT   rU   test_ediff1d_tobegin4     

z$TestArraySetOps.test_ediff1d_tobeginc                 C   r  )Nr   r  r   )to_end)r<   r<   r<   r   r   )r<   r   r   r<   r<   r   r   )r<   r<   r<   r   r<   r9   rz   )r<   r   r   r<   r   r   r   r  r  rT   rT   rU   test_ediff1d_toendC  r  z"TestArraySetOps.test_ediff1d_toendc                 C   s   t tdg dd}t|ttd}tg dg dd}t|| t|d|d t|j|j t|g dtd}tg d	g d
d}t|| t|d|d t|j|j d S )Nr   r  r   r  r  )r   r<   r<   r<   r   r   )r<   r<   r   r   r<   r<   r   r   )r   r<   r<   r<   r   r<   r9   rz   )r<   r<   r   r   r<   r   r   r   r  r  rT   rT   rU   test_ediff1d_tobegin_toendR  s   

z*TestArraySetOps.test_ediff1d_tobegin_toendc                 C   s   t d}t|}tg dg dd}t|| tt|t t|d|d t|j	|j	 t|t
t
d}tg dg dd}tt|t t|d|d t|j	|j	 d S )	Nr   r<   r<   r<   r<   r   r   r   r   r   r   r  r   r   )rO   r
   r$   r	   r   r   r  r   r_  r>   r   r  rT   rT   rU   test_ediff1d_ndarrayb  s   

z$TestArraySetOps.test_ediff1d_ndarrayc                 C   sT   t g dg dd}t g dg dd}t||}t g dg dd}t|| d S )N)r<   rz   rz   rz   r  r   )rz   r<   r<   r<   )r<   rz   r  r   )r	   r"   r   )rP   r   r   rQ   rR   rT   rT   rU   test_intersect1dr  s
   
z TestArraySetOps.test_intersect1dc                 C   s$  t g dg dd}t g dg dd}t||}t|t g d t g dg dd}g d}t||}t|t g dg d	d t g d
}t g d}t||}tt|t t|g d t g dg dd}t g dg d	d}t||}tt|t t|g d tg tg g  d S )Nr<   r9   r   rh   r  r   r   r   r   r<   r   r<   r9   rz   r   r   r  r^  )rz   r   rh   r<   r9   rz   r   r   rz   r   rh   r  r  r   )rw   r   r   r  r<   rx   r9   rz   r   r<   r   r   rw   r   r   rx   )r	   r   r   r   r  r   r   rP   r?   r@   rQ   rT   rT   rU   test_setxor1dz  s&   



zTestArraySetOps.test_setxor1dc                 C   s   t g dg dd}g d}t||dd}t|t g dg dd t g d	g d
d}t g dg dd}t||dd}tt|t t|g d t dgdgdgdgg}t ddgddgg}t||dd}tt|t t|g d d S )Nr#  r$  r   r&  T)assume_uniquer'  r  r(  r)  r*  r  r<   rx   r9   rz   rw   r   r   )r	   r   r   r   r  r   r+  rT   rT   rU   test_setxor1d_unique  s   z$TestArraySetOps.test_setxor1d_uniquec                 C   s   t dg d}t g d}d|d< t||d}tg dg dd}tdtd	}d
|d< d
|d< d
|d< t||}tt|t	 t
|| t |||j  |j @ }t
|| d S )Nr  r   r<   )r<   r9   r   r   )	r   re   r>  r@  r<   rz   r   r  rB  )	r   r<   r   r<   r   r<   r   r<   r   )rl   r>   r:   Tr   r   )r   r9   rz   )rO   r
   r   r   r	   r   r1   r   r  r   r   r>   )rP   r?   r>   r@   ecrW   r  rT   rT   rU   	test_isin  s    

zTestArraySetOps.test_isinc                 C   s   t g dg dd}t g dg dd}t||}t|g d t g dg dd}t g dg d	d}t||}t|g d
 tg tg g  d S )Nr#  r$  r   r%  r^  )TTTFTr   r   r9   r<   r  r<   r   r  r   )TTFTT)r	   r#   r   r   r+  rT   rT   rU   	test_in1d  s   

zTestArraySetOps.test_in1dc                 C   s   t g dg dd}t g dg dd}ttt||t||dd t g dg dd}t g d	g d
d}ttt||t||dd tg tg g dd d S )Nr#  r$  r   r%  r^  T)invertr1  r2  r   )r	   r   rO   r4  r#   r   rc  rT   rT   rU   test_in1d_invert  s     z TestArraySetOps.test_in1d_invertc           	      C   s   t g dg dd}t g dg dd}t||}t g dg dd}t|| t g dg dgg d	g d
gd}t g dg dd}t g dg dd}t||}t|| tg tg g  d S )N)r<   r9   r   rh   r   r  r^  r   r%  )r<   r9   rz   r   r   rh   r  )r   r   r   r   r   r   r<   r   r"  r   r   r  r$  )r   r<   r9   rz   r   r   )r	   r!   r   r   )	rP   r?   r@   rQ   rR   r   r   ezr   rT   rT   rU   test_union1d  s   

$

zTestArraySetOps.test_union1dc                 C   s   t g dg dd}t g d}t||}t|t g dg dd td}td}tt||t dd	g t g tjg d}tt|g jtj d S )
N)rw   r   r   rh   rh   r<   r9   r<   )r   r   r   r   r   r   r   r<   r   )r9   r   rz   rz   r9   r<   r   )rw   rh   r  r   re   rx   ry   )r	   r    r   r
   rO   uint32r;   r+  rT   rT   rU   test_setdiff1d  s   
zTestArraySetOps.test_setdiff1dc                 C   s8   t g d}t g d}tt||t dg d S )N)r?   r@   rW   )r?   r@   rs   rW   )rO   r	   r   r    rc  rT   rT   rU   test_setdiff1d_char_array  s   z)TestArraySetOps.test_setdiff1d_char_arrayN)r   r   r   r  r  r  r  r  r  r  r!  r"  r,  r.  r0  r3  r5  r7  r9  r:  rT   rT   rT   rU   r	    s$    		r	  c                   @   r  )TestShapeBasec                 C   sn   t g dg dd}t|}t|jd t|jj|jj t|jd t|jj|jj t|jj|jj d S )Nr   rR  r   r  r  )r   r   r   r   r>   rl   rc  rT   rT   rU   test_atleast_2d  s   zTestShapeBase.test_atleast_2dc                 C   s  t d}t|jd t|jj|j t|jj|j t dd}|D ]}t|jd t|jj|j t|jj|j q!td}t|jd t|jj|j t|jj|j tdd}|D ]}t|jd t|jj|j t|jj|j q[td}t|jd t|jj|j t|jj|j tdd}|D ]}t|jd t|jj|j t|jj|j qtd}t|jd t|jj|jj d S )Nr   rX   r   rF   r#  )r   r   r   r>   rl   r   r   r2   )rP   r@   r?   rT   rT   rU   test_shape_scalar  s<   


zTestShapeBase.test_shape_scalarN)r   r   r   r<  r=  rT   rT   rT   rU   r;    rs  r;  c                   @   r   )TestNDEnumeratec                 C   s   t dd}t j|td}t||d}ttt |tt| ttt|tt| ttt|tt|dd d S )Nr   )r<   rz   r9   r:   r   Frn   )	rO   r
   r   
zeros_liker   r   r   rL  r3   )rP   ordinary
empty_mask	with_maskrT   rT   rU   test_ndenumerate_nomasked5  s   

z)TestNDEnumerate.test_ndenumerate_nomaskedc                 C   s   t d}t d}t d}ttt|g  ttt|g  ttt|ddtttddtg  ttt|g  ttt|ddtttddtg  d S )NrT   )d   r   Fr?  rE  r  )r/   r   rL  r3   r  rO   ndindexr   )rP   r?   r@   rW   rT   rT   rU   test_ndenumerate_allmasked@  s   z*TestNDEnumerate.test_ndenumerate_allmaskedc                 C   s   t tddg dg dg dgd}g d}ttt|| tttt|dd	|j t|dd	D ]\}}t|| | q6d S )
Nr   r  r  )r<   r<   r   r<   r   r   ))r   rw   ))r9   r   rx   )r  ry   )rG   re   )r  r   Fr?  )	r   rO   r
   r   r   rL  r3   r^   r   )rP   r?   items
coordinatevaluerT   rT   rU   test_ndenumerate_mixedmaskedL  s   z,TestNDEnumerate.test_ndenumerate_mixedmaskedN)r   r   r   rD  rG  rK  rT   rT   rT   rU   r>  3  s    r>  c                   @   r   )	TestStackc                 C   s   t g dg dd}t g dg dd}t||gdd}t|jd t|j|d j t|j|d	 j t||g}t|j|j t|j|j t||gd	d}t|jd
 t|j|d d df j t|j|d d d	f j d S )Nr   rR  r   ry   rx   rh   r   r   r   r  r<   rz   r9   r   r4   r   r   r   r>   r5   rl   rP   r?   r@   rW   r  rT   rT   rU   test_stack_1d[  s   zTestStack.test_stack_1dc                 C   s   t g ddd}t g ddd}t||gdd}t|jd t|j|d j t|j|d	 j t||g}t|j|j t|j|j t||gd	d}t|jd
 t|j|d d df j t|j|d d d	f j d S )Nr   Tr   rM  Fr   r   r  r<   rN  rO  rP  rT   rT   rU   test_stack_masksm  s   zTestStack.test_stack_masksc           
      C   s  d}t jdd|}t jdd|}t jdd|t}t jdd|t}t||d}t||d}t||gdd}d| }	t|j|	 t	|j
|d j
 t	|j
|d j
 t||gd	d}|d }	t|j|	 t	|j
|d
 j
 t	|j
|d j
 d}t jdd|}t jdd|}t jdd|t}t jdd|t}t||d}t||d}t||gdd}d| }	t|j|	 t	|j
|d j
 t	|j
|d j
 t||gd	d}|d }	t|j|	 t	|j
|d
 j
 t	|j
|d j
 d S )NrN  r   re   r9   r   r   r8   r<   r  ).r   ).r<   )rz   r9   r   r   )rO   r  randintrM  r   r   r4   r   r   r   r>   )
rP   shpd1d2r   r   a1rN  rW   c_shprT   rT   rU   test_stack_nd  sD   zTestStack.test_stack_ndN)r   r   r   rQ  rR  rY  rT   rT   rT   rU   rL  Y  s    rL  )O__doc__r  r  r   numpyrO   numpy._core.numericr   numpy.testingr   r   numpy.ma.testutilsr   r   r   r   numpy.ma.corer	   r
   r   r   r   r   r   r   r   r   r   numpy.ma.extrasr   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/   r0   r1   r2   r3   r4   r5   r6   r7   r   r   r  r   rj  rt  ry  r  r  r  r	  r;  r>  rL  rT   rT   rT   rU   <module>   sD   4
   ,F  4   Wk: |7&