ó
¾÷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	 m
 Z
 d d l Z d d l Z d Z d Z d	 Z d
 Z d Z e j d ƒ Z d e f d „  ƒ  YZ d S(   sK   Defines Updates object for storing a (SharedVariable, new_value) mapping.

i    (   t   absolute_importt   print_functiont   division(   t   OrderedDict(   t	   iteritems(   t   SharedVariableNs
   theano-devs    (c) 2010, Universite de Montreals   3-clause BSD Licenses(   theano-dev <theano-dev@googlegroups.com>s   restructuredtext ens   theano.updatest   OrderedUpdatesc           B` s>   e  Z d  Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   sš   
    Dict-like mapping from SharedVariable keys to their new values.

    This mapping supports the use of the "+" operator for the union of updates.
    c         O` s®   t  | ƒ d k r_ t | d t ƒ r_ t  | d ƒ d k r_ t | d t ƒ r_ t j d ƒ n  t t |  ƒ j | | Ž  x/ |  D]' } t | t	 ƒ s t
 d | ƒ ‚ q q Wd  S(   Ni   i    sÒ   Initializing an `OrderedUpdates` from a non-ordered dictionary with 2+ elements could make your code non-deterministic. You can use an OrderedDict that is available at theano.compat.OrderedDict for python 2.6+.s4   OrderedUpdates keys must inherit from SharedVariable(   t   lent
   isinstancet   dictR   t   warningst   warnt   superR   t   __init__R   t	   TypeError(   t   selft   keyt   kwargs(    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyR      s    c         C` s;   t  | t ƒ r( t t |  ƒ j | | ƒ St d | ƒ ‚ d  S(   Ns4   OrderedUpdates keys must inherit from SharedVariable(   R   R   R   R   t   __setitem__R   (   R   R   t   value(    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyR   1   s    	c         C` s¼   | d  k r d  St | t ƒ rW t | ƒ d k rW t | t ƒ rW t j d d d ƒn  x^ t t | ƒ ƒ D]J \ } } | |  k rª |  | | k r˜ qj n  t d | ƒ ‚ n  | |  | <qj Wd  S(   Ni   sr   Updating an `OrderedUpdates` with a non-ordered dictionary with 2+ elements could make your code non-deterministict
   stackleveli   t	   Collision(	   t   NoneR   R	   R   R   R
   R   R   t   KeyError(   R   t   otherR   t   val(    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyt   update@   s    
c         C` s'   t  ƒ  } | j |  ƒ | j | ƒ | S(   N(   R   R   (   R   R   t   rval(    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyt   __add__R   s    	c         C` s'   t  ƒ  } | j |  ƒ | j | ƒ | S(   N(   R   R   (   R   R   R   (    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyt   __radd__X   s    	N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyR      s   			(   R    t
   __future__R    R   R   t   collectionsR   t   sixR   t   theano.compile.sharedvalueR   t   loggingR
   t   __authors__t   __copyright__t   __license__t   __contact__t   __docformat__t	   getLoggert   loggerR   (    (    (    s.   /tmp/pip-build-isqEY4/theano/theano/updates.pyt   <module>   s   