o
    h_=                     @   s   d dl Z d dlZd dlZd dlm  mZ d dlmZ ej	Z	G dd dZ
edkrpdZde Zd\ZZed	d
D ]9Zde Zeeeeed ZeeZede d  eede  eded  dded	 d q8dS dS )    N)build_err_msgc                   @   s   e Zd Zdd Z		d ddZd!ddZejd	d
dd Zejd	d
dd Z	ejd	d
dd Z
ejd	d
dd Zejd	d
dd Zejd	d
dd Zejd	d
dd Zejd	d
dd Zejd	d
dd Zejd	d
dd ZdS )"ModuleTesterc                 C   s  || _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	t
| _
|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _z|j| _W n ty~   |jj| _Y nw g | _d S N)moduleallequalarangearrayconcatenatecountequalfilledgetmaskgetmaskarrayidinner	make_maskmaskedmasked_arraymasked_valuesmask_ornomaskonesouterrepeatresizesorttake	transposezerosMaskTypeumathAttributeErrorcore	testnames)selfr    r%   V/var/www/Befach/backend/venv/lib/python3.10/site-packages/numpy/ma/timer_comparison.py__init__   sB   
zModuleTester.__init__ Tc              
   C   s,  |  |}|  |}| | || |}	|  | j||	d|}|  | j||	d|}|jjdkrR|tj}t	|tj
rK|jdkrKd|t|< nt|rRd}|jjdkrx|tj}t	|tj
rq|jdkrqd|t|< nt|rxd}z|jdkp|jdkp|j|jk}
|
st||g|d|j d|j d |d	d
}|
sJ ||||}|	| jur|r| j||	d}t	|tr|}
dg}n| }| }
| }|
sdd|d t|  }t||g|d|f  |d	d
}|
sJ |W dS W dS  ty } zt||g||d	d
}t||d}~ww )zZ
        Assert that a comparison of two masked arrays is satisfied elementwise.

        maskO   r   r%   z	
(shapes z, z
 mismatch)xy)headernamesd   g      Y@z
(mismatch %s%%)N)r   r   r   r   dtypecharastypenpfloat64
isinstancendarraysizeisnanshaper   r   boolravelalltolistr
   len
ValueError)r$   
comparisonr.   r/   err_msgr0   
fill_valuexfyfmcondmsgvalreducedmatcher%   r%   r&   assert_array_compare/   sl   



 


z!ModuleTester.assert_array_comparec                 C   s   | j | j|||dd dS )zH
        Checks the elementwise equality of two masked arrays.

        zArrays are not equal)rD   r0   N)rO   r   )r$   r.   r/   rD   r%   r%   r&   assert_array_equalf   s   
zModuleTester.assert_array_equalignore)r?   c                 C   sH   t ddddtd dddddddg}g d	}| j||d
}|d  dS )!
        Tests creation

              ?              @      @      @      $      $@      @r,   r   r   r   r   r   r,   r   r   r   r   r   r)   r   N)r6   r   pir   )r$   r.   rH   xmr%   r%   r&   test_0n   s   &zModuleTester.test_0c           	      C   s&  t ddddtd dddddddg}t g d	}g d
}g d}| j||d}| j||d}t |d|}|d || d sGJ |j}|j	t
dd |ksWJ | |t|t
dd | ksjJ dD ]$}||_||_||_||_||_| |t|t
dd | ksJ qldS )rR   rS   rT   rU   rV   rW   rX   rY   rZ   )rW           rZ   rU   g      g      r_   rX   rY   rS   r_   rZ   r[   )r   r   r,   r   r   r,   r,   r   r   r   r   r,   r)   g@xDr   c                 S   s   | | S r   r%   r-   r%   r%   r&   <lambda>       z%ModuleTester.test_1.<locals>.<lambda>c                 S      | | S r   r%   r-   r%   r%   r&   r`      ra   ))      )      c                 S   rb   r   r%   r-   r%   r%   r&   r`      ra   N)r6   r   r\   r   whereset_fill_valuer   anyr<   r:   	functoolsreducer
   rA   )	r$   r.   r/   m1m2r]   ymrF   sr%   r%   r&   test_1y   s(   &
&(zModuleTester.test_1c           	      C   s  t g d}| j|g dd}| j|g dd}| |}t| t| t|d t|d u s4J |d |d ks>J d|d< d|d< | || d|dd	< d|dd	< | j|d< | j|dd	< ||d
d
< | j|d< | g dg d|d
d
< | g dg d|d
d
< t dd }| 	|d}| g dt
}t g dt
}|d  |d  |dd jdksJ g d}| |}| |}||u sJ | j|dd}||usJ d
S )z2
        Tests conversions and indexing.

        )r,   rf   rc   rd   r,   r   r   r   r)   )r   r,   r   r,   r,   	   rf   c   rd   N)r,   rf   rd   rc   )r   r,   r,   r      rS   rZ   )r,   hellorf   rd   )r   )r   r   r,   r   r   )copy)r6   r   strreprtyperP   r   r   r   r   objectr<   r   )	r$   x1x2x3x4nrH   rm   m3r%   r%   r&   test_2   s@   




zModuleTester.test_2c                 C   s   |  d}| j|d< | |d}| | ||g|sJ | | |g ds*J | j|ddd}| |g d | j|ddd}| ||sJJ |jddd}| ||sYJ |dd}| ||sgJ d	S )
z&
        Tests resize/repeat

        rc   rf   )   )r   r   r,   r   r   r   r,   r   )rf   rf   rf   rf   r   axis)r   r   r,   r,   rf   rf   rd   rd   N)r   r   r   r   r	   r   r   rP   )r$   r~   y4y5y6y7y8r%   r%   r&   test_3   s   

