ó
àÆ÷Xc           @` s  d  d l  m Z m Z m Z d  d l Z d  d l j j 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 m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l Z e d „ Z  d „  Z! d e j" f d „  ƒ  YZ# d e j" f d „  ƒ  YZ$ d e% f d „  ƒ  YZ& d „  Z' e( d k r‰e j) ƒ  n  d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   configt   gof(   t	   iteritems(   t   Int   Out(   t   function(   t   UnusedInputError(   t   MissingInputError(   t   exc_message(   t   SkipTest(   t   tensorc         C` s   t  j t  j |  | ƒ d | ƒS(   Nt   ignore_newtrees(   R   t   OpKeyOptimizert
   PatternSub(   t   p1t   p2t   ign(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   PatternOptimizer   s    c         C` sE   y | ƒ  Wn) t  k
 r6 } t | | ƒ r0 d  S‚  n X|  j ƒ  d  S(   N(   t	   Exceptiont
   isinstancet   fail(   t   testcaset   fnt   Et   e(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   checkfor   s    t
   T_functionc           B` s  e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  RS(   c         C` sI   t  g  d  ƒ } | ƒ  } | g  k r3 t d ƒ ‚ n | d  k sE t ‚ d  S(   Ns@   See #254: Using None as function output leads to [] return value(   R   t   NoneR   t   AssertionError(   t   selfR   t   rval(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt	   test_none)   s
    	c         C` s)   t  g  g  ƒ } |  j | ƒ  g  k ƒ d  S(   N(   R   t
   assertTrue(   R    R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt
   test_empty2   s    c         C` sD   t  j d ƒ \ } } t | g | g ƒ } |  j t | d d ƒ d  S(   Nt   xsi   i   (   t   Tt   scalarsR   t   assertRaisest	   TypeError(   R    t   xt   sR   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_extra_inputs6   s    c         C` så   d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d „  } t  |  | t ƒ d	 „  } t  |  | t ƒ d  S(
   Nc          S` s)   t  j d ƒ \ }  } t g  |  g ƒ d  S(   NR%   (   R&   R'   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   =   s    c          S` s2   t  j d ƒ \ }  } t | g |  g d d ƒd  S(   NR%   t   on_unused_inputt   ignore(   R&   R'   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   B   s    c          S` s,   t  j d ƒ \ }  } t | g |  g ƒ d  S(   NR%   (   R&   R'   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   H   s    c          S` s/   t  j d ƒ \ }  } t | g |  d d ƒd  S(   NR%   R-   R.   (   R&   R'   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   M   s    c          S` s)   t  j d ƒ \ }  } t | g |  ƒ d  S(   NR%   (   R&   R'   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   S   s    c          S` s5   t  j d ƒ \ }  } t | g t |  ƒ d d ƒd  S(   NR%   R-   R.   (   R&   R'   R   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   X   s    c          S` s/   t  j d ƒ \ }  } t | g t |  ƒ ƒ d  S(   NR%   (   R&   R'   R   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   ^   s    c          S` s9   t  j d ƒ \ }  } t t |  d | |  ƒg |  ƒ d  S(   NR%   t   update(   R&   R'   R   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   c   s    c          S` s=   t  j d ƒ \ }  } t t |  d | | |  ƒg |  ƒ d  S(   NR%   R/   (   R&   R'   R   R   (   R*   R+   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   h   s    (   R   R
   R	   (   R    R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_missing_inputs;   s$    									c         C` ss   t  j d ƒ \ } } t | | g | | g ƒ } |  j | d d ƒ d g k ƒ |  j | d d ƒ d g k ƒ d  S(   NR%   i   i   i   (   R&   R'   R   R#   (   R    R*   R+   R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_input_anon_singletonm   s    c         C` sN   t  j d ƒ \ } } t | | g | | ƒ } |  j | d d ƒ d k ƒ d  S(   NR%   i   i   i   (   R&   R'   R   R#   (   R    R*   R+   R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_input_anon_unpackt   s    c         ` s  t  j d ƒ \ } } t | | g | | ƒ ‰  |  j ˆ  d d ƒ d k ƒ |  j ˆ  d d ƒ d k ƒ |  j ˆ  d d d d ƒ d k ƒ |  j ˆ  d d d d ƒ d k ƒ |  j ˆ  d d d ƒd k ƒ t |  ‡  f d †  t ƒ t |  ‡  f d	 †  t ƒ t |  ‡  f d
 †  t ƒ d  S(   NR%   i   i   g      à?g       @R+   R*   c           ` s   ˆ  d d d ƒS(   Ni   R*   g       @(    (    (   t   f(    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   <lambda>   s    c           ` s   ˆ  d d ƒ S(   NR*   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ‚   s    c           ` s   ˆ  d d ƒ S(   NR+   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ƒ   s    (   R&   R'   R   R#   R   R)   (   R    R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_naming_rule0y   s    ""c         ` sÇ   t  j ƒ  } t  j d ƒ \ } } t | | g | | ƒ ‰  |  j ˆ  d d ƒ d k ƒ |  j ˆ  d d ƒ d k ƒ |  j ˆ  d d d ƒd k ƒ t |  ‡  f d †  t ƒ t |  ‡  f d †  t ƒ d  S(	   NR%   i   i   g      à?g       @R+   c           ` s   ˆ  d d d d ƒ S(   Nt   qi   R+   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   Œ   s    c           ` s   ˆ  d d d d ƒ S(   Nt   ai   R+   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4      s    (   R&   t   scalarR'   R   R#   R   R)   (   R    R7   R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_naming_rule1…   s    c         ` sÙ   t  j ƒ  } t  j d ƒ \ } } t | | | g | | d d ƒ‰  |  j ˆ  d d d ƒ d k ƒ |  j ˆ  d d d ƒ d k ƒ |  j ˆ  d d d	 d ƒd k ƒ t |  ‡  f d
 †  t ƒ t |  ‡  f d †  t ƒ d  S(   NR%   R-   R.   i	   i   i   g      à?g       @R+   c           ` s   ˆ  d d d d d d ƒ S(   NR*   i	   R7   i   R+   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ™   s    c           ` s   ˆ  d d d ƒS(   Ng      @R*   i	   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   š   s    (   R&   R8   R'   R   R#   R   R)   (   R    R7   R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_naming_rule2   s    ""c         ` s  t  j ƒ  } t  j d ƒ \ } } t | t | d d ƒ| g | | | ƒ ‰  |  j ˆ  d d d ƒ d k ƒ |  j ˆ  d d d d ƒd k ƒ |  j ˆ  d d d ƒd	 k ƒ |  j ˆ  d
 d d d ƒ d	 k ƒ t |  ‡  f d †  t ƒ t |  ‡  f d †  t ƒ t |  ‡  f d †  t ƒ d  S(   NR%   t   valueg      ð?i	   i   i   g      #@R+   g     €"@R*   c           ` s   ˆ  d d d d d d ƒ S(   NR*   i	   R7   i   R+   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ¦   s    c           ` s   ˆ  ƒ  S(   N(    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   §   s    c           ` s   ˆ  d d ƒ S(   NR*   i	   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ¨   s    (   R&   R8   R'   R   R   R#   R   R)   (   R    R7   R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_naming_rule3œ   s    ,""c         ` sX  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒ| g | | | ƒ ‰  |  j ˆ  d d d ƒ d	 k ƒ |  j ˆ  d d d
 d ƒd	 k ƒ |  j ˆ  d d
 d ƒd k ƒ |  j ˆ  d d d d
 d ƒd	 k ƒ |  j ˆ  d d d d d
 d ƒ d	 k ƒ |  j ˆ  d d d
 d ƒ d k ƒ t |  ‡  f d †  t ƒ t |  ‡  f d †  t ƒ d  S(   NR%   R;   g      ð?t   nameR7   i	   i   i   g      #@R+   g     €"@R*   c           ` s   ˆ  ƒ  S(   N(    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ¶   s    c           ` s   ˆ  d d d ƒS(   Ng      @R*   i	   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ·   s    (   R&   R8   R'   R   R   R#   R   R)   (   R    R7   R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_naming_rule4ª   s    2"%("c         C` sV  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | ƒg | | | ƒ } |  j | | d k ƒ |  j | | d k ƒ |  j | d ƒ d k ƒ |  j | d d d	 ƒd
 k ƒ |  j | | d k ƒ |  j | | d
 k ƒ d | | <|  j | | d k ƒ |  j | d ƒ d k ƒ |  j | | d k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   g      @g       @g      "@g      @g      8@(   R&   R8   R'   R   R   R#   (   R    R7   R*   R+   R3   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_state_access¹   s    L
c         ` st   t  j d ƒ \ } } } t | | | g | | | ƒ ‰  |  j ˆ  d d d ƒ d k ƒ t |  ‡  f d †  t ƒ d  S(   Nt   xxxi   i   i   i   c           ` s   ˆ  d d d d ƒS(   Ni   i   R*   i   (    (    (   R3   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   Ò   s    (   R&   R'   R   R#   R   R)   (   R    R7   R*   R+   (    (   R3   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_same_namesÍ   s     c         ` sZ   t  j d ƒ \ ‰  ‰ ‰ t |  ‡  f d †  t ƒ ‡  ‡ ‡ f d †  } t |  | t ƒ d  S(   NR@   c           ` s   t  t ˆ  d g  ƒg g  ƒ S(   NR=   (   R   R   (    (   R7   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR4   ×   s    c       	   ` sl   t  t ˆ  d t d d g ƒ d d ƒt ˆ d d d d ƒt ˆ d t j ƒ  d d ƒg ˆ  ˆ ˆ ƒ }  |  S(	   NR=   t   adsfR;   g      ð?g       @g      @(    (    (   R   R   t   setR&   R8   (   R3   (   R7   R+   R*   (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   tÙ   s    $/(   R&   R'   R   R)   (   R    RD   (    (   R7   R+   R*   sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_weird_namesÔ   s    c         C` sÚ  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } t j | ƒ } |  j | j | j	 | j | j	 k ƒ |  j | j | j	 | j | j	 k ƒ |  j | j | j	 | j | j	 k ƒ |  j | j
 | | j
 | k	 ƒ |  j | j
 | | j
 | k ƒ |  j | j
 | | j
 | k j ƒ  ƒ |  j | d	 d
 ƒ | d	 ƒ k ƒ |  j | d	 d
 ƒ | d	 ƒ k ƒ | d
 d	 ƒ |  j | d
 d	 ƒ | d
 d	 ƒ k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   t   mutablei   i   (   R&   R8   R'   R   R   t   Truet   copyt   assertFalset	   containert   storageR;   t   anyR#   (   R    R7   R*   R+   R3   t   g(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt	   test_copyà   s     &'''!!'""c      
   C` sÊ  t  j d ƒ } t j d d ƒ } t j d d ƒ } t  j | | d | | d d ƒ } xid d g D][} t j | g | g d | d	 i | d | 6ƒ} | j d
 t ƒ } | j j	 } | j j	 }	 | j
 j }
 |
 j |
 j } | j ƒ  } g  |	 j ƒ  D]3 \ } } | | k s(t | t j j ƒ rû | ^ qû } x: | D]2 } |  j t g  | D] } | | k ^ qQƒ ƒ q;WxN t | j | j | j ƒ D]1 \ \ } } } } } |  j | j | j k ƒ qWqg Wd  S(   NR*   R;   i   i   gš™™™™™É?t   FAST_RUNt   FAST_COMPILEt   modet   updatest   share_memory(   R&   t   fscalart   theanot   sharedt   tanhR   RH   RG   R   t   storage_mapt   makert   fgrapht   inputst   outputst   valuest   itemsR   R   t   ConstantR#   RL   t   zipt   indicest   input_storaget   data(   R    R*   t   yt   zt   outRQ   t   orit   cpyt   storage_map_orit   storage_map_cpyt
   fgraph_cpyt   i_o_variablest   ori_storagest   keyt   valt   lRK   R+   t   inputt   _1t   _2t   heret   there(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_copy_share_memoryø   s(    '/-0"c         C` sî  t  j ƒ  } t j d t j j d ƒ j t j	 ƒ ƒ } t  j
 d ƒ } t j d d d d ƒ } t j d d d d ƒ } t j d d	 d d
 ƒ } t j d d d d ƒ } t j d d d d ƒ } i | | 6| | 6}	 i | d 6| d 6}
 | | | | } t } xêd d g D]Ü} t j | g | g d | d | | d f | | d f g d i | | | 6ƒ} | j d |	 ƒ } | d ƒ | d ƒ | d ƒ f | s| j ƒ  d k s®t ‚ | j ƒ  d k sÆt ‚ | j ƒ  d k sÞt ‚ | j ƒ  d k söt ‚ | j ƒ  d k szt ‚ ni | rz| j ƒ  d k s/t ‚ | j ƒ  d k sGt ‚ | j ƒ  d k s_t ‚ | j ƒ  d k szt ‚ n  |
 j ƒ  } xW | j j D]I } | j | k r“|
 | j j j d	 | j j | d	 k sÜt ‚ q“q“Wt } q
