o
    V=ºi)  ã                   @   s8  d Z ddlZddlZddlmZmZ ddlm  mZ ddl	Zddl	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 g d¢ZddlmZ g d	¢Zee Zd,dd„Zd-dd„Zd.dd„Zdd„ Zd.dd„Zd.dd„ZeZ d/dd„Z!e!Z"		
d0dd„Z#d1d d!„Z$d1d"d#„Z%d2d$d%„Z&d2d&d'„Z'd1d(d)„Z(d.d*d+„Z)dS )3zÌMiscellaneous functions for testing masked arrays and subclasses

:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
:version: $Id: testutils.py 3529 2007-11-13 08:01:14Z jarrod.millman $

é    N)ÚndarrayÚfloat_)Úassert_Úassert_allcloseÚassert_array_almost_equal_nulpÚassert_raisesÚbuild_err_msgé   )Úmask_orÚgetmaskÚmasked_arrayÚnomaskÚmaskedÚfilled)ÚalmostÚapproxÚassert_almost_equalÚassert_array_almost_equalÚassert_array_approx_equalÚassert_array_compareÚassert_array_equalÚassert_array_lessÚassert_closeÚassert_equalÚassert_equal_recordsÚassert_mask_equalÚassert_not_equalÚfail_if_array_equal)ÚTestCase)r   r   r   r   r   Tçñhãˆµøä>ç:Œ0âŽyE>c                 C   sª   t t| ƒt|ƒƒ}t| ƒ}t|ƒ}|jjdks|jjdkr%t ||¡ ¡ S tt|d|d�|ƒ 	t
¡}tt|d|d�dƒ 	t
¡}	t t ||	 ¡||t |	¡  ¡}
|
 ¡ S )a†  
    Returns true if all components of a and b are equal to given tolerances.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.  The relative error rtol should
    be positive and << 1.0 The absolute error atol comes into play for
    those elements of b that are very small or zero; it says how small a
    must be also.

    ÚOF©ÚcopyÚmaskr	   N)r
   r   r   ÚdtypeÚcharÚnpÚequalÚravelr   Úastyper   Z
less_equalÚumathÚabsolute)ÚaÚbÚ
fill_valueÚrtolZatolÚmÚd1Úd2ÚxÚyÚd© r7   úXC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\numpy/ma/testutils.pyr   )   s   $r   é   c           
      C   s¦   t t| ƒt|ƒƒ}t| ƒ}t|ƒ}|jjdks|jjdkr%t ||¡ ¡ S tt|d|d�|ƒ 	t
¡}tt|d|d�dƒ 	t
¡}t t || ¡|¡d|  k}	|	 ¡ S )z³
    Returns True if a and b are equal up to decimal places.

    If fill_value is True, masked values considered equal. Otherwise,
    masked values are considered unequal.

    r!   Fr"   r	   ç      $@N)r
   r   r   r%   r&   r'   r(   r)   r   r*   r   ZaroundÚabs)
r-   r.   Údecimalr/   r1   r2   r3   r4   r5   r6   r7   r7   r8   r   ?   s    r   Ú c                 C   sJ   t t| ƒt|ƒ|ƒ tt|ƒƒD ]}t | | || d|›d|› �ƒ qdS )z;
    Asserts the equality of two non-array sequences.

    úitem=Ú
N)r   ÚlenÚrange)ÚactualÚdesiredÚerr_msgÚkr7   r7   r8   Ú_assert_equal_on_sequencesR   s   "rF   c                 C   sd   t | j|jƒ | jjD ]$}t | |¡t ||¡}}|tur/|tur/t t | |¡t ||¡ƒ qdS )zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)r   r%   ÚnamesÚoperatorÚgetitemr   )r-   r.   ÚfÚafZbfr7   r7   r8   r   ]   s   €r   c                 C   s|  t |tƒrDt | tƒsttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ | ¡ D ]!\}}|| vr1t|› d| › �ƒ‚t| | || d|›d|› �ƒ q dS t |tt	fƒrYt | tt	fƒrYt
| |dd�S t | tƒstt |tƒstt| |g|ƒ}|| ksrt|ƒ‚dS | tu r||tus„|tu r’| tur’t| |g|ddd�}t|ƒ‚t | ¡} t |¡}| j|j}}|jd	kr¸|jd	kr¸t
|  ¡ | ¡ dd�S t| ||ƒS )
z,
    Asserts that two items are equal.

    z not in úkey=r?   Nr=   ©rD   ©r4   r5   )ÚheaderrG   ÚS)Ú
