
Xc           @` s  d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z m Z d d l Z d d l m Z m Z d d	 l m Z e	 j e  Z d
   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ yU e j j  rRe j! j" j# d   n  d d l m$ Z$ d e$ j% e f d     YZ& Wnw e' k
 rng e( e j! j" j# f k
 rZ) g  e D] Z* e* j+ d k re* ^ qd j, j- d  st. e)   n Xd e j/ f d     YZ0 d S(   s   
VMs that run Theano graph computations.

A VM is not actually different from a Linker, we just decided
VM was a better name at some point.

i    (   t   absolute_importt   print_functiont   divisioni   (   t   link(   t   defaultdictN(   t   configt   _config_var_list(   t	   iteritemst
   itervalues(   t   xrangec         C` s  i  } i  } x | j  D] } g  | | <q Wi  } t g   }	 t g   }
 xNt t |    D]:} |  | } t | j d d  } t | j d d  } d } xE| j D]:} x | j D] } d | | d <q Wd } | r!| | k r!| | } t |  d k st d   | j	 | d } n  | r| | k r| d k sEt  | | } t |  d k smt d   | j	 | d } n  | d k	 rt
 | t j  st  | j | |  } | | | <| | j |  n  | d 7} q Wx| j	 D]} | | k o| | st  t | d d  d k r| | d r| | j k r| j rt g  | j | g   D] } | | d ^ qe r| |
 k rd } | | k r\| j | g   r\xt | d t |    D] } | d k	 rPn  xo |  | j D]` } t | d d  d k r| |	 k r| j | j k r| } |	 j |  |
 j |  PqqWqWn| | k ro| | } | | | k r| | j |  n  | | ro| | j	 k rot
 | t j  rox t | d t |    D] } | d k	 rPn  xo |  | j D]` } t | d d  d k r| |	 k r| j | j k r| } |	 j |  |
 j |  PqqWqWqon  | d k	 r| | g | | <qqqWq[ W| S(	   s*   
    WRITEME : explain the parameters
    t   destroy_mapt   view_mapi    i   s9   Here we only support the possibility to destroy one inputs6   Here we only support the possibility to view one inputt   ndimN(   t	   variablest   sett   ranget   lent   getattrt   opt   Nonet   outputst   AssertionErrort   inputst
   isinstancet   theanot   Variablet   gett   appendt   ownert   allt   typet   addt   removet   Constant(   t   ordert   fgrapht   storage_mapt   compute_map_ret   dependenciest   reallocated_infot	   viewed_byt   vart   view_oft   pre_allocatedt	   allocatedt   idxt   nodet   dmapt   vmapt   idx_ot   outt   inst   idx_vt   origint   vt	   reuse_outt   i(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   calculate_reallocate_info   s    



'- 
 t   VMc           B` s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sw  
    A VM object's __call__ method evaluates a Theano program.

    The Stack should be considered the reference VM/Linker implementation.
    It can correctly evaluate all graphs and is the easiest to read. The CVM
    is a port of Stack, and should have the same behavior, but run faster.
    The CVM's code is harder to read though.

    The other python VMs are maybe not necessary anymore, and don't take
    advantage of lazy computation, though they still produce the correct
    output for lazy nodes.

    Parameters
    ----------
    nodes
        A list of nodes in toposort order.
    thunks
        A list of thunks to execute those nodes, in toposort order.
    pre_call_clear
        A list of containers to empty at the beginning of each call.

    Attributes
    ----------
    call_counts
        List of integers, one for each thunk. call_count[i] is the number of
        times thunks[i] was called in the course of computations performed by
        call_with_timers().
    call_times
        List of floats, one for each thunk. call_times[i] is the amount of
        runtime spent on thunks[i] in the course of computations performed by
        call_with_timers().

    need_update_inputs : bool
        True indicates that Function.__call__ must implement the feedback from
        output storage to input storage. False means it *must not* repeat that
        feedback.

    c         C` s   t  |  t  |  k r$ t    n  | |  _ | |  _ | |  _ d g t  |  |  _ d g t  |  |  _ t |  _ t	 |  _
 d  S(   Ni    (   R   t
   ValueErrort   nodest   thunkst   pre_call_cleart   call_countst
   call_timest   Falset   time_thunkst   Truet   need_update_inputs(   t   selfR<   R=   R>   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   __init__   s    				c         C` s   t  d   d S(   s   
        Run the machine.

        Postcondition - all output variables have been computed.  VMs vary in
        what exactly this means and how it is done.

        s   override meN(   t   NotImplementedError(   RE   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   __call__   s    c         C` s   t  d   d S(   s   
        Free any internal references to temporary variables.

        Free internal variables and outputs.  Essentially, free as much memory
        as possible without intefering with the ability to evaluate subsequent
        calls.

        s   override meN(   RG   (   RE   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   clear_storage   s    	c         C` sj  x t  |  j |  j |  j |  j  D]t \ } } } } | j j | d  | j | c | 7<| j j | d  | j | c | 7<t | d  | j	 | <q" Wt |  d  r |  j
 j   | _
 |  j j   | _ n  t |  d  r |  j | _ n  t |  d  r|  j | _ n  t |  d  r,|  j | _ n  x7 t t |  j   D]  } d |  j | <d |  j | <qBWd S(	   s4   
        Accumulate into the profile object
        g        i    t   cthunkt   variable_shapet   node_executed_ordert   node_cleared_orderR&   N(   t   zipR<   R=   R@   R?   t
   apply_timet
   setdefaultt   apply_callcountt   hasattrt   apply_cimplRK   t   copyt   variable_stridesRL   RM   R&   R	   R   (   RE   t   profileR.   t   thunkt   tt   cR8   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   update_profile   s&    "(   t   __name__t
   __module__t   __doc__RF   RH   RI   RZ   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyR:   t   s
   &		
	t   Loopc           B` s   e  Z d  Z e Z d   Z RS(   s   
    Unconditional start-to-finish program execution in Python.
    No garbage collection is allowed on intermediate results.

    c         C` s0  |  j  r x |  j D] } d  | d <q Wy xx t t |  j |  j   D][ \ } \ } } t j   } |   t j   } |  j | c d 7<|  j	 | c | | 7<qF WWq,t
 j | |  q,Xni x |  j D] } d  | d <q Wy1 x* t |  j |  j  D] \ } } |   q WWn t
 j | |  n Xd  S(   Ni    i   (   RB   R>   R   t	   enumerateRN   R=   R<   t   timeR?   R@   R   t   raise_with_op(   RE   t   contR8   RW   R.   t   t0t   t1(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRH      s(    	"(   R[   R\   R]   RA   t   allow_gcRH   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyR^      s   t   LoopGCc           B` s    e  Z d  Z d   Z d   Z RS(   s   
    Unconditional start-to-finish program execution in Python.
    Garbage collection is possible on intermediate results.

    c         C` sl   t  t |   j | | |  | |  _ t |  _ t |  t |  k oW t |  k n sh t    n  d  S(   N(   t   superRf   RF   t   post_thunk_clearRC   Re   R   R;   (   RE   R<   R=   R>   Rh   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRF   
  s
    		.c   	      C` s|  |  j  r x |  j D] } d  | d <q Wy d } x t |  j |  j |  j  D]} \ } } } t j   } |   t j   } |  j | c d 7<|  j	 | c | | 7<x | D] } d  | d <q W| d 7} qL WWqxt
 j | |  qxXn x |  j D] } d  | d <q WyU xN t |  j |  j |  j  D]1 \ } } } |   x | D] } d  | d <qEWq(WWn t
 j | |  n Xd  S(   Ni    i   (   RB   R>   R   RN   R=   R<   Rh   R`   R?   R@   R   Ra   (	   RE   Rb   R8   RW   R.   t   old_storageRc   Rd   t   old_s(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRH     s8    	(   R[   R\   R]   RF   RH   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRf     s   	t   Stackc           B` s5   e  Z d  Z d d d d  Z d   Z d d  Z RS(   s  
    Finish-to-start evalution order of thunks.

    This supports lazy evaluation of subtrees and partial
    computations of graphs when only some inputs have changed.

    At a pseudo-code level, the basic idea is the following:

    def recursively_evaluate(var):
        if var is up to date:
            return
        if var.owner.inputs are up to date:
            update var
            return
        for input in var.owner.unputs:
            recursively_evaluate(var)

    for output in outputs:
        recursively_evaluate(output)

    The actual logic is more complex to support intermediate
    garbage collection, lazily-evaluated nodes, and better speed.

    c         C` sZ  t  t |   j | | |  | |  _ d |  _ g  | j D] } | j r8 | j ^ q8 |  _ | j |  _ | |  _ i  |  _	 i  |  _
 | |  _ i  |  _ } |
 |  _ | |  _ | |  _ | j   } xf t |  j  D]U \ } } | | | <g  | _ | | k r x' | | D] } | j | j 7_ qWq q W|	 |  _ |  j rV|  j d  k rVt d   n  d  S(   Nt    s#   Must set dependencies when using GC(   Rg   Rk   RF   Re   t   messageR   R   t   base_apply_stackR$   RK   RU   t   compute_mapt   node_idxt   callbackt   callback_inputt	   n_updatest	   orderingsR_   R<   t   destroy_dependenciesR&   R   R;   (   RE   R<   R=   R>   R$   Ro   R#   Re   Rs   R&   Rq   Rr   t   oRp   t   ordsR8   R.   t   prereq(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRF   L  s.    		+							
		c      	   C` s   |  j  | } t j   } |  j |   } |  j j |  t t j   | d  } |  j d k	 r |  j d | d |  j | d |  j d |  j	  n  | | f S(   sw   
        Run the thunk corresponding to Apply instance `node`.

        Calls self.callback if it is defined.

        g|=R.   RW   R$   Ro   N(
   Rp   R`   R=   RL   R   t   maxRq   R   R$   Ro   (   RE   R.   R-   Rc   t   rvalt   dt(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   run_thunk_of_node|  s    		c   !      ` s	  |  j  } |  j   |  j } |  j } g  |  _ g  |  _ x] |  j  D]R } | j d  k   | d <|  j r@   | d r@ |  j | |  j  | d  q@ q@ W| d  k	 rt	 |  j
  |  j } | t t | t	 |  j
    } g  | D]& } |  j
 | j r |  j
 | j ^ q } n t |  j  } d }	 x t |  j   D] \ }
 } | d d  k rWq5n  t |
 j d  r|
 j j | d  } n d } | |  j |
 <t | d d d  } t | d d t  r| d j j rd } n, t | d d	  r| d j   rd } n  | |  j |
 <q5WxU| rnt	 |  } | |	 k s>t  | }	 | j   } | j } | j
 } | | j } t   f d
   | D  } t   f d   | D  } | |  j | j  s| rz| rzy_|  j! |  \ } } ~ t" j# st" j$ r&|  j | } |  j% | c d 7<|  j& | c | 7<x t' | |  j | j
  D] \ } } |  j( | j
 | }
 t |
 j d  r|
 j j | d  } n d } | |  j |
 <t | d d d  } t | d d t  r| d j j rd } n, t | d d	  r| d j   rd } n  | |  j |
 <qCWn  Wn5 t) k
 r^t* j+ | |  j |  j | d | n Xx | j
 D] } d   | d <qiWg  } |  j, rgx | j D] } | | r| j r| |  j
 k rt   f d   | | D  r`d  | | d <| j- | j j. |   d   | d <t" j/ j0 r]| | k r]t | j1 d t  r]t2 j/ d d d q]q`qqWn  |  j j- |  qk| sk| j- |  | j3 d   | D  qkq| syL |  j! |  \ } } |  j | } |  j% | c d 7<|  j& | c | 7<Wn5 t) k
 r3t* j+ | |  j |  j | d | n X| rx+| D]= } | j- |  | j | j rA| j- | j | j  qAqAWqkt" j# st" j$ rxt' | |  j | j
  D] \ } } |  j( |  j | j
 | }
 t |
 j d  r|
 j j | d  } n d } | |  j |
 <t | d d d  } t | d d t  r\| d j j r\d } n, t | d d	  r| d j   rd } n  | |  j |
 <qWn  g  } |  j, rXx | j D] } | | r| j r| |  j
 k rt4 } x* | | D] }   | d st } PqqW| rQd  | | d <| j- | j j. |   d   | d <qQqqWn  |  j j- |  qqWg  } |  j, rxo | D]d }  |  j r|  |  j
 k r  |  d d k rqqd  | |  d <| j- |   d   |  d <qqWn  |  j j- |  d  S(   Ni    it   get_shape_infos   input no shapet   stridess   input no stridest   flagsRY   t   is_c_contiguousc         3` s   |  ] }   | d  Vq d S(   i    N(    (   t   .0R6   (   Ro   (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pys	   <genexpr>  s    c         3` s   |  ] }   | d  Vq d S(   i    N(    (   R   R6   (   Ro   (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pys	   <genexpr>  s    i   R$   c         3` s   |  ] }   | d  Vq d S(   i    N(    (   R   R6   (   Ro   (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pys	   <genexpr>  s   i   R
   s   There was a bug that existed in the default Theano configuration, only in the development version between July 5th 2012 and July 30th 2012. This was not in a released version. The bug was affecting this script.t
   stackleveli   c         s` s!   |  ] } | j  r | j  Vq d  S(   N(   R   (   R   t   inp(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pys	   <genexpr>3  s   (5   R$   Ro   R=   R&   RL   RM   R   R   Rr   R   R   Rs   t   listR   Rn   R   RR   R   R}   RK   R   RA   R   t   c_contiguousR   RU   R   t   popR   Ru   R   Rp   t   lazyR|   R   RV   t   print_global_statsR?   R@   R_   R<   t	   ExceptionR   Ra   Re   R   t   indext   warnt	   vm_gc_bugR   t   warningst   extendRC   (!   RE   t   output_subsetR$   R=   R&   t   kt   first_updatedR8   t   apply_stackt   last_apply_stack_lenR)   t   datat   sht   stt   apply_stack_lent   current_applyt   current_inputst   current_outputst   current_depst   computed_inst   computed_outst   _R{   t   current_idxR-   Rv   t   input_indext   requirest   rt   empty_storage_mapt   xt   final_indexR6   (    (   Ro   s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRH     s>   						")&					
					
					
!					N(   R[   R\   R]   R   RF   R|   RH   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRk   2  s
   -	s@   lazylinker will not be imported if theano.config.cxx is not set.(   t   lazylinker_ct   CVMc           B` s   e  Z d    Z RS(   c         O` s   t  j j |  | |  d  S(   N(   R   t   CLazyLinkerRF   (   RE   t   argst   kwargs(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRF     s    (   R[   R\   RF   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyR     s   t   linkert   cvmt	   VM_Linkerc        	   B` sw   e  Z d  Z d e d d d d d d d  Z d d d  Z d   Z d   Z d   Z	 d d d d d  Z
 d   Z RS(	   s  
    Class that satisfies the Linker interface by acting as a VM factory.

    Parameters
    ----------
    allow_gc
        Force the virtual machine to clean up unnecessary
        references, in order to allow garbage collection on
        intermediate values during computation of a function.
        If None use as default the value of the Theano flag allow_gc.
    use_cloop
        Use the C-based virtual machine if possible
    callback
        A callable object to call after each call to a thunk within
        the virtual machine.  It will be called with four arguments called
        'node', 'thunk', 'storage_map', and 'compute_map'.
    callback_input
        A callable object to call on each input to the graph
        (variables with no owner).  This includes constants and shared
        variables values.  It will be called with two arguments:
        'var', 'value'.
    lazy
        Useful only when use_cloop is False. When lazy is None, use the
        theano flag vm.lazy value. Then if we have a None (default) we auto
        detect if lazy evaluation is needed and use the apropriate
        version. If lazy is True or False, we force the version used
        between Loop/LoopGC and Stack.
    c_thunks
        If None or True, don't change the default. If False,
        don't compile c code for the thunks.
    allow_partial_eval
        If True, enforces usage of Stack or CVM, to allow for partial
        evaluation of functions (calculating a subset of outputs).

    c	   	      C` s   | d  k r t j } n  d  |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | d  k ro t t	 j j
  } n  | |  _ | |  _ i  |  _ | r | |  _ n  d  S(   N(   R   R   Re   R#   t	   use_cloopRq   Rr   R   t   boolR   t   cxxt   c_thunkst   allow_partial_evalt   updated_varst   schedule(	   RE   Re   R   Rq   Rr   R   R   R   R   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyRF     s    									c         C` s   | d	 k r g  } n  |  j d	 k	 r |  j | k	 r t |   d |  j d |  j d |  j d |  j d |  j d |  j d |  j	 d |  j
  j | | |  S| |  _ | |  _ | |  _ |  S(
   s  
        Check if fgraph is the first FunctionGraph that has ever been
        associated to self, else, create a new VM_Linker
        associated to fgraph

        Parameters
        ----------
        fgraph
            A PerformLinker can have accepted one FunctionGraph instance
            at a time.
        no_recycling
            WRITEME

        Returns
        -------
        Self if fgraph is the first FunctionGraph that has ever been
        associated to self, else, a new VM_Linker associated to fgraph.

        Re   R   Rq   Rr   R   R   R   R   N(   R   R#   R   Re   R   Rq   Rr   R   R   R   R   t   acceptt   no_recyclingRV   (   RE   R#   R   RV   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyR     s"    											c         C` s   | |  _  d  S(   N(   R   (   RE   R   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   accept_var_updates  s    c         C` s   i  } x{ | D]s } g  | | <| j  r | j r g  } x5 | j D]* } | d d k r? | | d j 7} q? q? W| | c | 7<q q W| S(   s  
        Returns dict: variable K -> list of variables [v1, v2, v3, ...]
        for each K in variables.

        The variables v1, v2, ... are the full set of variables that depend
        directly on K. When we know that none of them will need to be
        computed, we know that:
        * K will not need to be computed.
        * If K is already computed, it can be released for garbage collection.

        Parameters
        ----------
        variables
            Iterable over the variables used in a graph computation.

        Notes
        -----
        It doesn't take care of the view_map/destroy_map. So it means it relies
        on Python gc no to free the object real storage.

        N.B. gc means garbage collection

        i    t   output(   R   t   clientsR   (   RE   R   R&   R   t   lst   cl(    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   compute_gc_dependencies  s    
	c
   1   &   C` sQ  g  |  j  D] }
 | |
 ^ q
 } |  j d  k	 sl |  j d  k	 sl t j sP t j rY t j sl |  j r?|  j	 r?|  j	 r |  j d  k	 s |  j d  k	 r t
 j d  n  |  j	 r t j r t j d  n  |  j	 r |  j r t j d  n  |  j |  } t | | | | | |  j |  j t |	  d | d |  j d |  j } n|  j	 rxi  } i  } xU t |  D]G \ } } | | | <x. | j | j D] }
 | j |
 t |   qWqaWx4 |  j j |  j j D] }
 | j |
 t |   qWi  } i  } x$ t |  D] \ } } | | | <qWx$ t |  D] \ } } | | | <q#Wg  t t |   D] } | | | ^ qP} g  t t |   D] } | | | ^ q}} | rt | d  t k st  t | d  t k st  n  |  j |  } g  t t |   D]+ } g  | | | D] } | | ^ q^ q} g  } g  } g  } g  } g  } x | D] } g  | j D] }
 | |
 ^ q`} g  | j D] }
 | |
 ^ q}  | j t |   | j t |    | j t |   | j |  | j t |   | j |   qPWd  g t |  }! x7 t |  D]) \ } } | j r | | j |! | <q q Wg  | D] }" t |" j  ^ qT}# g  |  j j D] }
 | |
 ^ q|}$ |  j j    }% g  }& g  }' x t |  D] \ } } |' j d  g  }( xA |% j! | g   D]- }) |( j g  |) j D] }
 | |
 ^ q qWt t" |(   }( |( j#   |& j |(  qWg  }* i  }+ x, t |	  D] \ }, }- | |, |+ | |- <qcWx. |$ D]& }. |. |+ k r|* j |+ |.  qqWt$ j% |  }/ t& | | | d |  j d	 d g t |  d
 d g t |  d | d | d | d | d | d | d | d |! d |# d |$ d |& d |' d |* d | } |/ t$ j% |  k sMt  n |  j }0 |0 d  k rt j' j }0 n  |0 d  k rt( g  | D] }" |" j ^ q }0 n  |0 s|  j rt) | | | |  } qMt* | | |  } nB |  j |  } t | | | | | |  j |  j t |	  d | } | S(   Ns.   CVM does not support callback, using Stack VM.s4   CVM does not support memory profile, using Stack VM.s;   LoopGC does not support partial evaluation, using Stack VM.R&   Rq   Rr   i    Re   R?   R@   g        t   compute_map_listt   storage_map_listt   base_input_output_listt   node_n_inputst   node_n_outputst   node_input_offsett   node_output_offsett	   var_ownert   is_lazy_listt   output_varst   node_prereqst   node_output_sizet   update_storage(+   R   Rq   R   Rr   R   RV   R   t   profile_memoryR   R   t   loggerR   R   R   Rk   R#   Re   R   R_   R   R   RP   R   R	   R   R   R   R   R   R   t   intR   Rt   R   R   t   sortt   syst   getrefcountR   t   vmR   Rf   R^   (1   RE   R<   R=   t   input_storaget   output_storageR$   Rh   t   computedRo   R   R6   R>   t   depsR   t	   nodes_idxt   vars_idxR8   R.   t   nodes_idx_invt   vars_idx_invR)   R   R   t   dependency_mapt   dt   dependency_map_listR   R   R   R   R   t
   inputs_idxt   outputs_idxR   t   thR   R   Rw   R   R   t   prereq_var_idxst   prereq_nodeR   t   update_in_from_outt   ivart   ovart   oidxt   c0R   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   make_vm@  s
    

			
**A  	"#%
			'			c   #   
   C` s  |  j  } |  j |  } |  j } t j | | | | |  \ } } } i  } x$ | D] }	 |	 j d  k g | |	 <qR Wg  }
 t d    } x | j D] } d | | d <q Wt	 | j
 d d   r t	 | j
 d  } n |  j |  } t | | | | |  } t j   } i  } d  } |  j t k r*d } n  x | D] } yo t j   } |
 j | j j | | | | d |  t j   | | | <t |
 d d  st |
 d _ n  Wq1t k
 r} d	 | d
 f | j | _   q1Xq1Wt j   } |  j
 r|  j
 j | | 7_ | |  j
 _ n  xc t | |
  D]R \ } } g  | j D] } | | ^ q<| _ g  | j D] } | | ^ q_| _ q&W|  j } | d  k rt j j } n  | d  k rt g  |
 D] } | j ^ q } n  | pt j
 st j rt j p|  j  p|  j! p|  j" s?x- t# |  D] } | | d | | d <qWn  t j$ |  \ } } |  j% rg  } x | D]x } g  } x\ | j D]Q } | | k r| | j k r| | | k r| | k r| j | |  qqW| j |  qjWn d  } |  j& | |
 | | | | | | |  j' 	 }  | |  _( | |  _) |  g  t | j |  D] \ } }! t j* | |!  ^ qAg  t | j |  D]! \ }" }! t j* |" |! t+  ^ qu|
 | f S(   Nc           S` s   d g S(   Ni    (    (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   <lambda>   s    i   i    R&   t   pyt   impliR   s5   The following error happened while compiling the nodes   
(,   R#   R   R   R   t   map_storageR   R   R   R   R   RV   R   R9   R`   R   RA   R   R   t
   make_thunkRR   R   R   R   t   linker_node_make_thunkst   linker_make_thunk_timeRN   R   R   R   R   R   R   R   Rq   Rr   R   t	   gc_helperRe   R   R   R$   Ro   t	   ContainerRC   (#   RE   t   profilerR   R   R$   R#   R"   R   Ro   R   R=   R%   R)   R&   R'   Rc   R   R   R.   t   thunk_startt   eRd   RW   R6   R   R   t   pairR   t	   last_userRh   t   clear_after_this_thunkt   inputR   t   storageR   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   make_all  s    			
	#'	'!				14c         C` se   |  j  j |  t |  d  s+ t |  _ n  t |  d  sF d  |  _ n  t |  d  sa d  |  _ n  d  S(   NR   R   Rr   (   t   __dict__t   updateRR   RC   R   R   R   Rr   (   RE   R   (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   __setstate__X  s    N(   R[   R\   R]   R   RA   RF   R   R   R   R   R   R   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyR     s   #		*		+	g(1   R]   t
   __future__R    R   R   Rl   R   t   collectionsR   t   loggingR   R`   R   t   theano.configparserR   R   t   theano.gof.cmoduleR   t   sixR   R   t	   six.movesR	   t	   getLoggerR[   R   R9   t   objectR:   R^   Rf   Rk   R   t   goft   cmodulet
   MissingGXXR   R   R   t   ImportErrort   OSErrorR   R   t   fullnamet   defaultt
   startswithR   t   LocalLinkerR   (    (    (    s-   /tmp/pip-build-X4mzal/theano/theano/gof/vm.pyt   <module>   s<   	Yn!/ ` 8