ó
àÆ÷Xc           @` s‘   d  d l  m Z m Z m Z d  d l Z d  d l j j Z d  d l	 m
 Z
 d  d l Z d  d l m Z d  d l Z d „  Z d „  Z d „  Z d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   xrange(   t   tensorc          C` sœ   t  j ƒ  }  t  j ƒ  } t j |  | g |  | ƒ } | t j d d d ƒt j d d d ƒƒ y | t j d ƒ ƒ Wn t k
 rŠ d  SXd s˜ t ‚ d  S(   Ni
   t   dtypet   int64s   should not get here(   t   Tt   lvectort   theanot   functiont   numpyt   onest	   TypeErrort   AssertionError(   t   xt   yt   f(    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   test_no_reuse
   s    +c       
   C` s›  t  j ƒ  }  x1 t d ƒ D]# } | r6 | | d } q |  } q Wd  } d } xHt j d t ƒ t j d t ƒ f t j d t ƒ t j d t ƒ f g D]þ\ } } t j	 |  g | d t j
 d | d | ƒ ƒ} t j	 |  g | d t j
 d | d | ƒ ƒ} t j | ƒ } t j | ƒ }	 t | ƒ }
 t |	 ƒ } d „  } | | ƒ | | ƒ k sXt ‚ | | ƒ | | ƒ k svt ‚ d	 „  } | | ƒ | | ƒ k st ‚ d
 „  } | | ƒ | | ƒ k sÄt ‚ | | ƒ | | ƒ k sât ‚ | t j d d d ƒƒ | t j d d d ƒƒ t j | ƒ } t j | ƒ } t | ƒ } t | ƒ } |
 | k sht |
 | f ƒ ‚ t | | ƒ d k  s• t | | | f ƒ ‚ q• Wd  S(   Ni   i
   t   fast_runt   allow_gct   modet	   optimizert   linkerc         S` s   t  t j |  j ƒ ƒ S(   N(   t   lent   picklet   dumpst   maker(   t   fn(    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   a>   s    c         S` s"   t  t j t j j j |  ƒ ƒ ƒ S(   N(   R   R   R   R	   t   compilet   function_modulet   _pickle_Function(   R   (    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   bC   s    c         S` s   t  t j |  ƒ ƒ S(   N(   R   R   R   (   R   (    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   cJ   s    id   R   t   float64i   (   R   t   dvectorR   t   NoneR	   t   PerformLinkert   Truet   Falset   OpWiseCLinkerR
   t   ModeR   R   R   R   R   R   t   abs(   R   t   it   rR   t   f_linkert   g_linkerR   t   gt   pre_ft   pre_gt	   len_pre_ft	   len_pre_gR   R!   R"   t   post_ft   post_gt
   len_post_ft
   len_post_g(    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt!   test_gc_never_pickles_temporaries   sJ    
"!!			c          C` s“   t  j ƒ  }  x1 t d ƒ D]# } | r6 | | d } q |  } q Wt j ƒ  } t j |  g | d d ƒ} t j ƒ  | } | d k  s t | ƒ ‚ d S(   sé   In the original merge optimization, the following graph took
    like caused the MERGE optimizer to exhibit really bad performance
    (quadratic? exponential?)

    Ironically, there is actually no merging to do in this graph.

    i2   i
   R   t   FAST_COMPILEg      @N(   R   R$   R   t   timeR	   R
   R   (   R   R,   R-   t   tR   t   dt(    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   test_merge_opt_runtimef   s    
(   t
   __future__R    R   R   R   t   six.moves.cPicklet   movest   cPickleR   t	   six.movesR   R	   R   R   R;   R   R9   R>   (    (    (    s;   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_gc.pyt   <module>   s   		M