isinstanceÚdictÚAssertionErrorÚreprÚtyper   r@   ÚitemsÚlistÚtuplerF   r   r   r   Ú
ValueErrorr'   Z
asanyarrayr%   r&   Útolistr   )rB   rC   rD   rE   ÚiÚmsgZactual_dtypeZdesired_dtyper7   r7   r8   r   l   sD   

"ÿÿÿ

þr   c                 C   s.  t |tƒrAt | tƒsttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ | ¡ D ]\}}|| vr.tt|ƒƒ‚t| | || d|›d|› �ƒ q dS t |tt	fƒrtt | tt	fƒrttt| ƒt|ƒ|ƒ t
t|ƒƒD ]}t| | || d|›d|› �ƒ q_dS t | tjƒs€t |tjƒr†t| ||ƒS t| |g|ƒ}|| ks•t|ƒ‚dS )z<
    Raises an assertion error if two items are equal.

    rL   r?   Nr>   )rQ   rR   rS   rT   rU   Úfail_if_equalr@   rV   rW   rX   rA   r'   r   r   r   )rB   rC   rD   rE   r[   r\   r7   r7   r8   r]   “   s(   

""ÿr]   é   c                 C   s^   t | tjƒst |tjƒrt| ||||d�S t| |g||d�}tt||  ƒ|ƒdks-t|ƒ‚dS )z~
    Asserts that two items are almost equal.

    The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal).

    )r<   rD   Úverbose)rD   r_   r   N)rQ   r'   r   r   r   Úroundr;   rS   )rB   rC   r<   rD   r_   r\   r7   r7   r8   r   °   s   ÿÿÿr   c           	      C   s˜   t t|ƒt|ƒƒ}t|d|ddd�}t|d|ddd�}|tu r#|tus+|tu r:|tur:t||g|||dd�}t|ƒ‚tjj| | 	|¡| 	|¡|||d�S )zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r#   r$   Z	keep_maskZsubokrN   )rD   r_   rO   rG   ©rD   r_   rO   N)
r
   r   r   r   r   rY   r'   Ztestingr   r   )	Z
comparisonr4   r5   rD   r_   rO   r/   r1   r\   r7   r7   r8   r   Ã   s$   	ÿÿÿür   c                 C   ó   t tj| |||dd� dS )z@
    Checks the elementwise equality of two masked arrays.

    úArrays are not equalra   N)r   rH   Ú__eq__©r4   r5   rD   r_   r7   r7   r8   r   Ü   ó   

þr   c                 C   s    dd„ }t || |||dd� dS )zT
    Raises an assertion error if two masked arrays are not equal elementwise.

    c                 S   s   t  t| |ƒ¡ S )N)r'   Zalltruer   rN   r7   r7   r8   Úcompareë   s   z$fail_if_array_equal.<locals>.comparerc   ra   N©r   )r4   r5   rD   r_   rg   r7   r7   r8   r   æ   s   
ÿr   c                    ó$   ‡ fdd„}t || |||dd� dS )ú|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                    s   t | |dˆ   d�S )ú<Returns the result of the loose comparison between x and y).r:   )r0   N)r   rN   ©r<   r7   r8   rg   ø   s   z*assert_array_approx_equal.<locals>.compareúArrays are not almost equalra   Nrh   ©r4   r5   r<   rD   r_   rg   r7   rl   r8   r   ñ   ó   
ÿr   c                    ri   )rj   c                    s   t | |ˆ ƒS )rk   N)r   rN   rl   r7   r8   rg     s   z*assert_array_almost_equal.<locals>.comparerm   ra   Nrh   rn   r7   rl   r8   r   ÿ   ro   r   c                 C   rb   )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedra   N)r   rH   Ú__lt__re   r7   r7   r8   r     rf   r   c                 C   s:   | t u r
t|t u ƒ |t u rt| t u ƒ t| ||d� dS )z-
    Asserts the equality of two masks.

    rM   N)r   r   r   )Úm1Úm2rD   r7   r7   r8   r     s
   r   )Tr   r    )r9   T)r=   )r^   r=   T)r=   Tr=   T)r=   T)r9   r=   T)*Ú__doc__rH   Znumpyr'   r   r   Znumpy.core.umathÚcorer+   Znumpy.testingr   r   r   r   r   r
   r   r   r   r   r   Z__all__maskedZunittestr   Z__some__from_testingÚ__all__r   r   rF   r   r   r]   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r8   Ú<module>   s<     




'

ÿ






