
[c           @` s  d  d l  m Z m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 m Z d d l m Z g  Z xJ d d d d	 g D]6 Z x- d d d d	 g D] Z e j e e f  q Wq We d
 d g Z d d
 f Z d d d f Z e e j e e e e f   Z d d d d f Z e e j e e e e f e e f   Z d   Z d e f d     YZ d e f d     YZ  e j! j" d e  d    Z# d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   assert_allcloset   assert_array_almost_equal_nulpi   (   t   convolve_fftu   >f4u   <f4u   >f8u   <f8u   fillu   wrapu   interpolateu   boundaryu   nan_treatmentu   normalize_kernelu   preserve_nanc         C` s0   t  |  | d d t j |  j    d d d S(   u  Assert arrays are close to within expected floating point rounding.

    Check that the result is correct at the precision expected for 64 bit
    numbers, taking account that the tolerance has to reflect that all powers
    in the FFTs enter our values.
    t   atoli
   t   rtolg        N(   R   t   npt   spacingt   max(   t   xt   y(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   assert_floatclose/   s    	t   TestConvolve1Dc           B` s  e  Z e j j e e  d     Z e j j e e  d    Z e j j e e  d    Z	 e j j e e  d    Z
 e j j e e  d    Z e j d e j d g d d e j d e j d g d d f Z e j d d	 d g d d e j d d	 d g d d f Z e e j e e e e f e e f e e   Z e j j e d e  d    Z e j j e e  d    Z d   Z d   Z d   Z  e j j e e  d    Z! RS(   c      	   C` sh   t  j d d d g d d } t  j d g d d } t | | d | d | d | } t | |  d	 S(
   uV   
        Test that a unit kernel with a single element returns the same array
        g      ?g       @g      @t   dtypeu   float64t   boundaryt   nan_treatmentt   normalize_kernelN(   R	   t   arrayR   R   (   t   selfR   R   R   R   R   t   z(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_1_none=   s    	c      	   C` sn   t  j d d d g d d } t  j d d d g d d } t | | d | d | d	 | } t | |  d
 S(   u|   
        Test that a unit kernel with three elements returns the same array
        (except when boundary is None).
        g      ?g       @g      @R   u   float64g        R   R   R   N(   R	   R   R   R   (   R   R   R   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_3M   s    	c      	   C` s  t  j d d d g d d } t  j d d d g d d } t | | d | d | d | } | | | f } i t  j d d	 d g d d d
 6t  j d d d g d d d 6t  j d	 d	 d	 g d d d 6t  j d d d g d d d 6} i | d d d t f 6| d d d t f 6| d
 d d t f 6| d d d t f 6}	 x9 t |	 j    D]% }
 |	 |
 |	 |
 d d |
 d f <qWWxL t |	 j    D]8 }
 |
 d d k r|	 |
 |	 d |
 d |
 d f <qqWt | |	 |  d S(   u   
        Test that the different modes are producing the correct results using
        a uniform kernel with three elements
        g      ?g        g      @R   u   float64R   R   R   g      @u   sum_fill_zerosi   i   u   average_fill_zerosu   sum_wrapu   average_wrapu   fillu   interpolateu   wrapi    i   NgUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?(	   R	   R   R   t   Truet   Falset   listt   keyst   NoneR   (   R   R   R   R   R   R   R   t
   answer_keyt   answer_dictt   result_dictt   k(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_uniform_3^   s,    	"#&c   	   	   C` s  t  j d d d g d d } t  j d d d g d d } t | | d | d | d	 | } i t  j d d
 d g d d d 6t  j d d
 d g d d d 6t  j d d
 d g d d d 6t  j d d d g d d d 6t  j d
 d
 d
 g d d d 6t  j d d d g d d d 6t  j d d  d g d d d 6t  j d d! d g d d d 6} | rjd } n d } | d k r| d 7} n
 | d 7} t | | |  d S("   u   
        Test that the different modes are producing the correct results using
        a uniform, non-unity kernel with three elements
        g      ?g        g      @R   u   float64g      ?R   R   R   g       @g      ?u   sumu	   sum_zerosu   sum_nozerosi   i   u   averageu   sum_wrapu   average_wrapu   average_zerosu   average_nozerosu   wrapu   _wrapu   _zerosNgUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?gUUUUUU?(   R	   R   R   R   (	   R   R   R   R   R   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_halfity_3   s*    	"	
c         C` s   t  j d t  j d g d d } t  j d d d g d d } t | | d | d | d | d	 | } | r t  j | d
  s t  n  t  j |  } t | d d d g  d S(   u   
        Test that a unit kernel with three elements returns the same array
        (except when boundary is None). This version includes a NaN value in
        the original array.
        g      ?g      @R   u   float64g        R   R   R   t   preserve_nani   N(   R	   R   t   nanR   t   isnant   AssertionErrort
   nan_to_numR   (   R   R   R   R   R$   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_3_withnan   s    	!	g      ?g      @R   u   float64g        u   invalu   outvalc   
      C` s   | } t  j d g d d } t | | d | d | d | d | }	 | rg t  j |	 d  sg t  n  t  j |	  }	 t |	 |  d	 S(
   u   
        Test that a unit kernel with three elements returns the same array
        (except when boundary is None). This version includes a NaN value in
        the original array.
        g      ?R   u   float64R   R   R   R$   i   N(   R	   R   R   R&   R'   R(   R   (
   R   R   R   R   R$   t   invalt   outvalR   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_1_withnan   s    
	c         C` s  t  j d t  j d g d d } t  j d d d g d d } t | | d | d | d | d | } | r t  j | d	  s t  n  i t  j d d
 d g d d d 6t  j d d
 d g d d d 6t  j d d
 d g d d d 6t  j d d
 d g d d d 6t  j d d d g d d d 6t  j d
 d
 d
 g d d d 6t  j d! d" d# g d d d 6t  j d d d g d d d 6t  j d$ d% d& g d d d 6t  j d d d g d d d 6t  j d' d( d) g d d d 6t  j d* d+ d, g d d d 6} xC t | j    D]/ }	 d |	 k r| |	 d d | |	 d <qqW| rWd }
 n d }
 | d k rv|
 d 7}
 n
 |
 d 7}
 | d k r|
 d 7}
 n  t  j t  j	 |   } t
 | | | |
 |  d  S(-   u   
        Test that the different modes are producing the correct results using
        a uniform kernel with three elements. This version includes a NaN
        value in the original array.
        g      ?g      @R   u   float64R   R   R   R$   i   g      @u   sumu   sum_nozerosu	   sum_zerosu   sum_nozeros_interpnang       @u   averageu   sum_wrapi   u   average_wrapi   u   average_wrap_interpnani   u   average_nozerosu   average_nozeros_interpnanu   average_zerosu   average_zeros_interpnanu
   _interpnanu   wrapu   _wrapu   _zerosu   interpolateNgUUUUUU?gUUUUUU?gUUUUUU?g      ?gUUUUUU?g      ?gUUUUUU?gUUUUUU?g      ?g      ?g       @g      ?(   R	   R   R%   R   R&   R'   R   R   t   wheret   isfiniteR   (   R   R   R   R   R$   R   R   R   R   t   keyR   t   posns(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_uniform_3_withnan   sD    	!	"!	
c         C` s   t  j d t  j d g d d } t  j d d d g  } t  j j | d d d d g } t | | d d	 d
 t  j } t | d d d g  d  S(   Ng      ?g      @R   u   float64i   t   maski    R   u   fillt
   fill_valuei   i   (   R	   R   R%   t   mat   masked_arrayR   R   (   R   R   t   kernelR5   t   result(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_nan_fill#  s
    !!c         C` s   t  j d t  j d g d d } t  j d d d g  } t  j j | d d d d g } t | | d d	 d
 t  j } t | d d d g  t  j d t  j d g d d } t  j d d d g  } t  j j | d d d d g } t | | d d	 d
 t  j } t | d d d g  d S(   uF   
        Check whether convolve_fft works with masked arrays.
        g      ?g      @R   u   float64i   R2   i    R   u   fillR3   i   i   N(   R	   R   R%   R4   R5   R   R   (   R   R   R6   R5   R7   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_masked_array,  s    !!!!c         C` sP   d d d g } d d d g } t  | | d t j } t | d d d g  d S(   uP   
        Check if convolve_fft works when passing a normalize function.
        i   i   i   R   i   i   N(   R   R	   R   R   (   R   R   R6   R7   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_normalize_function?  s    c      
   C` s   t  j d d d g  } t  j d g  } d } | d | d g } x` | D]X } | | }	 t | |	 d | d | d	 | }
 | r t |
 |  qK t |
 | |	  qK Wd
 S(   up   
        Check that if normalize_kernel is False then the normalization
        tolerance is respected.
        i   i   i   g      ?g-C6?i
   R   R   t   normalization_zero_tolN(   R	   R   R   R   (   R   R   R   R   R   t   base_kernelt   normalization_rtolt
   norm_errort   errR6   R7   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_normalization_is_respectedH  s    
	(   u   invalu   outval("   t   __name__t
   __module__t   pytestt   markt   parametrizet   option_namest   optionsR   R   R"   R#   t   option_names_preserve_nant   options_preserve_nanR)   R	   R   R%   t   inft   inputst   outputsR   t	   itertoolst   productt   BOUNDARY_OPTIONSt   NANTREATMENT_OPTIONSR   R   t   options_unity1withnanR,   R1   R8   R9   R:   R@   (    (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyR   ;   s*   ''$!		:					t   TestConvolve2Dc           B` s   e  Z e j j e e  d     Z e j j e e  d    Z e j j e e  d    Z	 e j j e
 e  d    Z e j j e
 e  d    Z d   Z e j j d e  d    Z RS(   c      	   C` s   t  j d d d g d d d g d d d	 g g d
 d } t  j d g g d
 d } t | | d | d | d | } t | |  d S(   uD   
        Test that a 1x1 unit kernel returns the same array
        g      ?g       @g      @g      @g      @g      @g      @g       @g      "@R   u   float64R   R   R   N(   R	   R   R   R   (   R   R   R   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_1x1_nonej  s    	c      	   C` s   t  j d d d g d d d g d d d	 g g d
 d } t  j d d d g d d d g d d d g g d
 d } t | | d | d | d | } t | |  d S(   ul   
        Test that a 3x3 unit kernel returns the same array (except when
        boundary is None).
        g      ?g       @g      @g      @g      @g      @g      @g       @g      "@R   u   float64g        R   R   R   N(   R	   R   R   R   (   R   R   R   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_3x3|  s    	c         C` s  t  j d d d g d d d g d d d g g d d } t  j d d d g d d d g d d d g g d d } t | | d | d | d	 | r t  j n d
 d | } t  j d d d g d d d g d d d g g d d } i t  j d d d g d d d g d d d g g d d d 6t  j d d d g d d d g d d d g g d d d 6} | d | | d <| d d | d <| d d | d <| d | d <| rd }	 n d }	 | d k r|	 d 7}	 n | d k r|	 d 7}	 n  | |	 }
 t | |
  d S(   uu   
        Test that the different modes are producing the correct results using
        a 3x3 uniform kernel.
        g        g      @g      ?g       @R   u   float64R   R   R3   i    R   g      @g      @g      "@g      @u   sumu   sum_wrapu   averageu   average_wrapu   average_withzerosu   sum_withzerosu   wrapu   _wrapu   fillu
   _withzerosN(   R	   R   R   R%   R   (   R   R   R   R   R   R   R   t   wR   R   t   a(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_uniform_3x3  sB    		
c         C` s   t  j d d d g d t  j d g d d d g g d	 d
 } t  j d d d g d d d g d d d g g d	 d
 } t | | d | d | d | d | } | r t  j | d  s t  t  j |  } n  t  j |  } t | |  d S(   u   
        Test that a 3x3 unit kernel returns the same array (except when
        boundary is None). This version includes a NaN value in the original
        array.
        g      ?g       @g      @g      @g      @g      @g       @g      "@R   u   float64g        R   R   R   R$   i   N(   i   i   (   R	   R   R%   R   R&   R'   R(   R   (   R   R   R   R   R$   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_unity_3x3_withnan  s    		c         C` s  t  j d d d g d t  j d g d d d g g d d } t  j d d d g d d d g d d d g g d d } t | | d | d | d	 | r t  j n d
 d | d | } | r t  j | d'  s t  n  t  j d d d g d d d g d d d g g d d } t  j d d d g d d d g d d d g g d d }	 i t  j d d d g d d d g d d d g g d d d 6t  j d d d g d d d g d d d g g d d d 6}
 |
 d |	 |
 d <|
 d | |
 d <|
 d d |
 d <|
 d d |
 d <|
 d d |
 d <|
 d d |
 d <|
 d |
 d <|
 d d d |
 d <|
 d |
 d <|
 d d d |
 d <| rd } n d } | d  k r| d! 7} n | d" k r| d# 7} n  | d$ k r| d% 7} n  |
 | } t  j t  j |   } t | | | |  d& S((   u   
        Test that the different modes are producing the correct results using
        a 3x3 uniform kernel. This version includes a NaN value in the
        original array.
        g        g      @g      ?g       @R   u   float64R   R   R3   i    R   R$   i   g      @g       @g      @g      @g      "@u   sumu   sum_wrapu   averageu   average_interpnanu   average_wrap_interpnanu   average_wrapu   average_withzerosu   average_withzeros_interpnanu   sum_withzerosi	   u   sum_interpnanu   sum_withzeros_interpnanu   sum_wrap_interpnanu   wrapu   _wrapu   fillu
   _withzerosu   interpolateu
   _interpnanN(   i   i   (	   R	   R   R%   R   R&   R'   R-   R.   R   (   R   R   R   R   R$   R   R   R   t   w_nt   w_zR   R   RV   R0   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_uniform_3x3_withnan  s`    			
c         C` sN   t  j t t f  3 t j d d d g d t j } t | |  Wd QXd S(   uN    Test that convolve_fft raises an exception if a too-large array is passed in i   R   N(   RC   t   raisest
   ValueErrort   MemoryErrorR	   t   emptyt   complexR   (   R   t   arr(    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_big_fail5  s    !u   boundaryc      	   C` sA  t  j d d d g d d d g d d d g g d d } t  j d d d g d d d g d d d g g d d } t | | d	 | d
 d d t } | d k r t | t  j d d d g d d d g d d d g g d d  n[ | d k r1t | t  j d d d g d d d g d d d g g d d  n t d   d  S(   Ng        g      @g      ?g       @g      @R   u   floatg      R   R   u   fillR   g      g      g       u   wrapg       g      @g      @g      u   Invalid boundary specification(   Nu   fill(   R	   R   R   R   R   R   R]   (   R   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_non_normalized_kernel@  s"    	(   RA   RB   RC   RD   RE   RF   RG   RS   RT   RW   RH   RI   RX   R[   Rb   RO   Rc   (    (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyRR   h  s   1U	c         C` s   t  j d d d g d d } t  j d d d g d d } t | | d	 |  d
 t } |  d k r t | t  j d d d g d d d  n7 |  d k r t | t  j d d d g d d d  n  d S(   uT   
    Make sure that asymmetric convolution
    functions go the right direction
    g      @g        g      ?R   u   >f8i   i   i   R   R   u   fillg      @g      $@g       @u   floati
   u   wrapg      "@g      @N(   Nu   fill(   R	   R   R   R   R   R   (   R   R   R   R   (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   test_asymmetric_kernelY  s    +($   t
   __future__R    R   R   R   RM   RC   t   numpyR	   t   numpy.testingR   R   t   convolveR   t   VALID_DTYPESt   dtype_arrayt   dtype_kernelt   appendR   RO   RP   RF   R   RN   R   R   RG   RH   RI   R   t   objectR   RR   RD   RE   Rd   (    (    (    sJ   lib/python2.7/site-packages/astropy/convolution/tests/test_convolve_fft.pyt   <module>   s4   "		 .