๓
เฦ๗Xc           @` s๚   d  d l  m Z m Z m Z d  d l m Z d  d l Z d  d l Z d  d l m	 Z	 d   Z
 d e f d     YZ d e f d	     YZ e d
 k r๖ e e e d    e e e d    e e d  e d  k  e e d  d k  n  d S(   i    (   t   absolute_importt   print_functiont   division(   t
   MutableSetN(   t   string_typesc         C` sX   |  d  k	 rT t |  t t t t j t f  sT t |   d k rQ t	 d   qQ qT n  d  S(   Ni   s1   Get an not ordered iterable when one was expected(
   t   Nonet
   isinstancet   listt   tuplet
   OrderedSett   typest   GeneratorTypeR   t   lent   AssertionError(   t   iterable(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   check_deterministic
   s    	t   Linkc           B` s    e  Z d Z d   Z d   Z RS(   t   prevt   nextt   keyt   __weakref__c         C` sD   |  j    |  j   g } y | j |  j  Wn t k
 r? n X| S(   N(   R   R   t   appendR   t   AttributeError(   t   selft   ret(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __getstate__5   s    c         C` sR   t  j | d  |  _ t  j | d  |  _ t |  d k rN | d |  _ n  d  S(   Ni    i   i   i   (   t   weakreft   refR   R   R   R   (   R   t   state(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __setstate__@   s    (   s   prevs   nexts   keys   __weakref__(   t   __name__t
   __module__t	   __slots__R   R   (    (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyR   0   s   	R	   c           B` s   e  Z d  Z d   Z d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z e d  Z d   Z d   Z RS(   s/   Set the remembers the order elements were addedc         C` s   t  |  |  | O}  d  S(   N(   R   (   R   R   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   updateS   s    
c         C` sY   t  |  t   |  _ } t j |  | _ | _ i  |  _ | d  k	 rU |  | O}  n  d  S(   N(	   R   R   t   _OrderedSet__rootR   R   R   R   t   _OrderedSet__mapR   (   R   R   t   root(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __init__W   s    
	c         C` s   t  |  j  S(   N(   R   R#   (   R   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __len__`   s    c         C` s   | |  j  k S(   N(   R#   (   R   R   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __contains__c   s    c         C` s~   | |  j  k rz t   |  j  | <} |  j } | j } | t j |  | | _ | _ | _ t j |  |   _ | _ n  d  S(   N(   R#   R   R"   R   R   R   R   R   (   R   R   t   linkR$   t   last(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   addf   s    		&c         C` sG   t  |  |  j   } x* | D]" } | | k r | j |  q q W| S(   N(   R   t   copyR*   (   R   t   st   nt   elem(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   uniono   s    
c         C` sU   g  } x* |  D]" } | | k r | j  |  q q Wx | D] } |  j |  q: W|  S(   N(   R   t   remove(   R   R,   t   lR.   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   intersection_updatew   s    c         C` s;   t  |  x* | D]" } | |  k r |  j |  q q W|  S(   N(   R   R0   (   R   R,   R.   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   difference_update   s
    
c         C` s   t    } | j |   | S(   N(   R	   R!   (   R   R-   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyR+      s    	c         C` sL   | |  j  k rH |  j  j |  } | j | j   _ | j | j   _ n  d  S(   N(   R#   t   popR   R   (   R   R   R(   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   discard   s    c         c` s@   |  j  } | j   } x$ | | k	 r; | j V| j   } q Wd  S(   N(   R"   R   R   (   R   R$   t   curr(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __iter__   s
    	c         c` s@   |  j  } | j   } x$ | | k	 r; | j V| j   } q Wd  S(   N(   R"   R   R   (   R   R$   R6   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __reversed__   s
    	c         C` sS   |  s t  d   n  | r0 t t |    } n t t |    } |  j |  | S(   Ns   set is empty(   t   KeyErrorR   t   reversedt   iterR5   (   R   R)   R   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyR4   ค   s    c         C` s1   |  s d |  j  j f Sd |  j  j t |   f S(   Ns   %s()s   %s(%r)(   t	   __class__R   R   (   R   (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __repr__ฎ   s    c         C` sc   t  | t  r= t |   t |  k o< t |   t |  k St  | t  r[ t d   n t Sd  S(   Nsฐ   Cannot compare an `OrderedSet` to a `set` because this comparison cannot be made symmetric: please manually cast your `OrderedSet` into `set` before performing this comparison.(   R   R	   R   R   t   sett	   TypeErrort   NotImplemented(   R   t   other(    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   __eq__ณ   s    .N(   R   R   t   __doc__R!   R   R%   R&   R'   R*   R/   R2   R3   R+   R5   R7   R8   t   TrueR4   R=   RB   (    (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyR	   G   s    														
	t   __main__t
   abracadabat
   simsalabimt   boomt   moob(   t
   __future__R    R   R   t   collectionsR   R
   R   t   sixR   R   t   objectR   R	   R   t   printR   (    (    (    s7   /tmp/pip-build-X4mzal/theano/theano/misc/ordered_set.pyt   <module>   s   	&