σ
ΨΖχXc           @` 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 m Z m Z m Z m Z m Z m Z m Z m Z d d l j j 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 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,  Z0 d! e" d-  Z1 d! d.  Z2 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   TestCaset   assert_t   assert_allcloset   assert_array_almost_equal_nulpt   assert_raisest   build_err_msgt   run_module_suitet   suppress_warningsi   (   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_equalR   R   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   /tmp/pip-build-X4mzal/numpy/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   decimalR0   R3   R4   R5   R6   R7   R8   (    (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyR   @   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   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyt   _assert_equal_on_sequencesS   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   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyR   ^   s    %,c   	   	   C` sd  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  snt |  | g |  } t   2 } | j t d  | |  k sdt |   n  Wd QXd S|  t k r| 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 rT| j d k rTt
 |  j   | j   d d St |  | |  S(   s,   
    Asserts that two items are equal.

    s   %s not in %ss	   key=%r
%sNRA   R<   s   .*NAT ==t   headerRD   R6   R7   R"   t   subokt   S(   R6   R7   (   t
   isinstancet   dictt   AssertionErrort   reprt   typeR   R=   t   itemst   listt   tupleRC   R   R
   R   t   filtert   FutureWarningR   t
   ValueErrorR&   t   arrayR)   t   TrueR$   R%   t   tolistR   (	   R?   R@   RA   RB   t   it   msgt   supt   actual_dtypet   desired_dtype(    (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyR   m   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(   RM   RN   RO   RP   RQ   t   fail_if_equalR=   RR   RS   RT   R>   R&   R   R    R
   (   R?   R@   RA   RB   R[   R\   (    (    s1   /tmp/pip-build-X4mzal/numpy/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).

    R;   RA   t   verbosei    N(   RM   R&   R   R   R
   t   roundR:   RO   (   R?   R@   R;   RA   Ra   R\   (    (    s1   /tmp/pip-build-X4mzal/numpy/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	 |  d | d | d | S(   sn   
    Asserts that comparison between two masked arrays is satisfied.

    The comparison is elementwise.

    R"   R#   t	   keep_maskRK   RA   Ra   RJ   RD   R6   R7   (   R6   R7   (
   R   R   R   R)   R   R
   RW   t   utilsR   R   (	   t
   comparisonR6   R7   RA   Ra   RJ   R0   R3   R\   (    (    s1   /tmp/pip-build-X4mzal/numpy/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.

    RA   Ra   RJ   s   Arrays are not equalN(   R   RE   t   __eq__(   R6   R7   RA   Ra   (    (    s1   /tmp/pip-build-X4mzal/numpy/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   (   R6   R7   (    (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyt   compareξ   s    RA   Ra   RJ   s   Arrays are not equalN(   R   (   R6   R7   RA   Ra   Rh   (    (    s1   /tmp/pip-build-X4mzal/numpy/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).R1   g      $@(   R   (   R6   R7   (   R;   (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyRh   ϋ   s    RA   Ra   RJ   s   Arrays are not almost equalN(   R   (   R6   R7   R;   RA   Ra   Rh   (    (   R;   s1   /tmp/pip-build-X4mzal/numpy/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   (   R6   R7   (   R;   (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyRh   	  s    RA   Ra   RJ   s   Arrays are not almost equalN(   R   (   R6   R7   R;   RA   Ra   Rh   (    (   R;   s1   /tmp/pip-build-X4mzal/numpy/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.

    RA   Ra   RJ   s   Arrays are not less-orderedN(   R   RE   t   __lt__(   R6   R7   RA   Ra   (    (    s1   /tmp/pip-build-X4mzal/numpy/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.

    RA   N(   R   R   R   (   t   m1t   m2RA   (    (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyR     s
    (3   t   __doc__t
   __future__R    R   R   RE   t   numpyR&   R   R   t   numpy.core.umatht   coreR,   t   numpy.testingR   R   R   R   R	   R
   R   R   t   numpy.testing.utilst   testingRd   R   R   R   R   R   R   t   __all__maskedt   __some__from_testingt   __all__RY   R   R   RC   R   R   R`   R   R   R   R   R   R    R   R   R   R   (    (    (    s1   /tmp/pip-build-X4mzal/numpy/numpy/ma/testutils.pyt   <module>   sB   :.			
	)	

