a
    hÝEbÿ'  ã                   @   s4  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d0dd„ZeZ d1dd„Z!e!Z"d2dd„Z#d3d d!„Z$d4d"d#„Z%d5d$d%„Z&d6d&d'„Z'd7d(d)„Z(d8d*d+„Z)dS )9zÌ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rJt ||¡ ¡ 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	   )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   úR/home/ja/django-apps/lartica_env/lib/python3.9/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rJt ||¡ ¡ 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	   ç      $@)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 ]H}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ÚafÚbfr7   r7   r8   r   ]   s    r   c                 C   s†  t |tƒrˆt | tƒs$ttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ | ¡ D ]B\}}|| vrbt|› d| › �ƒ‚t| | || d|›d|› �ƒ q@dS t |tt	fƒr²t | tt	fƒr²t
| |dd�S t | tƒsèt |tƒsèt| |g|ƒ}|| ksät|ƒ‚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�rz|jd	k�rzt
|  ¡ | ¡ 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   s4  t |tƒr‚t | tƒs$ttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ | ¡ D ]<\}}|| vr\tt|ƒƒ‚t| | || d|›d|› �ƒ q@dS t |tt	fƒrèt | tt	fƒrètt| ƒt|ƒ|ƒ t
t|ƒƒD ]$}t| | || d|›d|› �ƒ q¾dS t | tjƒ�st |tjƒ�rt| ||ƒS t| |g|ƒ}|| k�s0t|ƒ‚dS )z<
    Raises an assertion error if two items are equal.

    rM   r?   Nr>   )rR   rS   rT   rU   rV   Úfail_if_equalr@   rW   rX   rY   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sZt|ƒ‚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)rR   r'   r   r   r   Úroundr;   rT   )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 rF|tusV|tu rt|turtt||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subokrO   )rD   r`   rP   rG   ©rD   r`   rP   )
r
   r   r   r   r   rZ   r'   Útestingr   r   )	Z
comparisonr4   r5   rD   r`   rP   r/   r1   r]   r7   r7   r8   r   Ã   s$    	ÿÿÿür   c                 C   s   t tj| |||dd� dS )z@
    Checks the elementwise equality of two masked arrays.

    úArrays are not equalrb   N)r   rH   Ú__eq__©r4   r5   rD   r`   r7   r7   r8   r   Ü   s    
þ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   rO   r7   r7   r8   Úcompareë   s    z$fail_if_array_equal.<locals>.comparerd   rb   N©r   )r4   r5   rD   r`   rg   r7   r7   r8   r   æ   s    ÿr   c                    s$   ‡ 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   )r   rO   ©r<   r7   r8   rg   ø   s    z*assert_array_approx_equal.<locals>.compareúArrays are not almost equalrb   Nrh   ©r4   r5   r<   rD   r`   rg   r7   rk   r8   r   ñ   s    ÿr   c                    s$   ‡ fdd„}t || |||dd� dS )ri   c                    s   t | |ˆ ƒS )rj   )r   rO   rk   r7   r8   rg     s    z*assert_array_almost_equal.<locals>.comparerl   rb   Nrh   rm   r7   rk   r8   r   ÿ   s    ÿr   c                 C   s   t tj| |||dd� dS )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-orderedrb   N)r   rH   Ú__lt__rf   r7   r7   r8   r     s    
þ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.

    rN   N)r   r   r   )Úm1Úm2rD   r7   r7   r8   r     s
    r   )Tr   r    )r9   T)r=   )r=   )r=   )r_   r=   T)r=   Tr=   T)r=   T)r=   T)r9   r=   T)r9   r=   T)r=   T)r=   )*Ú__doc__rH   Ú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:    



'

  ÿ







