ó
àÆ÷Xc           @` sB  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
 m Z 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 d  d	 l m Z d
 „  Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e d k r>d e	 j _ e ƒ  j ƒ  n  d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   SkipTest(   t   dmatrixt   iscalart   lscalart	   dmatrices(   t   tensor(   t   In(   t   pfunc(   t   shared(   t   configc         C` s   |  j  j d S(   s)   Return the raw value of a shared variablei    (   t	   containert   storage(   t   s(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   data_of   s    t
   Test_pfuncc           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 RS(   c         C` s¡  t  ƒ  } t d ƒ } t | g | | ƒ } t t | d d ƒg | | d i | d | 6ƒ} |  j | j ƒ  d k ƒ |  j | d ƒ d k ƒ |  j | d ƒ d k ƒ |  j | j ƒ  d k ƒ |  j | d ƒ d k ƒ | j d	 ƒ |  j | d ƒ d k ƒ t j  ƒ  } t d
 ƒ } t | g | | ƒ } t | g | | ƒ } |  j | d ƒ d k ƒ | j d ƒ |  j | d ƒ d k ƒ |  j | d ƒ d k ƒ d S(   s4   Ensure the code given in pfunc.txt works as expectedi   t   valuei,   t   updatesi   i   i   i   i    i   i   i   i   i    N(   R   R   R
   R	   t
   assertTruet	   get_valuet	   set_valueR   (   t   selft   at   bt   f1t   f2(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_doc   s&    	3c   
      C` s¡  t  t j j d d ƒ d ƒ } | j d t ƒ } t ƒ  } | | } | | } t | g | g ƒ } t | g | g ƒ } t j j d d ƒ } t j | | ƒ | | k ƒ s± t	 ‚ t j | | ƒ | | k ƒ sÖ t	 ‚ t | g | d | | d f g ƒ}	 t j |	 | ƒ | | k ƒ s t	 ‚ t j | | ƒ | | d k ƒ sIt	 ‚ | j
 | j d t ƒ d d t ƒt j | | ƒ | | j d t ƒ k ƒ st	 ‚ d  S(   Ni   t   wt   borrowR   i   i
   (   R   t   npt   randomt   randR   t   FalseR   R
   t   allt   AssertionErrorR   t   True(
   R   R   t   wvalt   xt   out1t   out2R   R   t   xvalt   f3(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_shared2   s    	

%%%%)#c         C` s›   t  j j d d ƒ } t | j ƒ  d ƒ } y0 t | g t j j | | ƒ ƒ t	 sY t
 ‚ Wn: t k
 r– } d } t | ƒ j | ƒ d k  r— ‚  q— n Xd S(   s=   Test that shared variables cannot be used as function inputs.i   R   s2   Cannot use a shared variable (w) as explicit inputi    N(   R   R    R!   R   t   copyR
   t   theanoR   t   sumR"   R$   t	   TypeErrort   strt   find(   R   t   w_initR   t   et   msg(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_shared_as_inputL   s     c         C` sÊ   t  j j d ƒ } | j d ƒ } t | j ƒ  d ƒ } t j j | | ƒ } t	 g  | ƒ } | ƒ  t  j | | ƒ k s} t
 ‚ | j | j d t ƒ d d t ƒ| ƒ  t  j | d d ƒ k sÆ t
 ‚ d  S(   Ni#  i   R   R   g      ð?i   i   (   R   R    t   RandomStateR!   R   R-   R.   R   R/   R
   R$   R   R   R%   (   R   t   rngR3   R   t   regt   f(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_containerX   s    "#c         C` so   t  d d ƒ } t g  | ƒ } | ƒ  d k s3 t ‚ | j | j d t ƒ d d t ƒ| ƒ  d k sk t ‚ d  S(   Ng        R'   i    R   i   (   R   R
   R$   R   R   R%   (   R   R'   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_scalar_containerg   s
    #c         C` sà   t  j ƒ  } t d ƒ } | | } t t | d t ƒg | g ƒ } | t j j d ƒ ƒ | t j	 d d d d g d d	 ƒƒ t t | d t
 ƒg | g ƒ } y) | t j	 d d d d g d d	 ƒƒ Wn t k
 rÛ n Xd  S(
   Ni   t   stricti   i   i   i   i   t   dtypet   int32(   R   t   dvectorR   R
   R	   R"   R   R    R!   t   arrayR%   R0   (   R   R   R   t   outR:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_param_strictp   s    
!%!)c         C` s%  t  j ƒ  } | d } t t | d t ƒg | g d d ƒ} t j j d ƒ } | j ƒ  } t j	 | | ƒ | d k ƒ s€ t
 ‚ t j	 | | k ƒ sœ t
 ‚ t t | d t ƒg | g d d ƒ} t j j d ƒ } | j ƒ  } t j	 | | ƒ | d k ƒ st
 ‚ t j	 | | k ƒ s!t
 ‚ d  S(   Ni   t   mutablet   modet   FAST_RUNi
   (   R   R@   R
   R	   R%   R   R    R!   R-   R#   R$   R"   (   R   R   t   a_outt   fipt   avalt   aval2R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_param_mutableƒ   s    
'%'%c         C` se  t  j d ƒ } t | ƒ } | d } | j d t ƒ | k	 sC t ‚ t | ƒ } t g  | g d d ƒ} | ƒ  t  j d ƒ d k j ƒ  s t ‚ t  j | j d t ƒ t  j d ƒ k ƒ s¿ t ‚ t g  | g d | | f g d d ƒ} | ƒ  t  j d ƒ d k j ƒ  st ‚ | j d t ƒ t  j d ƒ d k j ƒ  s?t ‚ | t  j d ƒ d k j ƒ  sdt ‚ t  j d ƒ } | j	 | d t ƒt | ƒ } t g  | g d | | d f g d d ƒ} | ƒ  t  j d ƒ d k j ƒ  såt ‚ | j d t ƒ t  j d ƒ d d k j ƒ  st ‚ | t  j d ƒ k j ƒ  s<t ‚ | | j d t ƒ k j ƒ  sat ‚ d  S(   Ni   i   R   RE   RF   R   i   (
   R   t   arangeR   R   R%   R$   R   R
   R#   R   (   R   t   bvalR   t   b_outR:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_shared_mutable•   s(    
(0'(1%+(5"c         C` sG  t  j d ƒ } t  j d ƒ } t  j d ƒ } t t | d t ƒt | d t ƒt | d d  ƒg | | | ƒ } t	 j
 | d g d g d ƒ d k ƒ sž t ‚ |  j t | d g t	 j d g d	 d
 ƒd ƒ t	 j
 | d g t	 j d d	 d ƒd ƒ d k ƒ st ‚ |  j t | d g d g d ƒ |  j t | d g d g d ƒ d  S(   NR   R   t   ct   allow_downcasti   i   i   i
   R>   t   int16i   i   t   int8i8  i&  i   (   R   t   wvectort   bvectort   bscalarR
   R	   R%   R"   t   NoneR   R#   R$   t   assertRaisesR0   RA   t   ones(   R   R   R   RP   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_param_allow_downcast_int¸   s    -"9c         C` s(  t  j d ƒ } t  j d ƒ } t  j d ƒ } t t | d t ƒt | d t ƒt | d d  ƒg | | | ƒ } t j | d d d ƒ d k ƒ s˜ t	 ‚ t j
 | d d d ƒ d ƒ s¼ t	 ‚ |  j t | d d d ƒ t j d k rt j
 | d d d ƒ d ƒ s$t	 ‚ n |  j t | d d d ƒ d  S(   NR   R   RP   RQ   i    gš™™™™™¹?t   float32(   R   t   fscalarR
   R	   R%   R"   RW   R   R#   R$   t   allcloseRX   R0   R   t   floatX(   R   R   R   RP   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt    test_param_allow_downcast_floatXÔ   s    '$'c         C` s  t  j d ƒ } t  j d ƒ } t  j d ƒ } t t | d t ƒt | d t ƒt | d d  ƒg | | | ƒ } d g } t j | | | | ƒ d k ƒ s¡ t	 ‚ t j
 | d g | | ƒ d ƒ sÈ t	 ‚ |  j t | | d g | ƒ |  j t | | | d g ƒ d  S(   NR   R   RP   RQ   i    gš™™™™™¹?(   R   t   fvectorR
   R	   R%   R"   RW   R   R#   R$   R]   RX   R0   (   R   R   R   RP   R:   t   z(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt'   test_param_allow_downcast_vector_floatXí   s    	''c         C` sý  t  j d ƒ } t  j d ƒ } t  j d ƒ } t | | | g | | | d t ƒ} | d g d g d ƒ d k sw t ‚ | d	 g d
 g d ƒ d k s› t ‚ | d	 g d g d ƒ d k s¿ t ‚ t | | | g | | | d t ƒ} t j	 | d	 g d g d ƒ d k ƒ st ‚ |  j
 t | d	 g t j d g d d ƒd ƒ |  j
 t | d	 g d
 g d ƒ t | | | g | | | ƒ } t j	 | d	 g d g d ƒ d k ƒ s¬t ‚ |  j
 t | d	 g t j d g d d ƒd ƒ |  j
 t | d	 g d
 g d ƒ d  S(   NR   R   RP   t   allow_input_downcasti   i   i   i    i   i8  i;   i&  i*   i   i	   R>   RR   i   (   R   RT   RU   RV   R
   R%   R$   R"   R   R#   RX   R0   RA   (   R   R   R   RP   R:   t   gt   h(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_allow_input_downcast_int  s"    &$$$&-" -"c         C` sÖ  t  j d ƒ } t  j d ƒ } t | | g | | d t ƒ} t | | g | | d t ƒ} t | | g | | d d  ƒ} t j | d d g ƒ d k ƒ s¢ t	 ‚ t j | d d g ƒ d k ƒ sÉ t	 ‚ t j | d d g ƒ d k ƒ sð t	 ‚ t j
 | d d g ƒ d ƒ st	 ‚ |  j t | d d g ƒ |  j t | d d g ƒ t j
 | d d g ƒ d ƒ sjt	 ‚ |  j t | d d g ƒ t j d k r¹t j
 | d d g ƒ d ƒ sÒt	 ‚ n |  j t | d d g ƒ d  S(   NR   R   Rc   i    gš™™™™™¹?R[   (   R   R\   R`   R
   R%   R"   RW   R   R#   R$   R]   RX   R0   R   R^   (   R   R   R   R:   Rd   Re   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_allow_downcast_floatX$  s     '''$$'c         C` sò   t  d ƒ } t g  g  d i d | 6ƒ} | ƒ  |  j | j ƒ  d k ƒ | j d ƒ t g  g  d i | d | 6ƒ} | ƒ  |  j | j ƒ  d k ƒ | j d ƒ t  d ƒ } t g  g  d i | | | 6ƒ} | ƒ  |  j | j ƒ  d k ƒ d S(   s,   Test update mechanism in different settings.i    R   i   i   iÿÿÿÿi   N(   R   R
   R   R   R   (   R   R'   t   assignt   inct   yt   inc_by_y(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_update?  s      c         C` su   t  j j d d ƒ j d ƒ } t d d d | ƒ } |  j t t j d g  d g  d i | j	 ƒ  j
 d	 d	 ƒ | 6ƒd  S(
   Ni
   R[   t   namet   outputR   t   inputst   outputsR   R'   (   R   R    R!   t   astypeR   RX   R0   R.   t   functionR/   t
   dimshuffle(   R   t   datat
   output_var(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_update_err_broadcastU  s    c      
   C` st   t  d d ƒ \ } } t t j d ƒ ƒ } |  j t t j | | g | g d | | | | f | | | f g ƒd  S(   NR'   Rj   i   i   R   (   i   i   (   R   R   R   RY   RX   t
   ValueErrorR.   Rr   (   R   R'   Rj   Ra   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_duplicate_updates_  s    !c      	   C` su  t  d ƒ } t g  | d i d | 6ƒ} | ƒ  d k s= t ‚ | j d t ƒ d k s[ t ‚ t j ƒ  } t | g | | d i d | 6ƒ} t j | d d d g ƒ d d d g k ƒ s½ t ‚ | j ƒ  d k sÕ t ‚ t j ƒ  } | | } t | g | d d i t	 j
 d d d g d	 d
 ƒ| 6ƒ} t j | d d d g ƒ d d d g k ƒ sYt ‚ | j ƒ  d k sqt ‚ d  S(   Ni    t   givensi   R   i   i   i   i   R>   R?   i   (   R   R
   R$   R   R%   R   t   ivectorR   R#   R.   t   _asarray(   R   R'   Rh   Rj   R:   Ra   RP   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_givense  s    #3
(3c         C` s
  t  t j d d d g ƒ ƒ } t  t j d d d g ƒ ƒ } t  t j d d d g ƒ ƒ } t g  g  d i | d | 6| d | | 6| d | | | 6ƒ} | ƒ  t j | j ƒ  d k ƒ sÄ t ‚ t j | j ƒ  d k ƒ så t ‚ t j | j ƒ  d k ƒ st ‚ d  S(   Ni   i   R   i   i   i   i@  (   R   R   t   asarrayR
   R#   R   R$   (   R   R'   Rj   Ra   t   up(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_clone0w  s    !!c         C` s¤   t  d ƒ } | d | _ t g  | g ƒ } | ƒ  | j ƒ  d k sJ t ‚ | ` | ƒ  | j ƒ  d k so t ‚ t g  | g ƒ } | ƒ  | j ƒ  d k s  t ‚ d  S(   Ni    i   i   (   R   t   default_updateR
   R   R$   (   R   R'   R:   Rd   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_updates…  s    c         C` s¤  t  d ƒ } t  d ƒ } | d | _ t g  | g d t ƒ} | ƒ  | j ƒ  d k s\ t ‚ t g  | g d | g ƒ} | ƒ  | j ƒ  d k s– t ‚ t g  | g d | | g ƒ} | ƒ  | j ƒ  d k sÓ t ‚ t g  | g d | g ƒ} | ƒ  | j ƒ  d k st ‚ t g  | g d g  ƒ} | ƒ  | j ƒ  d k sDt ‚ t g  | g d t ƒ} | ƒ  | j ƒ  d k s{t ‚ |  j t t g  | g d | ƒ|  j t t g  | g d | ƒ|  j t t g  | g d d ƒt g  | g d | | d f g d t ƒ} | ƒ  | j ƒ  d	 k s"t ‚ t g  | g d | | d f g d | g ƒ}	 |	 ƒ  | j ƒ  d k sot ‚ t g  | g d | | d f g d | | g ƒ}
 |
 ƒ  | j ƒ  d
 k s¿t ‚ t g  | g d | | d f g d | g ƒ} | ƒ  | j ƒ  d k st ‚ t g  | g d | | d f g d g  ƒ} | ƒ  | j ƒ  d k sVt ‚ t g  | g d | | d f g d t ƒ} | ƒ  | j ƒ  d k s t ‚ d  S(   Ni    i   i   t   no_default_updatesi   i   t   canardR   i   i   (	   R   R€   R
   R%   R   R$   R"   RX   R0   (   R   R'   Rj   R   R   R+   t   f4t   f5t   g1t   g2t   g3t   g4t   g5(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_default_updates•  sV    +.1.++c         C` s  t  d ƒ } t  d ƒ } t d ƒ } | | } | | | _ t | g | ƒ } | d ƒ | j ƒ  d k so t ‚ t | g | d t ƒ} | d ƒ d k sŸ t ‚ | j ƒ  d k s· t ‚ t | g | d | g ƒ} | d ƒ d k sê t ‚ | j ƒ  d k st ‚ d  S(   Ni    i   R   i   R‚   i   i	   (   R   R   R€   R
   R   R$   R%   (   R   R'   Rj   R   Ra   R   R   R+   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt    test_default_updates_expressionsÑ  s    

c         C` s®  t  d ƒ } t  d ƒ } | d | _ | d | _ t g  | | g ƒ } | ƒ  | j ƒ  d k sf t ‚ | j ƒ  d k s~ t ‚ t g  | | g d | | d f g d | g ƒ} | ƒ  | j ƒ  d k sÎ t ‚ | j ƒ  d k sæ t ‚ t g  | | g d | | d f g d t ƒ} | ƒ  | j ƒ  d k s3t ‚ | j ƒ  d k sKt ‚ t g  | | g d | | d f g ƒ} | ƒ  | j ƒ  d	 k s’t ‚ | j ƒ  d k sªt ‚ d  S(
   Ni    i   iÿÿÿÿi   R   R‚   iýÿÿÿiûÿÿÿiúÿÿÿ(   R   R€   R
   R   R$   R%   (   R   R'   Rj   R   R   R+   R„   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_updates_multipleå  s(    1.(c   	      C` sN  t  d ƒ } t  d ƒ } t  d ƒ } | | | _ | | _ | d | _ t g  | g ƒ } | ƒ  | j ƒ  d k sx t ‚ | j ƒ  d k s t ‚ | j ƒ  d k s¨ t ‚ t g  | | g ƒ } | ƒ  | j ƒ  d k sÜ t ‚ | j ƒ  d k sô t ‚ | j ƒ  d k st ‚ t g  | g ƒ } | ƒ  | j ƒ  d k s=t ‚ | j ƒ  d k sUt ‚ | j ƒ  d k smt ‚ t g  | | g d | g ƒ} | ƒ  | j ƒ  d k sªt ‚ | j ƒ  d k sÂt ‚ | j ƒ  d k sÚt ‚ t g  | | | g d | g ƒ} | ƒ  | j ƒ  d	 k st ‚ | j ƒ  d k s2t ‚ | j ƒ  d k sJt ‚ d  S(
   Ni   i   iÿÿÿÿiþÿÿÿiýÿÿÿiüÿÿÿR‚   iûÿÿÿi   (   R   R€   R
   R   R$   (	   R   R'   Rj   Ra   R   R   R+   R„   R…   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_updates_chained   s>    	!c   	      C` s  t  d ƒ } t  d ƒ } t j j ƒ  d k r< t d ƒ } n t d ƒ } | | _ | | | _ t g  | d t ƒ} | ƒ  | j	 ƒ  d k s’ t
 ‚ | j	 ƒ  d k sª t
 ‚ t g  | d | g ƒ} | ƒ  | j	 ƒ  d k sá t
 ‚ | j	 ƒ  d k sù t
 ‚ t g  | d | g ƒ} | ƒ  | j	 ƒ  d k s0t
 ‚ | j	 ƒ  d k sHt
 ‚ t | g | ƒ } | d ƒ | j	 ƒ  d k s|t
 ‚ | j	 ƒ  d k s”t
 ‚ t g  | d i | d | 6ƒ} | ƒ  | j	 ƒ  d k sÓt
 ‚ | j	 ƒ  d k sët
 ‚ |  j t j j t g  | ƒ d  S(	   Ni    i   i    R   R‚   i   i   R   (   R   R.   t   configdefaultst   python_int_bitwidthR   R   R€   R
   R%   R   R$   RX   t   goft   MissingInputError(	   R   R'   Rj   R   R   R   R+   R„   R…   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_default_updates_input'  s8    	
 c         C` ss   t  d ƒ } | d | _ d | } t | g | ƒ } | j ƒ  d k sM t ‚ | d ƒ | j ƒ  d k so t ‚ d  S(   Ni    i   i   i   (   R   R€   R
   R   R$   (   R   R   R   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt"   test_default_updates_partial_graphN  s    

c         C` sš   t  d d ƒ } | d | _ t j d ƒ } | d } t | g | d i | | 6ƒ} t | j j j ƒ d k su t	 ‚ t | j j j
 ƒ d k s– t	 ‚ d  S(   Ng      ð?R   g      @R   i
   Ry   i   (   R   R€   R   t   dscalarR
   t   lent   makert   fgraphRo   R$   Rp   (   R   R   R   RP   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt$   test_givens_replaces_shared_variableX  s    
!c         C` st   t  d d ƒ } | d | _ | d } t g  | d i | d | 6ƒ} | ƒ  d k s[ t ‚ | ƒ  d k sp t ‚ d  S(   Ng      ð?R   i   i
   Ry   i   i"   (   R   R€   R
   R$   (   R   R   RP   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt%   test_givens_replaces_shared_variable2b  s    
 c         C` s>   t  j j d ƒ } |  j t  j j t  j | | | g | ƒ d  S(   NR'   (   R.   R   R   RX   t   compilet   UnusedInputErrorRr   (   R   R'   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_duplicate_inputsk  s    c         C` sI  t  d d ƒ } t  t j d ƒ d ƒ } t j g  g  d | | f | d | f g ƒ} t j g  g  d | | d f | | f g ƒ} | ƒ  | j d t ƒ j d	 k s· t | j ƒ  ƒ ‚ | j d t ƒ j d
 k sä t | j ƒ  ƒ ‚ | ƒ  | j d t ƒ j d k st | j ƒ  ƒ ‚ | j d t ƒ j d k sEt | j ƒ  ƒ ‚ d  S(   Ng      ð?R   i   i   R   R   R   (   i   i   (    (   i   i   (    (   i   i   (	   R   R   RY   R.   Rr   R   R%   t   shapeR$   (   R   R   R   R:   Rd   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_update_samep  s    ..---c         C` sQ  t  d d ƒ } t  t j d ƒ d ƒ } t j g  g  d | | f | d | | f g ƒ} t j g  g  d | | d | f | | f g ƒ} | ƒ  | j d t ƒ j d	 k s¿ t | j ƒ  ƒ ‚ | j d t ƒ j d
 k sì t | j ƒ  ƒ ‚ | ƒ  | j d t ƒ j d k s t | j ƒ  ƒ ‚ | j d t ƒ j d k sMt | j ƒ  ƒ ‚ d  S(   Ng      ð?R   i   i   R   R   R   (   i   i   (    (   i   i   (    (   i   i   (	   R   R   RY   R.   Rr   R   R%   Rž   R$   (   R   R   R   R:   Rd   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_update_equiv‰  s    22---(    t   __name__t
   __module__R   R,   R6   R;   R<   RC   RK   RO   RZ   R_   Rb   Rf   Rg   Rl   Rv   Rx   R|   R   R   R‹   RŒ   R   RŽ   R“   R”   R™   Rš   R   RŸ   R    (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyR      s<   									#				 			
					<			'	'	
	
				t   Test_aliasing_rulesc           B` sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   sß  
    1. Theano manages its own memory space, which typically does not overlap
    with the memory of normal python variables that the user uses.

    2. shared variables are allocated in this memory space, as are the
    temporaries used for Function evalution.

    3. Physically, this managed memory space may be spread across the host,
    on a GPU device(s), or even on a remote machine.

    4. Theano assumes that shared variables are never aliased to one another,
    and tries to make it impossible to accidentally alias them.

    5. Theano's managed data is constant while Theano Functions are not running
    and theano library code is not running.

    6. The default behaviour of Function is to return user-space values for
    outputs, but this can be overridden (borrow=True) for better performance,
    in which case the returned value may be aliased to managed memory, and
    potentially invalidated by the next Theano Function call or call to theano
    library code.
    c         C` s   t  j | ƒ S(   N(   R   t   _shared(   R   R'   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyR   ´  s    c         C` sl   t  j d ƒ } |  j | ƒ } t  j | t | ƒ ƒ s= t ‚ t  j | j d t ƒ t | ƒ ƒ sh t ‚ d  S(   Ni   R   (   i   i   (   R   t   zerosR   t   may_share_memoryR   R$   R   R"   (   R   t   orig_at   A(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_shared_constructor_copies·  s
    c         C` s  y d d  l  j } Wn t k
 r& n Xd d l m } | sL t d ƒ ‚ n  d d l m } | j d d d ƒƒ  } | j d d d ƒƒ  } t j t j	 | d t
 ƒt j	 | d t
 ƒg | | | | ƒ } | j t j d	 d d d d g d d	 d d d g d d d	 d d g d d d d	 d g d d d d d	 g g d d ƒƒ } | | | ƒ } | j t j d	 d d d d g d d	 d d d g d d d	 d d g d d d d	 d g d d d d d	 g g d d ƒƒ } | j ƒ  }	 | | |	 ƒ }
 t j |
 j ƒ  | j ƒ  ƒ st ‚ d  S(
   Ni    (   t   enable_sparses    Optional package sparse disabled(   t   sparset   cscR>   t   float64RD   i   (   t   scipy.sparseR«   t   ImportErrort   theano.sparseRª   R   R.   t
   SparseTypeRr   R	   R%   t
   csc_matrixR   R}   R-   R]   t   todenseR$   (   R   t   spRª   R«   R'   Rj   R:   t   mt
   bogus_valst   m_copyt   vals(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt7   test_sparse_input_aliasing_affecting_inplace_operationsÂ  s:    $$c      
   C` s>  t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j t  j | d t ƒt  j | d t ƒt  j | d t ƒt  j | d t ƒg t  j | d | ƒ t  j | d | ƒ ƒ } t j	 d d d d d g d d ƒ} t j	 d d	 d	 d	 d	 g d	 d d	 d	 d	 g d	 d	 d d	 d	 g d	 d	 d	 d d	 g d	 d	 d	 d	 d g g d d ƒ} | | | | | ƒ } t j	 d d d d d g d d ƒ} t j	 d d	 d	 d	 d	 g d	 d d	 d	 d	 g d	 d	 d d	 d	 g d	 d	 d	 d d	 g d	 d	 d	 d	 d g g d d ƒ} | j
 ƒ  }	 | j
 ƒ  }
 | | |
 | |	 ƒ } t j | | ƒ s:t ‚ d  S(
   NRD   i   i   i   i   i   R>   R­   i    (   R.   R   R@   R   Rr   R	   R%   t   dotR   R}   R-   R]   R$   (   R   R'   Rj   t   m1t   m2R:   t   vRµ   R¶   R·   t   v_copyR¸   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt0   test_input_aliasing_affecting_inplace_operationsô  s4    -$!$!c      
   C` sL  t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j j ƒ  } t  j t  j | d t ƒt  j | d t ƒt  j | d t ƒt  j | d t ƒt  j | d t ƒt  j | d t ƒg t  j | d | ƒ t  j | d | ƒ t  j | d | ƒ ƒ } t j	 d d d d d g d d ƒ} t j	 d d	 g d	 d g g d d ƒ}	 | | d  | d d !| d d !|	 |	 |	 ƒ }
 t j	 d d d d d g d d ƒ} t j	 d d	 g d	 d g g d d ƒ}	 |	 j
 ƒ  } | j
 ƒ  } |	 j
 ƒ  } | j
 ƒ  } | | d  | d d !| d d !|	 | | ƒ } t j | |
 ƒ sHt ‚ d  S(
   NRD   i   i   i   i   i   R>   R­   i    (   R.   R   R@   R   Rr   R	   R%   Rº   R   R}   R-   R]   R$   (   R   R'   Rj   Ra   R»   R¼   t   m3R:   R½   Rµ   R¶   t   m_copy1t   v_copy1t   m_copy2t   v_copy2R¸   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt8   test_partial_input_aliasing_affecting_inplace_operations  s8    '$-$-c         C` sc  |  j  t j d ƒ ƒ } |  j  t j d ƒ ƒ } t j d	 ƒ } t j ƒ  } | d } t | g g  d | | f | | f g ƒ} | | ƒ t j t | ƒ t | ƒ ƒ s® t ‚ t | g g  d | | f | | f g ƒ} | | ƒ t j t | ƒ t | ƒ ƒ st ‚ t | g g  d | | d f | | f g ƒ} | | ƒ t j t | ƒ t | ƒ ƒ sft ‚ t | g g  d | | d f | | f g ƒ} | | ƒ t j t | ƒ t | ƒ ƒ sÃt ‚ t | g | d | | d  f | | f g ƒ} | | ƒ } t j t | ƒ t | ƒ ƒ s"t ‚ t j | t | ƒ ƒ sAt ‚ t j | t | ƒ ƒ s`t ‚ t | g | d | | d  f | | d  d f g ƒ} | | ƒ } t j t | ƒ t | ƒ ƒ sÇt ‚ t j | t | ƒ ƒ sæt ‚ t j | t | ƒ ƒ st ‚ t | g | d d | | d  d f | | d  d f g ƒ} | | ƒ } t j t | ƒ t | ƒ ƒ stt ‚ t j | t | ƒ ƒ s“t ‚ t j | t | ƒ ƒ s²t ‚ t | g | d d | | d  d f | | d  d f g ƒ} | | ƒ } t j t | ƒ t | ƒ ƒ s!t ‚ t j | t | ƒ ƒ s@t ‚ t j | t | ƒ ƒ s_t ‚ d  S(
   Ni   i   R   i   i   i   (   i   i   (   i   i   (   i   i   (	   R   R   R¥   R   R   R
   R¦   R   R$   (   R   R¨   t   Bt   Ct   Dt   DDR:   t   R(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt1   test_potential_output_aliasing_induced_by_updatesK  sN    
*
%+
%/
%.
%.%6%+%+%c         C` s†   |  j  t j d ƒ d ƒ } |  j  t j d ƒ d ƒ } t g  g  d | | f g ƒ} | ƒ  t j t | ƒ t | ƒ ƒ s‚ t ‚ d  S(   Ni   g      à?R   (   i   i   (   i   i   (   R   R   R¥   R
   R¦   R   R$   (   R   R¨   RÆ   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_aliasing_0|  s
    c         C` sð   |  j  t j d ƒ d ƒ } |  j  t j d ƒ d ƒ } t j ƒ  } t | g g  d | | f | | f g ƒ} t j d ƒ } | | ƒ t j t | ƒ t | ƒ ƒ s¬ t ‚ t j | t | ƒ ƒ sË t ‚ t j	 t | ƒ | k ƒ sì t ‚ d  S(   Ni   g      à?R   (   i   i   (   i   i   (   i   i   (
   R   R   R¥   R   R   R
   R¦   R   R$   R#   (   R   R¨   RÆ   RÇ   R:   Ra   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_aliasing_1…  s    *
%c         C` s2  t  j d ƒ d } t  j d ƒ d } |  j | ƒ } |  j | ƒ } t | ƒ } t | ƒ } t g  g  d | | f | | f g ƒ} | ƒ  t  j t | ƒ d k ƒ s« t ‚ t  j t | ƒ d 
k ƒ sÍ t ‚ t  j t | ƒ t | ƒ ƒ sò t ‚ t  j t | ƒ | ƒ st ‚ t  j t | ƒ | ƒ s.t ‚ d  S(   Ni   g      à?R   g      à¿(   i   i   (   i   i   (   R   R¥   R   R   R
   R#   R$   R¦   (   R   R§   t   orig_bR¨   RÆ   t	   data_of_at	   data_of_bR:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_aliasing_2”  s    '!"%c      
   C` s  t  j d ƒ d } t  j d ƒ d } |  j | ƒ } |  j | ƒ } t | ƒ } t | ƒ } t g  g  d | | d  d  … d  d  d … f f | | j f g ƒ} | ƒ  t  j t | ƒ d k ƒ sÇ t ‚ t  j t | ƒ d 
