ó
àÆ÷Xc           @` s=  d  d l  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	 d  d l
 m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l j Z d  d l m Z m Z m Z d  d	 l m Z d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z d „  Z  d „  Z! d „  Z" d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   functiont   config(   t   scalar(   t   FunctionGraph(   t   out2in(   t   local_alloc_dimshufflet   local_reshape_dimshufflet   local_dimshuffle_alloct   local_dimshuffle_subtensor(   t   CAReducet   Elemwiset
   DimShuffle(   t   unittest_toolst   T_max_and_argmaxc           B` s   e  Z d  „  Z RS(   c         C` sJ  t  j j j ƒ  j d d ƒ } x%d d d g D]} t j t j j d d ƒ d t	 j
 ƒ} t j ƒ  } t | g t j | | ƒ d d	 | ƒ} | j j j ƒ  } t | ƒ d k s¹ t ‚ t | d j t ƒ sÕ t ‚ t | g t j | | ƒ d	 | ƒ} | j j j ƒ  } t | ƒ d k s#t ‚ t | d j t j ƒ s. t ‚ q. Wd  S(
   Nt   canonicalizet   fast_runi    i   iÿÿÿÿi   i   t   dtypet   mode(   t   theanot   compileR   t   get_default_modet	   includingt   numpyt   asarrayt   randomt   randR   t   floatXt   tensort   matrixR   t   max_and_argmaxt   makert   fgrapht   toposortt   lent   AssertionErrort
   isinstancet   opR   t   MaxAndArgmax(   t   selfR   t   axist   datat   nt   ft   topo(    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_optimization   s    '($(   t   __name__t
   __module__R/   (    (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyR      s   t	   T_min_maxc           B` s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C` s/   t  j ƒ  t j j j ƒ  j d d ƒ |  _ d  S(   NR   R   (   t   uttt   seed_rngR   R   R   R   R   (   R)   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   setUp.   s    
c         C` s­  t  j t  j j d d ƒ d t j ƒ} t j ƒ  } xsd d d g D]b} t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k sš t ‚ t | d j t ƒ s¶ t ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k st ‚ t | d j t ƒ s.t ‚ t | d j j t j ƒ sPt ‚ t | d j t ƒ slt ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k sÈt ‚ t | d j t ƒ sät ‚ t | d j t ƒ s t ‚ t | d j j t j ƒ s"t ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k st ‚ t | d j t ƒ s›t ‚ | | ƒ qC Wd  S(   Ni   i   R   i    i   iÿÿÿÿR   (   R   R   R   R   R   R   R   R   R   t   maxR   R!   R"   R#   R$   R%   R&   R'   R   R   t	   scalar_opR   t   Neg(   R)   R+   R,   R*   R-   R.   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_optimization_max3   s6    ''
("
("
)c         C` s­  t  j t  j j d d ƒ d t j ƒ} t j ƒ  } xsd d d g D]b} t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k sš t ‚ t | d j t ƒ s¶ t ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k st ‚ t | d j t ƒ s.t ‚ t | d j t ƒ sJt ‚ t | d j j t j ƒ slt ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k sÈt ‚ t | d j t ƒ sät ‚ t | d j j t j ƒ st ‚ t | d j t ƒ s"t ‚ | | ƒ t | g t j	 | | ƒ d |  j
 ƒ} | j j j ƒ  } t | ƒ d k st ‚ t | d j t ƒ s›t ‚ | | ƒ qC Wd  S(   Ni   i   R   i    i   iÿÿÿÿR   (   R   R   R   R   R   R   R   R   R   t   minR   R!   R"   R#   R$   R%   R&   R'   R   R   R7   R   R8   (   R)   R+   R,   R*   R-   R.   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_optimization_minT   s6    ''
("
("
)(   R0   R1   R5   R9   R;   (    (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyR2   -   s   		!c          C` s¼   t  t ƒ }  t j d ƒ } t j d ƒ } | j d d ƒ } t j | | d | j d ƒ } t | | g | g ƒ } |  | ƒ | j	 ƒ  } t
 g  | D] } t | t ƒ ^ q“ ƒ s¸ t ‚ d  S(   Nt   xt   mi    i   (   R   R   R   t   vectort   iscalart
   dimshufflet   alloct   shapeR   R#   t   anyR&   R   R%   (   t   alloc_dimshuffleR<   R=   t   yt   outt   gR.   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_local_alloc_dimshufflew   s    
c          C` s¾   t  t ƒ }  t j d ƒ } | j d d d d ƒ } t j | d | j d | j d d f ƒ } t | g | g ƒ } |  | ƒ | j ƒ  } t	 g  | D] } t
 | t ƒ ^ q• ƒ sº t ‚ d  S(   NR<   i    i   (   R   R	   R   R   R@   t   reshapeRB   R   R#   RC   R&   R   R%   (   t   reshape_dimshuffleR<   RE   RF   RG   R.   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_local_reshape_dimshuffleˆ   s    -
c          C` sé   t  t ƒ }  t j d ƒ } t j | d d ƒ j d d d d ƒ } t | g | g ƒ } |  | ƒ t j j	 ƒ  } | j
 | ƒ | j ƒ  } | d d g ƒ j d k sª t ‚ | j ƒ  } t g  | D] } t | t ƒ ^ qÀ ƒ så t ‚ d  S(   NR<   i   i   i    i   i   (   R   R
   R   R>   RA   R@   R   R   t   goft   PerformLinkert   acceptt   make_functiont   ndimR%   R#   RC   R&   R   (   RJ   R<   RF   RG   t   lR-   R.   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_local_dimshuffle_alloc˜   s    '
!c          C` s=  t  t ƒ }  t j d ƒ } t j | t t t t f ƒ } t j d ƒ } | d  d  … d  d  … d d … d  d  | … f j d d d ƒ } t	 | | g | g ƒ } |  | ƒ | j
 ƒ  } t g  | D] } t | t ƒ ^ qÀ ƒ så t ‚ t j d t t t f d	 d
 ƒ } | | j d ƒ } t	 | | g | g ƒ } |  | ƒ | j
 ƒ  } t g  | D] } t | t ƒ ^ qQƒ svt ‚ t j d t t t t f d	 d
 ƒ } | | j d ƒ } t j | | g | ƒ } | j j j
 ƒ  } t g  | D] } t | t ƒ ^ qáƒ st ‚ | t j j d d d d ƒ d ƒ j d k s9t ‚ d  S(   NR<   t   ii
   i   i    i   i   t   broadcastableR   t   float64i   i   i   (   i   (   R   R   R   t   dtensor4t   patternbroadcastt   Falset   TrueR?   R@   R   R#   RC   R&   R   R%   R   R   R!   R"   R   R   R   RB   (   t   dimshuffle_subtensorR<   RS   RF   RG   R.   R-   (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   test_local_dimshuffle_subtensor­   s,    @
/!
/	/(#   t
   __future__R    R   R   t   unittestR   R   R   R   R   t
   theano.gofR   t   theano.gof.optR   t    theano.tensor.opt_uncanonicalizeR   R	   R
   R   t   theano.tensorR   t   theano.tensor.elemwiseR   R   R   t   theano.testsR   R3   t   TestCaseR   R2   RH   RK   RR   R[   (    (    (    sK   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_opt_uncanonicalize.pyt   <module>   s"   "J			