σ
ϊ$]c           @` 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 e d d d  Z d e d   Z  d! d"  Z! d#   Z" d! d$  Z# d! d%  Z$ e$ Z% d& d! e d'  Z& e& Z' d! e d! e d(  Z( d! e d)  Z) d! e d*  Z* d d! e d+  Z+ d d! e d,  Z, d! e d-  Z- d! d.  Z. d S(/   sΜ   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 $

i    (   t   divisiont   absolute_importt   print_functionN(   t   ndarrayt   float_(   t   assert_t   assert_allcloset   assert_array_almost_equal_nulpt   assert_raisest   build_err_msgi   (   t   mask_ort   getmaskt   masked_arrayt   nomaskt   maskedt   filledt   almostt   approxt   assert_almost_equalt   assert_array_almost_equalt   assert_array_approx_equalt   assert_array_comparet   assert_array_equalt   assert_array_lesst   assert_closet   assert_equalt   assert_equal_recordst   assert_mask_equalt   assert_not_equalt   fail_if_array_equal(   t   TestCaseR   R   R   R   R   gρhγ΅ψδ>g:0βyE>c         C` sϋ   t  t |   t |   } t |   } t |  } | j j d k sW | j j d k rm t j | |  j   St t | d t	 d | |  j
 t  } t t | d t	 d | d  j
 t  }	 t j t j | |	  | | t j |	   }
 |
 j   S(   s  
    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.

    t   Ot   copyt   maski   (   R
   R   R   t   dtypet   chart   npt   equalt   ravelR   t   Falset   astypeR   t
   less_equalt   umatht   absolute(   t   at   bt
   fill_valuet   rtolt   atolt   mt   d1t   d2t   xt   yt   d(    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   +   s    $**0i   c   
      C` sυ   t  t |   t |   } t |   } t |  } | j j d k sW | j j d k rm t j | |  j   St t | d t	 d | |  j
 t  } t t | d t	 d | d  j
 t  } t j t j | |  |  d | k }	 |	 j   S(   s³   
    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    R!   i   g      $@(   R
   R   R   R"   R#   R$   R%   R&   R   R'   R(   R   t   aroundt   abs(
   R,   R-   t   decimalR.   R1   R2   R3   R4   R5   R6   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   A   s    $***t    c         C` s_   t  t |   t |  |  x< t t |   D]( } t  |  | | | d | | f  q/ Wd S(   s;   
    Asserts the equality of two non-array sequences.

    s
   item=%r
%sN(   R   t   lent   range(   t   actualt   desiredt   err_msgt   k(    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyt   _assert_equal_on_sequencesT   s    &c         C` s   t  |  j | j  xy |  j j D]k } t j |  |  t j | |  } } | t k	 r  | t k	 r  t  t j |  |  t j | |   q  q  Wd S(   sI   
    Asserts that two records are equal.

    Pretty crude for now.

    N(   R   R"   t   namest   operatort   getitemR   (   R,   R-   t   ft   aft   bf(    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   _   s    %,c         C` sB  t  | t  r½ t  |  t  s9 t t t |      n  t t |   t |  |  xa | j   D]S \ } } | |  k r t d | |  f   n  t |  | | | d | | f  qb Wd St  | t t	 f  rϊ t  |  t t	 f  rϊ t
 |  | d d St  |  t  pt  | t  sLt |  | g |  } | |  k sHt |   n  d S|  t k rd| t k	 s|| t k r¬|  t k	 r¬t |  | g | d d d d } t |   n  t j |  d
 t d t }  t j | d
 t d t } |  j | j } } | j d k r2| j d k r2t
 |  j   | j   d d St |  | |  S(   s,   
    Asserts that two items are equal.

    s   %s not in %ss	   key=%r
%sNR?   R:   t   headerRB   R4   R5   R    t   subokt   S(   R4   R5   (   t
   isinstancet   dictt   AssertionErrort   reprt   typeR   R;   t   itemst   listt   tupleRA   R   R	   R   t
   ValueErrorR$   t   arrayR'   t   TrueR"   R#   t   tolistR   (   R=   R>   R?   R@   t   it   msgt   actual_dtypet   desired_dtype(    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   n   s:    &*c         C` sͺ  t  | t  rΉ t  |  t  s9 t t t |      n  t t |   t |  |  x] | j   D]O \ } } | |  k r t t |    n  t |  | | | d | | f  qb Wd St  | t t	 f  rBt  |  t t	 f  rBt t |   t |  |  x< t
 t |   D]( } t |  | | | d | | f  qWd St  |  t j  sft  | t j  rvt |  | |  St |  | g |  } | |  k s¦t |   n  d S(   s<   
    Raises an assertion error if two items are equal.

    s	   key=%r
%sNs
   item=%r
%s(   RK   RL   RM   RN   RO   t   fail_if_equalR;   RP   RQ   RR   R<   R$   R   R   R	   (   R=   R>   R?   R@   RW   RX   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR[      s&    &*&$i   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 |   n  d S(   s~   
    Asserts that two items are almost equal.

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

    R9   R?   t   verbosei    N(   RK   R$   R   R   R	   t   roundR8   RM   (   R=   R>   R9   R?   R\   RX   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   ²   s    $c   	      C` s  t  t |  t |   } t | d t d | d t d t } t | d t d | d t d t } | t k r{ | t k	 s | t k rΜ | t k	 rΜ t | | g d | d | d | d d } t |   n  t j j	 |  | j
 |  | j
 |  d | d | d | S(   sn   
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    R    R!   t	   keep_maskRI   R?   R\   RH   RB   R4   R5   (   R4   R5   (   R
   R   R   R'   R   R	   RS   R$   t   testingR   R   (	   t
   comparisonR4   R5   R?   R\   RH   R.   R1   RX   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   Ε   s    	$$c      
   C` s)   t  t j |  | d | d | d d d S(   s@   
    Checks the elementwise equality of two masked arrays.

    R?   R\   RH   s   Arrays are not equalN(   R   RC   t   __eq__(   R4   R5   R?   R\   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   ή   s    c      
   C` s/   d   } t  | |  | d | d | d d d S(   sT   
    Raises an assertion error if two masked arrays are not equal elementwise.

    c         S` s   t  j t |  |   S(   N(   R$   t   alltrueR   (   R4   R5   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyt   compareν   s    R?   R\   RH   s   Arrays are not equalN(   R   (   R4   R5   R?   R\   Rc   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   θ   s    	c      
   ` s5     f d   } t  | |  | d | d | d d d S(   s|   
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c         ` s   t  |  | d d   S(   s<   Returns the result of the loose comparison between x and y).R/   g      $@(   R   (   R4   R5   (   R9   (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyRc   ϊ   s    R?   R\   RH   s   Arrays are not almost equalN(   R   (   R4   R5   R9   R?   R\   Rc   (    (   R9   s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR   σ   s    c      
   ` s5     f d   } t  | |  | d | d | d d d S(   s|   
    Checks the equality of two masked arrays, up to given number odecimals.

    The equality is checked elementwise.

    c         ` s   t  |  |    S(   s<   Returns the result of the loose comparison between x and y).(   R   (   R4   R5   (   R9   (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyRc     s    R?   R\   RH   s   Arrays are not almost equalN(   R   (   R4   R5   R9   R?   R\   Rc   (    (   R9   s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR     s    c      
   C` s)   t  t j |  | d | d | d d d S(   s7   
    Checks that x is smaller than y elementwise.

    R?   R\   RH   s   Arrays are not less-orderedN(   R   RC   t   __lt__(   R4   R5   R?   R\   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR     s    c         C` sU   |  t  k r t | t  k  n  | t  k r> t |  t  k  n  t |  | d | d S(   s-   
    Asserts the equality of two masks.

    R?   N(   R   R   R   (   t   m1t   m2R?   (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyR     s
    (/   t   __doc__t
   __future__R    R   R   RC   t   numpyR$   R   R   t   numpy.core.umatht   coreR*   t   numpy.testingR   R   R   R   R	   R
   R   R   R   R   R   t   __all__maskedt   unittestR   t   __some__from_testingt   __all__RU   R   R   RA   R   R   R[   R   R   R   R   R   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/numpy/ma/testutils.pyt   <module>   sD   (.			
	'	

