ó
àÆ÷Xc           @` s¬   d  d l  m Z m Z m Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d l	 j
 Z d  d l m Z d  d l m Z d  d l m Z d e j f d „  ƒ  YZ d S(	   i    (   t   absolute_importt   print_functiont   divisionN(   t   SkipTest(   t   unittest_tools(   t   conv(   t	   _allcloset   TestSignalConv2Dc           B` s8   e  Z d  „  Z e d „ Z d „  Z d „  Z d „  Z RS(   c         C` s   t  j ƒ  d  S(   N(   t   uttt   seed_rng(   t   self(    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt   setUp   s    c         C` s  t  | ƒ } t  | ƒ } t j d t g | ƒ ƒ  } t j d t g | ƒ ƒ  } | d }	 | d k ro d }	 n  | d }
 | d k rŽ d }
 n  d „  } | | | ƒ } | j | k s» t ‚ t j | | g | ƒ } t j	 j	 | ƒ } t j	 j	 | ƒ } | | | ƒ } t j
 | d ƒ t j
 | d ƒ d } t j t | ƒ ƒ } | j |	 f | d ƒ } | j |
 f | d ƒ } | j |	 |
 f | j d ƒ } xQt |	 ƒ D]C} x:t |
 ƒ D],} | | d  d  … d  d  … f } | | d  d  … d  d  … f } t j | j ƒ } x¡ t | j d ƒ D]Œ } xƒ t | j d ƒ D]n } | | | f c | | | | j d … | | | j d … f | d  d  d … d  d  d … f j ƒ  7<q;Wq!W|  j t | | | d  d  … d  d  … f | ƒ ƒ q·Wq¤W| r
t j | | | g ƒ n  d  S(   Nt   float64i    i   i   c         S` s   t  j |  | ƒ S(   N(   R   t   conv2d(   t   inputt   filters(    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt
   sym_conv2d%   s    iþÿÿÿiÿÿÿÿ(   t   lent   Tt
   TensorTypet   Falset   ndimt   AssertionErrort   theanot   functiont   numpyt   randomt   arrayt   zerost   tuplet   reshapet   shapet   ranget   sumt
   assertTrueR   R   t   verify_grad(   R
   t   image_shapet   filter_shapet   out_dimR#   t	   image_dimt
   filter_dimR   R   t   bsizet   nkernR   t   outputt   theano_convt
   image_datat   filter_datat   theano_outputt   out_shape2dt
   ref_outputt   image_data3dt   filter_data3dt   theano_output4dt   bt   kt   image2dt   filter2dt   output2dt   rowt   col(    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt   validate   sL    
	
		(1(c         C` s¨   t  j j j j r4 t  j j d k r4 t d ƒ ‚ n  |  j d d d d d	 t	 ƒ|  j d d d d d	 t
 ƒ|  j d d d d d	 t
 ƒ|  j d d d d d	 t
 ƒd S(   sì   
        Basic functionality of nnet.conv.ConvOp is already tested by
        its own test suite.  We just have to test whether or not
        signal.conv.conv2d can support inputs and filters of type
        matrix or tensor3.
        t    s)   conv2d tests need SciPy or a c++ compileri   i   i   i   i   R&   R#   i   N(   i   i   i   (   i   i   i   (   i   i   (   i   i   i   (   i   i   i   (   i   i   (   i   i   (   i   i   (   R   t   tensort   nnetR   t   imported_scipy_signalt   configt   cxxR   R<   t   TrueR   (   R
   (    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt
   test_basicS   s    c         C` sN   |  j  t t j t j ƒ  t j ƒ  ƒ |  j  t t j t j ƒ  t j ƒ  ƒ d S(   sJ   
        Test that conv2d fails for dimensions other than 2 or 3.
        N(   t   assertRaisest	   ExceptionR   R   R   t   dtensor4t   dtensor3t   dvector(   R
   (    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt	   test_failc   s    %c         C` s2   t  j j ƒ  } t  j j ƒ  } t j | | ƒ d S(   sÔ   
        Test refers to a bug reported by Josh, when due to a bad merge these
        few lines of code failed. See
        http://groups.google.com/group/theano-dev/browse_thread/thread/8856e7ca5035eecb
        N(   R   R>   t   matrixR   R   (   R
   t   m1t   m2(    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt   test_bug_josh_reportedj   s    (   t   __name__t
   __module__R   RC   R<   RD   RJ   RN   (    (    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyR      s
   	>		(   t
   __future__R    R   R   t   unittestt   nose.plugins.skipR   R   R   t   theano.tensorR>   R   t   theano.testsR   R   t   theano.tensor.signalR   t   theano.tensor.basicR   t   TestCaseR   (    (    (    sD   /tmp/pip-build-X4mzal/theano/theano/tensor/signal/tests/test_conv.pyt   <module>   s   