ó
¢áSc           @` s²  d  Z  d d l m Z m Z m Z d Z d Z d Z d 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 Td d l j j Z d
 d l m Z m Z m Z m Z m Z m Z m Z m 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_functions5   Pierre GF Gerard-Marchant ($Author: jarrod.millman $)s   1.0s   $Revision: 3529 $s5   $Date: 2007-11-13 10:01:14 +0200 (Tue, 13 Nov 2007) $N(   t   ndarrayt   float_(   t   *i   (   t   mask_ort   getmaskt   masked_arrayt   nomaskt   maskedt   filledt   equalt   lessgñ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(   ss  Returns true if all components of a and b are equal subject 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   npR   t   ravelR   t   Falset   astypeR   t
   less_equalt   umatht   absolute(   t   at   bt
   fill_valuet   rtolt   atolt   mt   d1t   d2t   xt   yt   d(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   approx   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   R   R    R!   R"   R#   R$   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   almost0   s    $***t    c         C` s_   t  t |  ƒ t | ƒ | ƒ x< t t | ƒ ƒ D]( } t  |  | | | d | | f ƒ q/ Wd S(   s0   Asserts the equality of two non-array sequences.s
   item=%r
%sN(   t   assert_equalt   lent   range(   t   actualt   desiredt   err_msgt   k(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   _assert_equal_on_sequencesA   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(   s9   Asserts that two records are equal. Pretty crude for now.N(   R+   R   t   namest   operatort   getitemR
   (   R   R   t   ft   aft   bf(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   assert_equal_recordsH   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
%sNR0   R*   t   headerR3   R"   R#   R   t   subokt   S(   R"   R#   (   t
   isinstancet   dictt   AssertionErrort   reprt   typeR+   R,   t   itemst   listt   tupleR2   R   t   build_err_msgR
   t
   ValueErrorR   t   arrayR   t   TrueR   R   t   tolistt   assert_array_equal(   R.   R/   R0   R1   t   it   msgt   actual_dtypet   desired_dtype(    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyR+   R   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(   s6   Raises an assertion error if two items are equal.
    s	   key=%r
%sNs
   item=%r
%s(   R=   R>   R?   R@   RA   t   fail_if_equalR,   RB   RC   RD   R-   R   R   t   fail_if_array_equalRE   (   R.   R/   R0   R1   RK   RL   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyRO   ~   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(   sv   Asserts that two items are almost equal.
    The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal)
    R(   R0   t   verbosei    N(   R=   R   R   t   assert_array_almost_equalRE   t   roundR'   R?   (   R.   R/   R(   R0   RQ   RL   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   assert_almost_equal˜   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(   sZ   Asserts that a comparison relation between two masked arrays is satisfied
    elementwise.R   R   t	   keep_maskR;   R0   RQ   R:   R3   R"   R#   (   R"   R#   (
   R   R   R   R   R
   RE   RF   t   utilst   assert_array_compareR   (	   t
   comparisonR"   R#   R0   RQ   R:   R   R   RL   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyRW   ¨   s    $$	c      
   C` s)   t  t j |  | d | d | d d ƒd S(   s5   Checks the elementwise equality of two masked arrays.R0   RQ   R:   s   Arrays are not equalN(   RW   R4   t   __eq__(   R"   R#   R0   RQ   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyRJ   À   s    c      
   C` s/   d „  } t  | |  | d | d | d d ƒd S(   sK   Raises an assertion error if two masked arrays are not equal (elementwise).c         S` s   t  j t |  | ƒ ƒ S(   N(   R   t   alltrueR%   (   R"   R#   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   compareÉ   s    R0   RQ   R:   s   Arrays are not equalN(   RW   (   R"   R#   R0   RQ   R[   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyRP   Ç   s    	c      
   ` s5   ‡  f d †  } t  | |  | d | d | d d ƒd S(   s[   Checks the elementwise equality of two masked arrays, up to a given
    number of decimals.c         ` s   t  |  | d d ˆ  ƒS(   s<   Returns the result of the loose comparison between x and y).R   g      $@(   R%   (   R"   R#   (   R(   (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyR[   Ò   s    R0   RQ   R:   s   Arrays are not almost equalN(   RW   (   R"   R#   R(   R0   RQ   R[   (    (   R(   sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   assert_array_approx_equalÏ   s    c      
   ` s5   ‡  f d †  } t  | |  | d | d | d d ƒd S(   s[   Checks the elementwise equality of two masked arrays, up to a given
    number of decimals.c         ` s   t  |  | ˆ  ƒ S(   s<   Returns the result of the loose comparison between x and y).(   R)   (   R"   R#   (   R(   (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyR[   Ü   s    R0   RQ   R:   s   Arrays are not almost equalN(   RW   (   R"   R#   R(   R0   RQ   R[   (    (   R(   sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyRR   Ù   s    c      
   C` s)   t  t j |  | d | d | d d ƒd S(   s,   Checks that x is smaller than y elementwise.R0   RQ   R:   s   Arrays are not less-orderedN(   RW   R4   t   __lt__(   R"   R#   R0   RQ   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   assert_array_lessã   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.R0   N(   R	   t   assert_RJ   (   t   m1t   m2R0   (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   assert_mask_equalê   s
    (.   t   __doc__t
   __future__R    R   R   t
   __author__t   __version__t   __revision__t   __date__R4   t   numpyR   R   R   t   numpy.core.umatht   coreR   t   numpy.testingt   numpy.testing.utilst   testingRV   R   R   R   R	   R
   R   R   R   RH   R%   R)   R2   R9   R+   RO   t   assert_not_equalRT   t   assert_closeRW   RJ   RP   R\   RR   R^   Rb   (    (    (    sL   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/ma/testutils.pyt   <module>   s:   
:	
,	

