ó
àÆ÷Xc           @` sú  d  d l  m Z m Z m Z d  d l m Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 m Z d  d l m Z 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 d  d
 l m Z d „  Z d e f d „  ƒ  YZ e ƒ  Z d „  Z d e f d „  ƒ  YZ e d d d „  ƒ Z  e d d d „  ƒ Z! e d d d „  ƒ Z" e d d d „  ƒ Z# d „  Z$ e d d e$ ƒ Z% d „  Z& d „  Z' d „  Z( d  e j) f d! „  ƒ  YZ* d" „  Z+ d# e j) f d$ „  ƒ  YZ, d% „  Z- d& „  Z. d S('   i    (   t   absolute_importt   print_functiont   division(   t   deepcopyN(   t   graph(   t   Variablet   Applyt   Constant(   t   Type(   t   Op(   t   fg(   t   PerformLinkert
   WrapLinkert	   Container(   t   cmpc         C` s   t  |  t ƒ s t ‚ |  S(   N(   t
   isinstanceR   t   AssertionError(   t   x(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   as_variable   s    t   TDoublec           B` s   e  Z d  „  Z RS(   c         C` s
   t  | ƒ S(   N(   t   float(   t   selft   data(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   filter   s    (   t   __name__t
   __module__R   (    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR      s   c         C` s   t  t d  d  d |  ƒS(   Nt   name(   R   t   tdoublet   None(   R   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   double   s    t   MyOpc           B` s5   e  Z d Z d d „ Z d „  Z d „  Z d „  Z RS(	   t   ninR   t   implc         C` s(   | |  _  | |  _ | r$ | |  _ n  d  S(   N(   R   R   R    (   R   R   R   R    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   __init__&   s    		c         G` s   t  | ƒ |  j k s t ‚ g  | D] } t | ƒ ^ q" } x, | D]$ } | j t k	 rA t d ƒ ‚ qA qA Wt |  j d ƒ g } t	 |  | | ƒ S(   Ns   Error 1t   _R(
   t   lenR   R   R   t   typeR   t	   ExceptionR   R   R   (   R   t   inputst   it   inputt   outputs(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt	   make_node,   s    c         C` s   |  j  S(   N(   R   (   R   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   __str__5   s    c         C` s    | \ } |  j  | Œ  | d <d  S(   Ni    (   R    (   R   t   nodeR&   t   out_t   out(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   perform8   s    	(   s   nins   names   implN(   R   R   t	   __props__R   R!   R*   R+   R/   (    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR   "   s
   			i   t   Addc         C` s   |  | S(   N(    (   R   t   y(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   <lambda><   s    t   Subc         C` s   |  | S(   N(    (   R   R2   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR3   =   s    t   Mulc         C` s   |  | S(   N(    (   R   R2   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR3   >   s    t   Divc         C` s   |  | S(   N(    (   R   R2   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR3   ?   s    c         C` s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   R   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   notimplB   s    i   t   RaiseErrc          C` s1   t  d ƒ }  t  d ƒ } t  d ƒ } |  | | f S(   NR   R2   t   z(   R   (   R   R2   R:   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR&   I   s    c         C` s   t  ƒ  j |  ƒ } | S(   N(   R   t   accept(   t   fgrapht   lnk(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   perform_linkerP   s    c         C` s   t  j |  | ƒ } | S(   N(   R
   t   FunctionGraph(   R&   R)   t   e(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR?   U   s    t   TestPerformLinkerc           B` s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` s¡   t  ƒ  \ } } } t t | | ƒ t | | ƒ ƒ } t t | | | g | g ƒ ƒ j ƒ  \ } } } d | d _ d | d _ | ƒ  | d j d k s t ‚ d  S(   Ni   i    i   g      ø?(	   R&   t   mult   addt   divR>   R?   t
   make_thunkR   R   (   R   R   R2   R:   R@   t   fnR'   t   o(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt
   test_thunk[   s    !0c         C` s|   t  ƒ  \ } } } t t | | ƒ t | | ƒ ƒ } t t | | | g | g ƒ ƒ j ƒ  } | d d d ƒ d k sx t ‚ d  S(   Ng      ð?g       @g      @g      ø?(   R&   RB   RC   RD   R>   R?   t   make_functionR   (   R   R   R2   R:   R@   RF   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_functiond   s    !'c         C` s   t  ƒ  \ } } } t t d ƒ } t t | | ƒ t | | ƒ ƒ } t t | g | g ƒ ƒ j ƒ  } | d ƒ d k s{ t	 ‚ d  S(   Ng       @g      ð?g      ø?(
   R&   R   R   RB   RC   RD   R>   R?   RI   R   (   R   R   R2   R:   R@   RF   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_constantj   s
    !!c         C` sO   t  ƒ  \ } } } t t | g | g ƒ ƒ j ƒ  } d | d ƒ k sK t ‚ d  S(   Ng      ð?(   R&   R>   R?   RI   R   (   R   R   R2   R:   RF   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_input_output_sameq   s    !c         C` s’   t  ƒ  \ } } } t | | ƒ t | | ƒ } } t | | ƒ } t t t j | | | g | g ƒ Œ  ƒ j ƒ  } | d d d ƒ d k sŽ t	 ‚ d  S(   Ng      ð?g       @g      "@g      @(
   R&   RC   RD   RB   R>   R?   R   t   cloneRI   R   (   R   R   R2   R:   t   at   dR@   RF   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_input_dependency0v   s    c         C` sŽ   t  ƒ  \ } } } t | | ƒ } t | ƒ } t | | ƒ } t t t j | | | g | g ƒ Œ  ƒ j ƒ  } | d d d ƒ d k sŠ t ‚ d  S(   Ng      ð?g       @g      @g      @(	   R&   RC   t	   raise_errR>   R?   R   RM   RI   R   (   R   R   R2   R:   RN   t   rR@   RF   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_skiphole~   s    (   R   R   RH   RJ   RK   RL   RP   RS   (    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyRA   Z   s   						c         C` s   t  | | ƒ j |  ƒ } | S(   N(   R   R;   (   R<   t   linkerst   wrapperR=   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   wrap_linkerˆ   s    t   TestWrapLinkerc           B` s   e  Z d  „  Z d „  Z RS(   c   	      ` sã   g  ‰  ‡  f d †  } t  ƒ  \ } } } t t | | ƒ t | | ƒ ƒ } t t | | | g | g ƒ t d t ƒ g | ƒ j ƒ  \ } } } d | d _	 d | d _	 | ƒ  ˆ  t t t g k sÆ t
 ‚ | d j	 d  k sß t
 ‚ d  S(   Nc         ` s   ˆ  j  | j ƒ d  S(   N(   t   appendt   op(   R'   R,   t   th(   t   nodes(    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   wrap‘   s    t   allow_gci   i    i   (   R&   RB   RC   RD   RV   R?   R   t   FalseRE   R   R   R   (	   R   R\   R   R2   R:   R@   RF   R'   RG   (    (   R[   s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_0Ž   s    !'c   	      ` sã   g  ‰  ‡  f d †  } t  ƒ  \ } } } t t | | ƒ t | | ƒ ƒ } t t | | | g | g ƒ t d t ƒ g | ƒ j ƒ  \ } } } d | d _	 d | d _	 | ƒ  ˆ  t t t g k sÆ t
 ‚ | d j	 d k sß t
 ‚ d  S(   Nc         ` s   ˆ  j  | j ƒ | ƒ  d  S(   N(   RX   RY   (   R'   R,   RZ   (   R[   (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyR\   ¢   s    R]   i   i    i   g      ø?(   R&   RB   RC   RD   RV   R?   R   R^   RE   R   R   (	   R   R\   R   R2   R:   R@   RF   R'   RG   (    (   R[   s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_1Ÿ   s    !'(   R   R   R_   R`   (    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyRW      s   	c          C` s*  d d  l  }  d d l m } m } |  j j d ƒ } |  j j | d  d | j d ƒ j } d „  } |  j d | | ƒ ƒ } |  j	 d	 | ƒ } |  j
 | f | f d
 | ƒ} | j j j ƒ  d }	 | ƒ  }
 xX t |	 d  |	 d ƒ D]? \ } } |
 | | f ƒ sã t | ƒ t | ƒ k  s"t ‚ qã qã Wd  S(   Ni    (   t   sort_schedule_fnt   make_dependsR   i   i   i   c         S` s   t  t |  ƒ t | ƒ ƒ S(   N(   R   t   str(   RN   t   b(    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   str_cmp¸   s    t   schedulet   linkert   modeiÿÿÿÿ(   t   theanot   theano.gof.schedRa   Rb   t   tensort   matrixt   dott   Tt   OpWiseCLinkert   Modet   functiont   makerRg   t   make_allt   zipRc   R   (   Ri   Ra   Rb   R   R2   Re   Rg   Rh   t   fR[   t   dependsRN   Rd   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_sort_schedule_fn²   s    '		$c          C` s÷  t  j j ƒ  }  t j d d t  j j ƒ} t | t j ƒ sN t	 t
 | ƒ ƒ ‚ x¢t t g D]”} t |  | g d | ƒ} t | j d t j ƒ s¸ t	 | j d t
 | j d ƒ f ƒ ‚ | j d j | j k sð t	 | j d j | j f ƒ ‚ | j d j | j
 j k s.t	 | j d j | j
 j f ƒ ‚ t | ƒ } t | j d t j ƒ syt	 | j d t
 | j d ƒ f ƒ ‚ | j d j | j k s±t	 | j d j | j f ƒ ‚ | j d j | j
 j k s[ t	 | j d j | j
 j f ƒ ‚ q[ Wd S(   s6   
    This is a test to a work around a NumPy bug.
    g        t   dtypet   readonlyi    N(   Ri   Rk   t   scalart   npt   asarrayt   configt   floatXR   t   ndarrayR   R$   t   TrueR^   R   t   storageRx   R   (   t   tt   vRy   t   cRO   (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   test_container_deepcopyÆ   s     $&8,&8,(/   t
   __future__R    R   R   t   copyR   t   unittestt   numpyR{   Ri   t
   theano.gofR   t   theano.gof.graphR   R   R   t   theano.gof.typeR   t   theano.gof.opR	   R
   t   theano.gof.linkR   R   R   t   theano.compatR   R   R   R   R   R   RC   t   subRB   RD   R8   RQ   R&   R>   R?   t   TestCaseRA   RV   RW   Rw   R…   (    (    (    s:   /tmp/pip-build-X4mzal/theano/theano/gof/tests/test_link.pyt   <module>   s<   							.	%	