a
    mJh"                     @   s   d dl Zd dl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mZ d dlmZ d dlmZ G dd deejZG d	d
 d
ZG dd dZG dd dZdS )    N)assert_warns)assert_assert_equalassert_raisesassert_array_equal)masked_arraymasked_valuesmaskedallequalMaskTypegetmaskMaskedArraynomasklogaddhypotdividemr_)picklec                   @   s,   e Zd ZefddZdd Zedd ZdS )MMatrixc                 C   s   t |}tj| ||d}|S )N)datamask)npmatrixr   __new__)clsr   r   Zmat_data r   Z/var/www/shaz/venv/lib/python3.9/site-packages/numpy/matrixlib/tests/test_masked_matrix.pyr      s    
zMMatrix.__new__c                 C   s   t j| | t| | d S N)r   r   __array_finalize__r   )selfobjr   r   r   r!      s    zMMatrix.__array_finalize__c                 C   s   |  t}d|_|S )NF)viewr   Z_sharedmask)r"   Z_viewr   r   r   _series   s    
zMMatrix._seriesN)__name__
__module____qualname__r   r   r!   propertyr%   r   r   r   r   r      s   r   c                   @   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 )TestMaskedMatrixc                 C   s  t g dg dg}t|g dg dgd}t|g dg dgd}t|}t| t| tt|d t|d u  t|d |d k t|d tu  t|d |d  t|d	d
d f |d	d
d f  t|d d df |d d df  t|d d  |d d   t|d
d  |d
d   d|d< d|d< t|| d|d	d
d f< d|d	d
d f< t|| t|d< t|| t|d	d
d f< t|| |d	d d f |d	d d f< t|d< tt	t
|t g dg dg tg dg d|d
d d f< tt	t
|d
 tg d tt	t
|d
 tg d tg dg d|d
d d f< tt	t
|d
 tg d tt	|d
 tg d t t dd }t|d}t|| tt	tg dtd|j td|j d S )N         )   r.   r-   r,   r   r   )r   r,   r   r   r,   r   )r,   r,   )r   r-   r   r,   r-   	   c   )r   r,   )r,   r,   r            ?      @)r   r   r   r,   r   Zdtype)r   r   r   strreprr   typer	   r   r
   r   arrayaranger   r   r   Z
fill_value)r"   x1Zx2Zx3Zx4r   r   r   test_matrix_indexing    sP    ""



$

z%TestMaskedMatrix.test_matrix_indexingc                 C   sz   t tttdg dd d}tdtjd D ]B}ttj||d}t	|j
|j
 t	|| tt|jtj q2d S )N
   )r,   r   r,   r   r   r-   r1   r,   )protocol)r   r   r   listranger   HIGHEST_PROTOCOLloadsdumpsr   _maskr   
isinstancer   )r"   aprotoZ	a_pickledr   r   r   test_pickling_subbaseclassL   s    "
z+TestMaskedMatrix.test_pickling_subbaseclassc                 C   s   t tddgddggtdd}t|jddjd	 t|jddjd
 t|jddddgg t|jdddgdgg d S )Nr,   r-   r.   r/   )r-   r-   r1   r   )Zaxis)r,   r-   )r-   r,   g       @r7   g      ?g      @)r   r   r   Zzerosr   countshapemean)r"   mr   r   r   test_count_mean_with_matrixU   s
    $z,TestMaskedMatrix.test_count_mean_with_matrixc                 C   sb  t tg dgg dd}t|jd d t|jd t tt|jdd |dddf k t tg dgg dd}t g dg dd|_t tg dgg dd}t|| t tg dgg dd}|j}|g d	 |d d < t|| d
|d< t ttddd}|j}|d d }t|j	t
ddgg t|jt
ddgg d S )Nr+   )r   r   r,   r1   r,   r-   r   )r.   r-   r,   r0   )r-   r,   r   r3   r6   g        F)r   r   r   r   Zflatr	   r   alleyer   r<   r   )r"   testcontrolZtestflatrI   bZb01r   r   r   	test_flat_   s$    (