zModuleTester.test_3c              	   C   s@  |  d}t d}| j|dd< |ddd}|ddd}| t|d| |ds/J | t|dd| |ddsAJ | t| |d	| |d	| ||sYJ | t	| |d	| |d	| 	||sqJ | 
g d
t}| j|d< | |g d}|d	 dksJ |d dksJ |d dksJ dS )zB
        Test of take, transpose, inner, outer products.

           rt   re   rf   rd   rc   )rf   r   r,   r,   r   )abcr,   defrf   rd   )r   rd   rc   r   N)r   r6   r   reshaper   r   r   r   r   r   r   rz   )r$   r.   r/   tr%   r%   r&   test_4   s&   

 $


zModuleTester.test_4c                 C   s  |  d}|  d}|  d}| j|d< |d7 }| ||d s"J |d7 }| ||d s0J |  d}|  d}| j|d< |d8 }| ||d sMJ |d8 }| ||d s[J |  dd }|  dd }| j|d< |d9 }| ||d s|J |d9 }| ||d sJ |  dd }|  dd }| j|d< |d }| ||sJ |d }| ||sJ |  dd }|  dd }| j|d< |d }| ||d sJ ||  d }| || d |  dtj}|  d}| j|d< |d7 }| ||d sJ dS )z*
        Tests inplace w/ scalar

        
   rf   r,   rS   rU   )r   N)r   r   r   rP   r   r5   r6   r7   )r$   r.   r/   r]   r%   r%   r&   test_5   sR   











zModuleTester.test_5c                 C   sB  | j dtjd}|  d}| j dtjd}| j|d< |j}| j dtjd}| j|d< ||7 }||7 }| ||| s<J | ||| sFJ | |j| ||jsTJ | j dtjd}| j dtjd}| j|d< |j}| j dtjd}| j|d< ||8 }||8 }| ||| sJ | ||| sJ | |j| ||jsJ | j dtjd}| j dtjd}| j|d< |j}| j dtjd}| j|d< ||9 }||9 }| ||| sJ | ||| sJ | |j| ||jsJ | j dtjd}| j dtjd}| j|d< |j}| j dtjd}| j|d< || }|| }dS )z)
        Tests inplace w/ array

        r   )r3   rf   N)r   r6   r7   r   r*   r   r   )r$   r.   r/   r]   rH   ar%   r%   r&   test_6!  sT   








zModuleTester.test_6c              	   C   s   | j dddtd gd ddgdgd  d| j dddtd gd ddgdgd  df}dD ]C}zt| j|}W n tyF   tt|}Y nw t| j|}|d	|j }|| }|| }| |	d|	d| | |j
|j
 q.d	S )
zTests ufuncrS   r   r   rf   r,   re   r)   )sqrtloglog10exp	conjugateN)r   r\   getattrr    r!   fromnumericr   ninrP   r   _mask)r$   dfufmfargsurmrr%   r%   r&   test_7U  s    **zModuleTester.test_7c              	   C   s  | j g dg dd}| d| j|dd | d| j|g dd | j|g dd	d
\}}| d| |dks;J | j|d d < | j|dd| ju sNJ | j g dg dd}|dd}| j|d d d	f< | | j|ddddg | j|d	dd | ju sJ | ddg| j|dd | j|dd	d\}}| |ddg g d}g dg dg}| d}| | j|ddd | | j|d|dd |  | dd| d g}| | |d tjtdd d  | | j|ddtdd d  | | j|d	d| j|dd| j|ddd g | | j|d |dd | | j|d|dg d | | j|d	d| j|dd| j|ddd g | 	d}g d}	g dg dg}
| 
d}g d}| | j| ||ddd | | j| ||	ddd | | j| ||ddd | | | j| ||ddd | ||
}| | |d d | | j|ddg d | | j|d	dddg | | j|d|dg d d S )N)r_   rS   rU   rZ   rq   r)   rU   r   r   )rS   rS   rU   rS   )weightsr,   )r   returnedrV   rf   r_   )r   r   rS   )r   r,   r,   r,   r,   r   )r,   r   r   r   r   r,   re   g      @)r   r   rZ   g      (@g
@)r_   rS   rU   rZ   rV   rY   )r   r   r,   r,   r   r   )r   r,   r,   r,   r,   r,   )r_   rS        X@r   rV   g      @rW   )r_   rS   r   r   rV   rY   )r   rP   averager   r   r   r6   addrk   r   r   r   r
   )r$   ottresultwtsw1w2r.   r/   rl   rm   r   m4m5zr%   r%   r&   test_99x  sT   
*$22

$ zModuleTester.test_99c                 C   s*   |  d}| j|dd< |ddd}d S )Nr   rt   re   rf   rd   rc   )r   r   r   )r$   r.   r%   r%   r&   test_A  s   
zModuleTester.test_AN)r(   r(   T)r(   )__name__
__module____qualname__r'   rO   rP   r6   errstater^   rp   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r      s4    "

7







*





4

3

"

-r   __main__zNfrom __main__ import ModuleTester 
import numpy
tester = ModuleTester(module)
zimport numpy.ma.core as module
)r   r   r,   r   ztester.test_%i()r   z#%iz2..................................................zModuleTester.test_%i.__doc__zcore_current : z.3fz - )rj   timeitnumpyr6   numpy._core.fromnumeric_corer   numpy.testingr   r\   r   r   
setup_base	setup_curnrepeatnlooprangeifuncTimerr   curr   printevalr%   r%   r%   r&   <module>   s.       $
"