ó
ÿ¼÷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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/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-2Vcwy8/numpy/numpy/ma/testutils.pyt   <module>   sB   :.			
	)	