zTestMaskedMatrix.test_flatc                 C   st  t g dg dg dg}t |}t jg dg dg dgt jd}t||d}|d	k}|d	k }t|   t|  t|d
t g d t|dt g dj	 t|d
t g d t|dt g dj	 t|   t|  t|d
t g d t|dt g dj	 t|d
t g d t|dt g dj	 d S )N)gp=
ף?gp=
ף?g?)gQ?gQ?g)\(?)gףp=
?gףp=
?gffffff?)TFF)FFF)TTFr8   r1   g      ?r   )FFTr,   )TTT)
r   r<   r   Zbool_r   r   rQ   anyr   T)r"   xXrO   ZmXZmXbigZmXsmallr   r   r   test_allany_onmatricesx   s4    


z'TestMaskedMatrix.test_allany_onmatricesc                 C   s`   t tg dg dd}| }t|| tt|tj t|d< | }t|g dg d S )N)r,   r-   r.   r/   )r   r   r   r   r1   )r   r   )r-   r.   r/   )r   r   r   
compressedr   r   rH   r	   )r"   rI   rU   r   r   r   test_compressed   s    
z TestMaskedMatrix.test_compressedc                 C   sD   t tg dg dgd}| }t|jd t|jj|j d S )N)r,   r-   r.   r/   r5   r   r,   r   r   r   r1   )r,   r5   )r   r   r   Zravelr   rM   rG   )r"   rI   Zaravelr   r   r   
test_ravel   s    zTestMaskedMatrix.test_ravelc                 C   s   t ttdtjd}t|}t|dtfdtfgd}d|j	d< |
tdftj}t|| tt|tj tt|t  d S )Nr@   rI   rU   r8   r2   r   r-   )rB   zipr   r=   randomZrandr<   r   floatr   r$   r   r   r   rH   r   )r"   iteratorr   rI   rS   r   r   r   	test_view   s    


zTestMaskedMatrix.test_viewN)r&   r'   r(   r?   rK   rP   rV   r[   r]   r_   rd   r   r   r   r   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 )TestSubclassingc                 C   s,   t jddd}t|g dd}||f| _d S )Nr5   rb   r8   r^   r1   )r   r=   r   r   r"   rY   mxr   r   r   setup_method   s    zTestSubclassing.setup_methodc                 C   s    | j \}}tt|jtj d S r    )r   r   rH   r   r   r   rf   r   r   r   test_maskedarray_subclassing   s    
z,TestSubclassing.test_maskedarray_subclassingc                 C   s`   | j \}}tjdd6 ttt|t tt|t| W d    n1 sR0    Y  d S )Nignore)r   )r   r   Zerrstater   rH   r   r   r   rf   r   r   r   test_masked_unary_operations   s    
z,TestSubclassing.test_masked_unary_operationsc                 C   s   | j \}}ttt||t ttt||t tt||||  ttt||jtj t	t
& ttt||t W d    n1 s0    Y  ttt||t ttt||t d S r    )r   r   rH   r   r   r   r   r   r   r   DeprecationWarningouterr   rf   r   r   r   test_masked_binary_operations   s    

4z-TestSubclassing.test_masked_binary_operationsc                 C   s`   | j \}}t|j  |jd}ttt||t ttt||t tt||t|| d S )Nr1   )	r   r   Z	__array__r   r   rH   r   r   r   )r"   rY   rg   Zxmxr   r   r   test_masked_binary_operations2   s
    
z.TestSubclassing.test_masked_binary_operations2N)r&   r'   r(   rh   ri   rk   rn   ro   r   r   r   r   re      s
   re   c                   @   s   e Zd Zdd Zdd ZdS )TestConcatenatorc                 C   s   t tjjdd  d S )Nc                   S   s   t d S )Nz
1, 2; 3, 4r   r   r   r   r   <lambda>       z6TestConcatenator.test_matrix_builder.<locals>.<lambda>)r   r   maZMAError)r"   r   r   r   test_matrix_builder   s    z$TestConcatenator.test_matrix_builderc                 C   sP   t d }tjtjd }t|| tt|t| tt|jt|j d S )N)rr,   r-   r.   )	r   r   rs   r<   Zr_r   r   r;   r   )r"   actualexpectedr   r   r   test_matrix   s
    
zTestConcatenator.test_matrixN)r&   r'   r(   rt   rx   r   r   r   r   rp      s   rp   )numpyr   Znumpy.testingr   Znumpy.ma.testutilsr   r   r   r   Znumpy.ma.corer   r   r	   r
   r   r   r   r   r   r   r   r   Znumpy.ma.extrasr   Znumpy.compatr   r   r   r*   re   rp   r   r   r   r   <module>   s   8 *