Wd  S(   NR;   i
   R*   i   R=   Rd   i   Re   i    t   mi   t   y_rpli   t   z_rplRO   RP   RQ   RR   t   givenst   swapi   i   i   (   R&   t   iscalarRU   RV   t   npt   randomt   randt   astypeR   t   floatXR8   t   FalseR   RH   t	   get_valueR   t   keysR   RX   R=   RJ   RK   RG   (   R    t   it   x_listR*   Rd   Re   Rw   Rx   Ry   R{   t   map_SVRf   t   second_timeRQ   Rg   Rh   t   namesRn   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_swap_SharedVariable  sF    * $c      	   C` sÙ  t  j d t j j d d ƒ j t j ƒ ƒ } t  j d t j j d d ƒ j t j ƒ ƒ } t  j d t j j d d ƒ j t j ƒ ƒ } t  j d t j j d d ƒ j t j ƒ ƒ } t j	 d ƒ } t j
 d ƒ } t j
 d ƒ } t j | ƒ | d } t  j | g | d i | | | 6| | | 6d	 i | d
 | 6ƒ}	 t  j | g | d i | | | 6| | | 6ƒ}
 |	 j d i | | 6| | 6d t ƒ } xA t |
 j j | j j ƒ D]$ \ } } | j | j k s­t ‚ q­Wd S(   s§   
        A special testcase for logistic_sgd.py in Deep Learning Tutorial
        This test assert that SharedVariable in different function have same storage
        R;   i
   i   t   indexR*   Rd   i   Rz   RR   gš™™™™™¹?R{   t   delete_updatesN(   RU   RV   R}   R~   R   R€   R   R   R&   R|   t   vectort   sumR   RH   RG   R`   RY   R[   R;   R   (   R    t   train_xt   test_xt   train_yt   test_yR…   R*   Rd   Rf   t   traint   test_deft   test_cpyt   in1t   in2(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt#   test_swap_SharedVariable_with_givenS  s     ----1	(c   	   
   C` sŸ  t  j d ƒ } t  j d ƒ } t j d d d d ƒ } t j d d d d ƒ } | | | } x¦ d	 d
 g D]˜ } t j | g | d | d i | d | 6ƒ} | j d t ƒ } | d ƒ d d k sÉ t ‚ | d ƒ d d k så t ‚ | d ƒ d d k si t ‚ qi Wx“ d	 d
 g D]… } t j | g | d | d i | d | 6ƒ} | j d t ƒ } t j | | g | d | d i | | | 6ƒ} | j d t ƒ } qWd  S(   Nt   wR*   R;   i   R=   Rd   i   Re   RO   RP   RQ   RR   RŒ   i    i   (	   R&   R|   RT   RU   RV   R   RH   RG   R   (	   R    R™   R*   Rd   Re   Rf   RQ   Rg   Rh   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_copy_delete_updatesn  s     , ,/c         C` sF  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } t | t | d d d d ƒt | d | j | d | | | d t ƒg | | | ƒ } | d	 d
 ƒ |  j | | d
 k ƒ |  j | | d
 k ƒ | d	 d
 ƒ |  j | | d k ƒ |  j | | d k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   RF   i   i   i    (   R&   R8   R'   R   R   RG   RJ   R#   (   R    R7   R*   R+   R3   RM   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_shared_state0Š  s    &-c         C` s?  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } t | t | d d d d ƒt | d | j | ƒg | | | ƒ } | d	 d
 ƒ |  j | | d
 k ƒ |  j | | d
 k ƒ | d	 d
 ƒ | d	 d
 ƒ |  j | | d k ƒ |  j | | d k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   RF   i   i   i   (   R&   R8   R'   R   R   RG   RJ   R#   (   R    R7   R*   R+   R3   RM   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_shared_state1œ  s    7*c         C` sm  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } t | t | d d d d ƒt | d | j | ƒg | | | ƒ } | d	 d
 ƒ |  j | | d
 k ƒ |  j | | d
 k ƒ | d	 d
 ƒ |  j | | d k ƒ |  j | | d k ƒ | d	 d
 ƒ |  j | | d k ƒ |  j | | d k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   RF   i   i   i   (   R&   R8   R'   R   R   R‚   RJ   R#   (   R    R7   R*   R+   R3   RM   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_shared_state2­  s    8Ec      
   C` s  t  j d ƒ \ } } t | t | d | | d d ƒg g  ƒ } t | t | d | | d | j | d t ƒg g  ƒ } |  j | | | | k ƒ d | | <|  j | | d k ƒ | d ƒ |  j | | d k ƒ | d d ƒ |  j | | d	 k ƒ |  j | | d	 k ƒ d  S(
   NR%   R/   R;   g      $@t   impliciti   i   i    iÿÿÿÿ(   R&   R'   R   R   RJ   R‚   R#   (   R    R*   R+   t   inct   dec(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_shared_state_not_implicit¿  s    +&

c         C` sJ  t  j g  t  j j d g ƒ ƒ } | ƒ  } | d k j ƒ  sB t ‚ d | d <| ƒ  } | | k	 sg t ‚ | d k j ƒ  s t ‚ t  j g  t t  j j d g ƒ d t ƒƒ } | ƒ  } | d k j ƒ  sÍ t ‚ d | d <| ƒ  } t t  j	 j
 j ƒ  t  j	 j ƒ r| d k j ƒ  sFt ‚ n* | | k s.t ‚ | d k j ƒ  sFt ‚ d  S(   Ni   i   i    t   borrow(   RU   R   R   t   constantt   allR   R   RG   R   t   compileRQ   t   get_default_modet	   DebugMode(   R    R3   Rf   t   out2(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_constant_outputÑ  s"    !	
	-	
	c         C` s'  t  j ƒ  } t j j d d ƒ } t j t | d t ƒg t	 | d d t
 ƒƒ } t j | | ƒ | d k ƒ sw t ‚ t j | | | ƒ ƒ s– t ‚ t j t | d t ƒg t	 | d d d … f d t
 ƒƒ } t j | | ƒ | d d d … f k ƒ st ‚ t j | | | ƒ ƒ s#t ‚ d S(   s@  
        Tests that the contract for io.In is respected. When borrow=False, it should be
        impossible for outputs to be aliased to the input variables provided by the user,
        either through a view-map or a destroy map. New tests should be added in the future
        when borrow=True is implemented.
        i   R¢   i   i    N(   R&   t   dmatrixR}   R~   R   RU   R   R   R‚   R   RG   R¤   R   t   may_share_memory(   R    R7   t   avalR3   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_borrow_inputí  s    1%=1c         C` s”  t  j ƒ  } t | g t | d t ƒƒ } t j d ƒ } | | | ƒ k	 sQ t ‚ t | g t | d d t ƒƒ } t j d	 ƒ } | | ƒ } t j | d k ƒ s© t ‚ | | d ƒ t j | d k ƒ sÒ t ‚ t | g t | d d t	 ƒd t
 j d d ƒ ƒ} t j d
 ƒ } | | ƒ } t j | d k ƒ s<t ‚ | | d ƒ t
 j j rut j | d k ƒ st ‚ n t j | d k ƒ st ‚ d  S(   NR¢   i   i   gš™™™™™¹?RQ   s	   c|py_nogct   fast_run(   i   i   (   i   i   (   i   i   (   R&   Rª   R   R   R‚   R}   t   onesR   R¤   RG   RU   t   ModeR   t   cxx(   R    R7   R3   t   ot   four(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_borrow_output  s$    "4c         C` s_   t  j d ƒ } t  j d ƒ } |  j t t | | g | d ƒ t | | g | d d d ƒd  S(   NR7   t   vi   R-   R.   (   R&   R8   R   R(   R	   R   (   R    R7   Rµ   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_disconnected_input  s     c         C` sb   t  j d ƒ } | j  } d | _ |  j t t | | g | d ƒ t | | g | d d d ƒd  S(   NRw   s   m.Ti   R-   R.   (   R&   t   matrixR=   R(   R	   R   (   R    Rw   t   mt(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_masked_input   s
    		 c      	   C` sG   t  j d ƒ } | d } |  j t t | g | d i | d | 6ƒd S(   sR   
        Ensure error is raised when trying to replace an input variable.
        R*   i   Rz   i   N(   R&   R8   R(   t   RuntimeErrorR   (   R    R*   Rd   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_givens_input_var'  s    
c         C` s  t  j d ƒ } t | g | d ƒ } t | j _ | d g ƒ g  } xE t | j j ƒ D]1 \ } } t | t	 j
 j ƒ sW | j | ƒ qW qW Wt g  | D] } | d ^ q– ƒ sµ t ‚ | j ƒ  xN t | j j ƒ D]: \ } } t | t	 j
 j ƒ sÒ | d d k st ‚ qÒ qÒ Wd S(   s.   
        Make test on free() function
        R*   i   i    N(   R&   R   R   R‚   R   t   allow_gcR   RX   R   RU   R   R_   t   appendRL   R   t   freeR   (   R    R*   t   funct
   check_listRn   Ro   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt	   test_free/  s    )
c         C` s±   t  j d d ƒ \ } } | | } t j t j | d d ƒt j | d d d d ƒg | ƒ } | d d ƒ } y | d d ƒ Wn, t k
 r¬ | d d ƒ | k s­ t ‚ n Xd	 S(
   sn   
        Check that default values are restored
        when an exception occurs in interactive mode.
        R7   t   bR=   t   firstR;   i   t   secondi   N(   R&   t   dscalarsRU   R   R   R)   R   (   R    R7   RÂ   t   cR¿   R*   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_default_valuesD  s    
<(!   t   __name__t
   __module__R"   R$   R,   R0   R1   R2   R5   R9   R:   R<   R>   R?   RA   RE   RN   Rv   RŠ   R˜   Rš   R›   Rœ   R   R¡   R©   R­   R´   R¶   R¹   R»   RÁ   RÇ   (    (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR   (   s>   					2				
								 	;													t   T_picklefunctionc           B` sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` sö  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } y t j | ƒ } Wn- t k
 rµ } | d	 j	 d
 ƒ r¯ d  S‚  n X|  j
 | j d	 j | j d	 j k ƒ |  j
 | j d j | j d j k ƒ |  j
 | j d j | j d j k ƒ |  j
 | | j k ƒ |  j
 | | j k ƒ |  j t | j ƒ t | j ƒ k ƒ |  j t g  t | j | j ƒ D]B \ \ } } }	 \ }
 } } | |
 k oÚ| | k oÚ|	 | k ^ q›ƒ ƒ |  j
 | j d | j d k ƒ |  j
 | j d | j d k ƒ |  j
 | j d | j d k j ƒ  ƒ |  j | d d ƒ | d ƒ k ƒ |  j | d d ƒ | d ƒ k ƒ | d d ƒ |  j
 | d d ƒ | d d ƒ k ƒ | d d ƒ |  j | d ƒ | d ƒ k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   RF   i    s   DebugMode is not picklablei   i   i   (   R&   R8   R'   R   R   RG   RH   t   deepcopyt   NotImplementedErrort
   startswithRI   RJ   RK   R;   R#   t   lent   defaultsR¤   R`   RL   (   R    R7   R*   R+   R3   RM   R   t   f_reqt   f_feedt   f_valt   g_reqt   g_feedt   g_val(    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_deepcopyU  s8    7'''%\!!'""%c   
      C` sR  t  j d ƒ \ } } t t | d d ƒg | ƒ } t | t | d | j | d t ƒg | | ƒ } yw i  } t j | ƒ } | j i | t	 | ƒ 6ƒ t j | d | ƒ} | j i | t	 | ƒ 6ƒ t j | d | ƒ} Wn- t
 k
 r}	 |	 d j d ƒ rd  S‚  n Xd | | <d	 | | <|  j | | d k ƒ |  j | | d	 k ƒ d  S(
   Nt   axR;   g        Rž   t   memoi    s   DebugMode is not picklablei   i   (   R&   R'   R   R   RJ   RG   RH   RË   R/   t   idRÌ   RÍ   R#   (
   R    R7   R*   t   hR3   RØ   t   act   hct   fcR   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_deepcopy_shared_container  s$    2

c         C` sg  t  j ƒ  } t  j d ƒ \ } } t | t | d d d d ƒt | d d d | | | d t ƒg | | | ƒ } y@ t j t j | d	 d
 ƒƒ } t j t j | d	 d ƒƒ } Wn- t	 k
 râ } | d
 j
 d ƒ rÜ d  S‚  n X|  j | j d
 j | j d
 j k ƒ |  j | j d j | j d j k ƒ |  j | j d j | j d j k ƒ |  j | | j k ƒ |  j | | j k ƒ |  j | j d | j d k ƒ |  j | j d | j d k ƒ |  j | j d | j d k j ƒ  ƒ |  j | d d ƒ | d ƒ k ƒ |  j | d d ƒ | d ƒ k ƒ | d d ƒ |  j | d d ƒ | d d ƒ k ƒ d  S(   NR%   R;   g      ð?R=   R7   g        R/   RF   t   protocoli    iÿÿÿÿs   DebugMode is not picklablei   i   (   R&   R8   R'   R   R   RG   t   picklet   loadst   dumpsRÌ   RÍ   RI   RJ   RK   R;   RL   R#   (   R    R7   R*   R+   R3   RM   R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_pickle—  s.    7"'''!!'""c         C` sß  t  j ƒ  } t  j d ƒ } t  j d ƒ } t  j d ƒ } t  j d ƒ } t | | | | | g | j  j  t j | | j  j  j  ƒ | j  | | | ƒ } t j } t j } t j	 }	 zy yC t
 j | d d ƒ}
 d t _ d t _	 d t _ t
 j |
 ƒ } Wn/ t k
 r*} | d j d	 ƒ r+d
 } q+n XWd  | t _ | t _ |	 t _	 X| d
 k r[d  S| j | j k	 sst ‚ | j j | j j k	 s‘t ‚ | j j j ƒ  } | j j j ƒ  } t | ƒ t | ƒ k sÓt ‚ xt | | ƒ D]ô \ } } | j | j k st ‚ t | j ƒ t | j ƒ k s+t ‚ t | j ƒ t | j ƒ k sOt ‚ g  | j D] } | j ^ qYg  | j D] } | j ^ quk s“t ‚ g  | j D] } | j ^ qg  | j D] } | j ^ q¹k sãt ‚ qãWd  S(   NR*   R+   Rß   iÿÿÿÿR°   t   pyR   i    s   DebugMode is not picklt   ok(   R&   t   dvectorRª   R   R   t   dotR   RQ   t	   optimizert   linkerRà   Râ   Rá   RÌ   RÍ   RY   R   RZ   t   toposortRÎ   R`   t   opR[   R\   t   type(   R    R7   R*   R+   t   xmt   smR3   t   old_default_modet   old_default_optt   old_default_linkt   str_fRM   R   t   tft   tgt   nft   ngR…   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_optimizations_preserved»  sF    P								
$$Dc         C` sŠ  t  j ƒ  } t  j d ƒ \ } } t  j d ƒ } | | | g } | j | | | ƒ t | t | d d d d ƒt | d d d | | | d	 t ƒg | | | ƒ } | j | ƒ t | t | d d d d ƒt | d | j | d | | | d	 t ƒg | | | ƒ } | j | ƒ t	 | j | j
 t ƒ s8t ‚ | j | j
 | j | j
 k s^t ‚ t j d
 d d g d t j ƒ} t | t | d | ƒg | | ƒ }	 | j |	 ƒ y( t j | d d ƒ}
 t j |
 ƒ } Wn- t k
 r} | d j d ƒ rd  S‚  n X| } | } xn t d ƒ D]` } | | | | k sBt ‚ | | j | | j k sbt ‚ | | j | | j k	 s"t ‚ q"W| d j j d | k s¦t ‚ | d j j d | k	 sÆt ‚ | d j j d j | j k sìt ‚ x1 t d d ƒ D]  } | | | | k süt ‚ qüW| d | d | d | d k	 sJt ‚ | d | d | d | d k stt ‚ | d d ƒ | d d ƒ k sšt ‚ | d j | d j
 | d j | d j
 k sÐt ‚ | d j | d j
 | d j | d j
 k st ‚ | d d ƒ | d d ƒ k s,t ‚ | d j | d d k sMt ‚ t j | d | d
 t j d
 d d g ƒ k ƒ s†t ‚ d  S(   NR%   Rµ   R;   g      ð?R=   R7   g        R/   RF   i   i   g      @t   dtypeRß   iÿÿÿÿi    s   DebugMode is not picklablei   i   i   i   i   g      @(   R&   R8   R'   R   R½   R   R   RG   RJ   R   RK   t   listR   R}   t   asarrayR   R   Rà   Râ   Rá   RÌ   RÍ   t   rangeRì   t   ownerR[   R;   R¤   (   R    R7   R*   R+   Rµ   t   list_of_thingst   f1t   f2t   v_valuet   f3t   saved_formatt   new_list_of_thingsR   t   olt   nlR…   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_multiple_functionsæ  sX    &-&!% $  &**&66&!c         ` s>  g  ‰  ‡  f d †  } ‡  f d †  } t  j j d d ƒ } t j j ƒ  } t j | ƒ } t j | g t j j | | ƒ ƒ } d d l	 m
 } | ƒ  } t j | d ƒ }	 | |	 _ y |	 j | ƒ Wn/ t k
 rñ }
 t |
 ƒ j d ƒ rë d  S‚  n X| | j ƒ  ƒ } | j ƒ  t j | ƒ }	 | |	 _ |	 j ƒ  | j ƒ  d  S(	   Nc         ` s5   t  |  t j ƒ r- ˆ  j |  ƒ t ˆ  ƒ d Sd  Sd  S(   Ni   (   R   R}   t   ndarrayR½   RÎ   R   (   t   obj(   t   saves(    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt	   pers_save4  s    c         ` s   ˆ  |  S(   N(    (   RÙ   (   R	  (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt	   pers_load;  s    i   i   i    (   t   BytesIOi   s   DebugMode is not picklable(   R}   R~   R   RU   R   R·   RV   R   Rç   t   theano.compatR  Rà   t   Picklert   persistent_idt   dumpRÌ   R   RÍ   t   getvaluet   closet	   Unpicklert   persistent_loadt   load(   R    R
  R  RÂ   R*   Rd   R3   R  t   fpt   pR   t   fp2(    (   R	  sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_broken_pickle_with_shared1  s.    $		
	
c         C` s  t  ƒ  } | j j | j j | j j | j j k s; t ‚ y t j | ƒ } Wn- t	 k
 r} } | d j
 d ƒ rw d  S‚  n X| j j | j j | j j | j j k s° t ‚ | j | j | j | j k sÖ t ‚ | j d ƒ | j | j | j | j k s	t ‚ d  S(   Ni    s   DebugMode is not picklablei   (   t   SomethingToPickleRÿ   RJ   R+   RK   Rþ   R   RH   RË   RÌ   RÍ   (   R    t   blaht   blah2R   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt    test_pickle_class_with_functionsW  s    	22&(	   RÈ   RÉ   RÖ   RÞ   Rã   R÷   R  R  R  (    (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyRÊ   S  s   	*		$	+	K	&R  c           B` s   e  Z d  „  Z RS(   c         C` s  t  j ƒ  } t  j d ƒ \ } } t  j d ƒ } | |  _ | |  _ | |  _ | | | |  _ t | t	 | d d d d ƒt	 | d d d | | | d	 t
 ƒg | | | ƒ |  _ t | t	 | d d d d ƒt	 | d |  j j | d | | | d	 t
 ƒg | | | ƒ |  _ d  S(
   NR%   Rµ   R;   g      ð?R=   R7   g        R/   RF   (   R&   R8   R'   R   R+   R*   Rµ   R   R   R   RG   Rþ   RJ   Rÿ   (   R    R7   R*   R+   Rµ   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   __init__m  s    			&'	(   RÈ   RÉ   R  (    (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyR  l  s   c          C` sX   t  j ƒ  }  |  d } t t j |  ƒ g | d i  ƒt t j |  ƒ g | d i  ƒd S(   s3   
    Regression test for bug fixed in 8625e03.
    i   Rz   RR   N(   R&   R8   R   RU   R   (   R*   Rd   (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   test_empty_givens_updates‚  s    
t   __main__(*   t
   __future__R    R   R   RH   t   six.moves.cPicklet   movest   cPickleRà   t   numpyR}   t   unittestRU   R   R   t   sixR   t   theano.compile.ioR   R   t   theano.compileR   R	   t
   theano.gofR
   R  R   t   theano.tests.unittest_toolsR   R   R&   RG   R   R   t   TestCaseR   RÊ   t   objectR  R  RÈ   t   main(    (    (    sI   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_function_module.pyt   <module>   s4   	ÿ ÿ -ÿ 	