3
ßL]}(  ã               @   s`  d Z ddlmZmZmZ ddlZddlZddlmZm	Z	 ddl
jj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 dd	d
dddddddddddgZddlmZ dddddgZee Zd2dd	„Zd3d!d„Zd4d#d$„Z d%d„ Z!d5d&d„Z"d6d'd(„Z#e#Z$d7d*d
„Z%e%Z&d8d+d„Z'd9d,d„Z(d:d-d„Z)d;d.d„Z*d<d/d„Z+d=d0d„Z,d>d1d„Z-dS )?zÌ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 $

é    )ÚdivisionÚabsolute_importÚprint_functionN)Ú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)ÚTestCaser!   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j||ƒjƒ S tt|d|d�|ƒj	t
ƒ}tt|d|d�dƒj	t
ƒ}	tjtj||	 ƒ||tj|	ƒ  ƒ}
|
jƒ 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ÚumathZabsolute)ÚaÚbÚ
fill_valueÚrtolZatolÚmÚd1Úd2ÚxÚyÚd© r8   ú5/tmp/pip-install-q_7g0qgj/Numpy/numpy/ma/testutils.pyr   +   s    $é   c       
      C   s¦   t t| ƒt|ƒƒ}t| ƒ}t|ƒ}|jjdks:|jjdkrJtj||ƒjƒ S tt|d|d�|ƒj	t
ƒ}tt|d|d�dƒj	t
ƒ}tjtj|| ƒ|ƒd|  k}	|	jƒ 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$   F)r%   r&   r   g      $@)r   r   r   r'   r(   r)   r*   r+   r   r,   r   ZaroundÚabs)
r.   r/   Údecimalr0   r2   r3   r4   r5   r6   r7   r8   r8   r9   r   A   s     Ú c             C   sJ   t t| ƒt|ƒ|ƒ x0tt|ƒƒD ] }t | | || d||f ƒ q"W dS )z;
    Asserts the equality of two non-array sequences.

    z
item=%r
%sN)r   ÚlenÚrange)ÚactualÚdesiredÚerr_msgÚkr8   r8   r9   Ú_assert_equal_on_sequencesT   s     rD   c             C   sh   t | j|jƒ xT| jjD ]H}tj| |ƒtj||ƒ }}|tk	r|tk	rt tj| |ƒtj||ƒƒ qW dS )zI
    Asserts that two records are equal.

    Pretty crude for now.

    N)r   r'   ÚnamesÚoperatorÚgetitemr   )r.   r/   ÚfÚafZbfr8   r8   r9   r   _   s    c             C   s�  t |tƒr†t | tƒs$ttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ xH|jƒ D ]<\}}|| krbtd|| f ƒ‚t| | || d||f ƒ qBW dS t |tt	fƒr°t | tt	fƒr°t
| |dd�S t | tƒpÂt |tƒsæt| |g|ƒ}|| ksât|ƒ‚dS | tkoô|tk	�s|tk�r(| tk	�r(t| |g|ddd�}t|ƒ‚tj| d	d
d�} tj|d	d
d�}| j|j }}|jdk�r„|jdk�r„t
| jƒ |jƒ dd�S t| ||ƒS )z,
    Asserts that two items are equal.

    z%s not in %sz	key=%r
%sNr=   )rB   r5   r6   )ÚheaderrE   FT)r%   ÚsubokÚS)r5   r6   )Ú
isinstanceÚdictÚAssertionErrorÚreprÚtyper   r>   ÚitemsÚlistÚtuplerD   r   r   r   Ú
ValueErrorr)   Úarrayr'   r(   Útolistr   )r@   rA   rB   rC   ÚiÚmsgZactual_dtypeZdesired_dtyper8   r8   r9   r   n   s:    

 c             C   s4  t |tƒr‚t | tƒs$ttt| ƒƒƒ‚tt| ƒt|ƒ|ƒ xD|jƒ D ]8\}}|| kr^tt|ƒƒ‚t| | || d||f ƒ qBW dS t |tt	fƒrèt | tt	fƒrètt| ƒt|ƒ|ƒ x0t
t|ƒƒD ] }t| | || d||f ƒ qÀW 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.

    z	key=%r
%sNz
item=%r
%s)rM   rN   rO   rP   rQ   Úfail_if_equalr>   rR   rS   rT   r?   r)   r   r    r   )r@   rA   rB   rC   rX   rY   r8   r8   r9   rZ   •   s&    

  
rZ   é   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<   rB   Úverbose)rB   r\   r   N)rM   r)   r   r   r   Úroundr;   rO   )r@   rA   r<   rB   r\   rY   r8   r8   r9   r   ²   s    

c       	      C   s˜   t t|ƒt|ƒƒ}t|d|ddd�}t|d|ddd�}|tkrF|tk	sV|tkrt|tk	rtt||g|||dd�}t|ƒ‚tjj| |j	|ƒ|j	|ƒ|||d�S )zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    F)r%   r&   Z	keep_maskrK   r5   r6   )rB   r\   rJ   rE   )rB   r\   rJ   )r5   r6   )
r   r   r   r   r   rU   r)   Ztestingr   r   )	Z
comparisonr5   r6   rB   r\   rJ   r0   r2   rY   r8   r8   r9   r   Å   s    	
c             C   s   t tj| |||dd� dS )z@
    Checks the elementwise equality of two masked arrays.

    zArrays are not equal)rB   r\   rJ   N)r   rF   Ú__eq__)r5   r6   rB   r\   r8   r8   r9   r   Þ   s    
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 jt| |ƒƒ S )N)r)   Zalltruer   )r5   r6   r8   r8   r9   Úcompareí   s    z$fail_if_array_equal.<locals>.comparezArrays are not equal)rB   r\   rJ   N)r   )r5   r6   rB   r\   r_   r8   r8   r9   r    è   s    c                s$   ‡ fdd„}t || |||dd� dS )z|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                s   t | |dˆ   d�S )z<Returns the result of the loose comparison between x and y).g      $@)r1   )r   )r5   r6   )r<   r8   r9   r_   ú   s    z*assert_array_approx_equal.<locals>.comparezArrays are not almost equal)rB   r\   rJ   N)r   )r5   r6   r<   rB   r\   r_   r8   )r<   r9   r   ó   s    c                s$   ‡ fdd„}t || |||dd� dS )z|
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c                s   t | |ˆ ƒS )z<Returns the result of the loose comparison between x and y).)r   )r5   r6   )r<   r8   r9   r_     s    z*assert_array_almost_equal.<locals>.comparezArrays are not almost equal)rB   r\   rJ   N)r   )r5   r6   r<   rB   r\   r_   r8   )r<   r9   r     s    c             C   s   t tj| |||dd� dS )z7
    Checks that x is smaller than y elementwise.

    zArrays are not less-ordered)rB   r\   rJ   N)r   rF   Ú__lt__)r5   r6   rB   r\   r8   r8   r9   r     s    
c             C   s:   | t krt|t kƒ |t kr(t| t kƒ t| ||d� dS )z-
    Asserts the equality of two masks.

    )rB   N)r   r   r   )Úm1Úm2rB   r8   r8   r9   r     s
    )Tr"   r#   )r:   T)r=   )r=   )r=   )r[   r=   T)r=   Tr=   T)r=   T)r=   T)r:   r=   T)r:   r=   T)r=   T)r=   ).Ú__doc__Ú
__future__r   r   r   rF   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   rD   r   r   rZ   r   r   r   r   r   r    r   r   r   r   r8   r8   r8   r9   Ú<module>   sD    



'

 