k ƒ sé t ‚ t  j t | ƒ t | ƒ ƒ st ‚ t	 j
 j d k rt  j t | ƒ d	 k  ƒ sAt ‚ | d
 7} t  j t | ƒ d	 k ƒ slt ‚ | d
 8} t  j t | ƒ d	 k  ƒ s—t ‚ | d
 7} t  j t | ƒ d	 k ƒ sÂt ‚ | d
 8} t  j t | ƒ | ƒ sêt ‚ t  j t | ƒ | ƒ st ‚ n  d  S(   Ni   g      à?R   iÿÿÿÿg      à¿t	   DebugModet
   DEBUG_MODEt   FAST_COMPILEi   i
   (   i   i   (   i   i   (   RÒ   RÓ   RÔ   (   R   R¥   R   R   R
   t   TR#   R$   R¦   R.   R   RE   (   R   R§   RÎ   R¨   RÆ   RÏ   RÐ   R:   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test_no_aliasing_2b¬  s.    C!"%		!
!
!
!
(   R¡   R¢   t   __doc__R   R©   R¹   R¿   RÅ   RË   RÌ   RÍ   RÑ   RÖ   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyR£   œ  s   			2	(	/	1				t   Test_rebuild_strictc           B` s   e  Z d  „  Z RS(   c         C` sÒ   t  j ƒ  } t  j d d ƒ \ } } | | } t j | | g | d | | f g d t ƒ} | t j d
 d d ƒt j d d d ƒƒ } | j	 d	 k s t
 ‚ t j | t j d ƒ t j d ƒ k ƒ sÎ t
 ‚ d  S(   NR'   Rj   Ry   t   rebuild_stricti   i   R>   R?   i   (   i   i   (   i   i   (   R   t   imatrixt   ivectorsR.   Rr   R"   R   RY   RL   t   ndimR$   R#   (   R   R   R'   Rj   Ra   R:   t   z_val(    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   test1ß  s    
--(   R¡   R¢   RÞ   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyRØ   Þ  s   t   __main__RÔ   (   t
   __future__R    R   R   t   unittestt   nose.plugins.skipR   t   numpyR   R.   t   theano.tensorR   R   R   R   R   t   theano.compileR	   R
   R   R   R   t   TestCaseR   R£   RØ   R¡   RE   R<   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/compile/tests/test_pfunc.pyt   <module>   s(   "	ÿ ÿ ˆÿ C