a
    !ñ»jD)  ã                   @   s0  d Z ddlZddlZddl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)Ú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j
¡}tt|d|d�dƒ 	tj
¡}	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   ÚastypeÚfloat64Z
less_equalÚumathÚabsolute)ÚaÚbÚ
fill_valueÚrtolZatolÚmÚd1Úd2ÚxÚyÚd© r7   ú8E:\soccer\ml_env\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rJt ||¡ ¡ S tt|d|d�|ƒ 	tj
¡}tt|d|d�dƒ 	tj
¡}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*   ÚaroundÚabs)
r-   r.   Údecimalr/   r1   r2   r3   r4   r5   r6   r7   r7   r8   r   A   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_sequencesV   s    "rG   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   a   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>   ©rE   ©r4   r5   )ÚheaderrH   ÚS)Ú
isinstanceÚdictÚAssertionErrorÚreprÚtyper   rA   ÚitemsÚlistÚtuplerG   r   r   r   Ú
ValueErrorr&   Z
asanyarrayr$   r%   Útolistr   )rC   rD   rE   rF   ÚiÚmsgZactual_dtypeZdesired_dtyper7   r7   r8   r   p   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.

    rN   r@   Nr?   )rS   rT   rU   rV   rW   Úfail_if_equalrA   rX   rY   rZ   rB   r&   r   r   r   )rC   rD   rE   rF   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=   rE   Úverbose)rE   ra   r   N)rS   r&   r   r   r   Úroundr<   rU   )rC   rD   r=   rE   ra   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subokrP   )rE   ra   rQ   rH   ©rE   ra   rQ   )
r	   r
   r   r   r   r[   r&   Ztestingr   r   )	Z
comparisonr4   r5   rE   ra   rQ   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 equalrc   N)r   rI   Ú__eq__©r4   r5   rE   ra   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&   Úallr   rP   r7   r7   r8   Úcompareï   s    z$fail_if_array_equal.<locals>.comparerd   rc   N©r   )r4   r5   rE   ra   rh   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   rP   ©r=   r7   r8   rh   ü   s    z*assert_array_approx_equal.<locals>.compareúArrays are not almost equalrc   Nri   ©r4   r5   r=   rE   ra   rh   r7   rl   r8   r   õ   s    ÿr   c                    s$   ‡ fdd„}t || |||dd� dS )rj   c                    s   t | |ˆ ƒS )rk   )r   rP   rl   r7   r8   rh   
  s    z*assert_array_almost_equal.<locals>.comparerm   rc   Nri   rn   r7   rl   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-orderedrc   N)r   rI   Ú__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.

    rO   N)r   r   r   )Úm1Úm2rE   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__rI   Únumpyr&   r   Znumpy._core.umathZ_corer+   Znumpy.testingr   r   r   r   r   Úcorer	   r
   r   r   r   r   Z__all__maskedZunittestr   Z__some__from_testingÚ__all__r   r   rG   r   r   r_   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r8   Ú<module>   s:    



'

  ÿ







