
;>"^}(                 @   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 d d d d d	  Z d  d d! d  Z d" d# d$  Z  d% d   Z! d" d& d  Z" d" d' d(  Z# e# Z$ d) d" d d* d
  Z% e% Z& d" d d" d d+ d  Z' d" d d, d  Z( d" d d- d  Z) d  d" d d. d  Z* d  d" d d/ d  Z+ d" d d0 d  Z, d" d1 d  Z- d S)2zMiscellaneous 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
   Tgh㈵>g:0yE>c             C   s   t  t |   t |   } t |   } t |  } | j j d k sW | j j d k rm t j | |  j   St t | d d d | |  j	 t
  } t t | d 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.

    OcopyFmaskr   )r   r   r   dtypecharnpequalravelr   astyper   
less_equalumathabsolute)ab
fill_valuertolZatolmd1d2xyd r8   D/home/birch/.local/lib/python3.5/site-packages/numpy/ma/testutils.pyr   +   s    $**0   c       
      C   s   t  t |   t |   } t |   } t |  } | j j d k sW | j j d k rm t j | |  j   St t | d d d | |  j	 t
  } t t | d 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"   r#   Fr$   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   s_   t  t |   t |  |  x< t t |   D]( } t  |  | | | d | | f  q/ Wd 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   s   t  |  j | j  xv |  j j D]h } t j |  |  t j | |  } } | t k	 r  | t k	 r  t  t j |  |  t j | |   q  Wd 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   s6  t  | t  r t  |  t  s6 t t t |      t t |   t |  |  x^ | j   D]P \ } } | |  k r t d | |  f   t |  | | | d | | f  q_ Wd St  | t t	 f  r t  |  t t	 f  r t
 |  | d d St  |  t  pt  | t  sCt |  | g |  } | |  k s?t |   d S|  t k r[| t k	 ss| t k r|  t k	 rt |  | g | d d d d } t |   t j |  d
 d d d }  t j | d
 d d d } |  j | j } } | j d k r&| j d k r&t
 |  j   | j   d d St |  | |  S)z,
    Asserts that two items are equal.

    z%s not in %sz	key=%r
%sNrB   r=   headerrE   r5   r6   r#   FsubokT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   s  t  | t  r t  |  t  s6 t t t |      t t |   t |  |  xZ | j   D]L \ } } | |  k r t t |    t |  | | | d | | f  q_ Wd St  | t t	 f  r<t  |  t t	 f  r<t t |   t |  |  x< t
 t |   D]( } t |  | | | d | | f  qWd St  |  t j  s`t  | t j  rpt |  | |  St |  | g |  } | |  k st |   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  rC t |  | d | d | d | St |  | g d | 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<   rB   verboser   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 d d d } t | d d d | d d d d } | t k r{ | t k	 s | t k r | t k	 r t | | g d | d | d | d	 d } t |   t j j |  | j	 |  | j	 |  d | d | d | S)zn
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    r#   Fr$   Z	keep_maskrK   rB   r\   rJ   rE   r5   r6   )r5   r6   )
r   r   r   r   r   rU   r'   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 d d S)z@
    Checks the elementwise equality of two masked arrays.

    rB   r\   rJ   zArrays are not equalN)r   rF   __eq__)r5   r6   rB   r\   r8   r8   r9   r      s    c          
   C   s2   d d   } t  | |  | d | d | 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>.comparerB   r\   rJ   zArrays are not equalN)r   )r5   r6   rB   r\   r`   r8   r8   r9   r       s    c          
      s8     f d d   } t  | |  | d | d | 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).r1   g      $@)r   )r5   r6   )r<   r8   r9   r`      s    z*assert_array_approx_equal.<locals>.comparerB   r\   rJ   zArrays are not almost equalN)r   )r5   r6   r<   rB   r\   r`   r8   )r<   r9   r      s    c          
      s8     f d d   } t  | |  | d | d | 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>.comparerB   r\   rJ   zArrays are not almost equalN)r   )r5   r6   r<   rB   r\   r`   r8   )r<   r9   r     s    c          
   C   s)   t  t j |  | d | d | d d d S)z7
    Checks that x is smaller than y elementwise.

    rB   r\   rJ   zArrays are not less-orderedN)r   rF   __lt__)r5   r6   rB   r\   r8   r8   r9   r     s    c             C   sO   |  t  k r t | t  k  | t  k r8 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
    ).__doc__
__future__r   r   r   rF   numpyr'   r   r   Znumpy.core.umathcorer,   Znumpy.testingr   r   r	   r
   r   r   r   r   r   r   r   Z__all__masked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   (.			
'	

