B
    ӻd                 @   s   d Z ddlZddlZG dd deZG dd deZG dd deZG d	d
 d
ejjZ	G dd de	Z
G dd dejjZG dd deZdS )z:Utilities for collecting objects based on "is" comparison.    Nc               @   sd   e Zd ZdZddgZdd Zedd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd ZdS )_ObjectIdentityWrappera  Wraps an object, mapping __eq__ on wrapper to "is" on wrapped.

  Since __eq__ is based on object identity, it's safe to also define __hash__
  based on object ids. This lets us add unhashable types like trackable
  _ListWrapper objects to object-identity collections.
  _wrapped__weakref__c             C   s
   || _ d S )N)r   )selfwrapped r   _/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/keras/utils/object_identity.py__init__    s    z_ObjectIdentityWrapper.__init__c             C   s   | j S )N)r   )r   r   r   r   	unwrapped#   s    z _ObjectIdentityWrapper.unwrappedc             C   s   t |tstdd S )Nz3Cannot compare wrapped object with unwrapped object)
isinstancer   	TypeError)r   otherr   r   r   _assert_type'   s    
z#_ObjectIdentityWrapper._assert_typec             C   s   |  | t| jt|jk S )N)r   idr   )r   r   r   r   r   __lt__+   s    
z_ObjectIdentityWrapper.__lt__c             C   s   |  | t| jt|jkS )N)r   r   r   )r   r   r   r   r   __gt__/   s    
z_ObjectIdentityWrapper.__gt__c             C   s"   |d krdS |  | | j|jkS )NF)r   r   )r   r   r   r   r   __eq__3   s    
z_ObjectIdentityWrapper.__eq__c             C   s   |  | S )N)r   )r   r   r   r   r   __ne__9   s    z_ObjectIdentityWrapper.__ne__c             C   s
   t | jS )N)r   r   )r   r   r   r   __hash__<   s    z_ObjectIdentityWrapper.__hash__c             C   s   d t| j| jS )Nz<{} wrapping {!r}>)formattype__name__r   )r   r   r   r   __repr__B   s    z_ObjectIdentityWrapper.__repr__N)r   
__module____qualname____doc__	__slots__r	   propertyr
   r   r   r   r   r   r   r   r   r   r   r   r      s   r   c                   s,   e Zd ZdZ fddZedd Z  ZS )_WeakObjectIdentityWrapperr   c                s   t t| t| d S )N)superr   r	   weakrefref)r   r   )	__class__r   r   r	   J   s    z#_WeakObjectIdentityWrapper.__init__c             C   s   |   S )N)r   )r   r   r   r   r
   M   s    z$_WeakObjectIdentityWrapper.unwrapped)r   r   r   r   r	   r   r
   __classcell__r   r   )r"   r   r   F   s   r   c               @   s"   e Zd ZdZdZe Zdd ZdS )	ReferencezReference that refers an object.

  ```python
  x = [1]
  y = [1]

  x_ref1 = Reference(x)
  x_ref2 = Reference(x)
  y_ref2 = Reference(y)

  print(x_ref1 == x_ref2)
  ==> True

  print(x_ref1 == y)
  ==> False
  ```
  r   c             C   s   | j S )z~Returns the referenced object.

    ```python
    x_ref = Reference(x)
    print(x is x_ref.deref())
    ==> True
    ```
    )r   )r   r   r   r   derefj   s    	zReference.derefN)r   r   r   r   r   r   r
   r%   r   r   r   r   r$   R   s   r$   c               @   sV   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )ObjectIdentityDictionarya  A mutable mapping data structure which compares using "is".

  This is necessary because we have trackable objects (_ListWrapper) which
  have behavior identical to built-in Python lists (including being unhashable
  and comparing based on the equality of their contents by default).
  _storagec             C   s
   i | _ d S )N)r'   )r   r   r   r   r	      s    z!ObjectIdentityDictionary.__init__c             C   s   t |S )N)r   )r   keyr   r   r   	_wrap_key   s    z"ObjectIdentityDictionary._wrap_keyc             C   s   | j | | S )N)r'   r)   )r   r(   r   r   r   __getitem__   s    z$ObjectIdentityDictionary.__getitem__c             C   s   || j | |< d S )N)r'   r)   )r   r(   valuer   r   r   __setitem__   s    z$ObjectIdentityDictionary.__setitem__c             C   s   | j | |= d S )N)r'   r)   )r   r(   r   r   r   __delitem__   s    z$ObjectIdentityDictionary.__delitem__c             C   s
   t | jS )N)lenr'   )r   r   r   r   __len__   s    z ObjectIdentityDictionary.__len__c             c   s   x| j D ]}|jV  qW d S )N)r'   r
   )r   r(   r   r   r   __iter__   s    z!ObjectIdentityDictionary.__iter__c             C   s   dt | j S )NzObjectIdentityDictionary(%s))reprr'   )r   r   r   r   r      s    z!ObjectIdentityDictionary.__repr__N)r   r   r   r   r   r	   r)   r*   r,   r-   r/   r0   r   r   r   r   r   r&   v   s   r&   c               @   s.   e Zd ZdZdgZdd Zdd Zdd Zd	S )
ObjectIdentityWeakKeyDictionaryz?Like weakref.WeakKeyDictionary, but compares objects with "is".r   c             C   s   t |S )N)r   )r   r(   r   r   r   r)      s    z)ObjectIdentityWeakKeyDictionary._wrap_keyc             C   s   t t| jS )N)r.   listr'   )r   r   r   r   r/      s    z'ObjectIdentityWeakKeyDictionary.__len__c             c   s8   | j  }x(|D ] }|j}|d kr*| |= q|V  qW d S )N)r'   keysr
   )r   r4   r(   r
   r   r   r   r0      s    

z(ObjectIdentityWeakKeyDictionary.__iter__N)r   r   r   r   r   r)   r/   r0   r   r   r   r   r2      s
   r2   c               @   s|   e Zd ZdZddgZdd Zedd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )ObjectIdentitySetz6Like the built-in set, but compares objects with "is".r'   r   c                s    t  fddt| D  _d S )Nc             3   s   | ]}  |V  qd S )N)r)   ).0obj)r   r   r   	<genexpr>   s    z-ObjectIdentitySet.__init__.<locals>.<genexpr>)setr3   r'   )r   argsr   )r   r   r	      s    zObjectIdentitySet.__init__c             C   s   t  }| |_|S )N)r5   r'   )Zstorageresultr   r   r   _from_storage   s    zObjectIdentitySet._from_storagec             C   s   t |S )N)r   )r   r(   r   r   r   r)      s    zObjectIdentitySet._wrap_keyc             C   s   |  || jkS )N)r)   r'   )r   r(   r   r   r   __contains__   s    zObjectIdentitySet.__contains__c             C   s   | j | | d S )N)r'   discardr)   )r   r(   r   r   r   r>      s    zObjectIdentitySet.discardc             C   s   | j | | d S )N)r'   addr)   )r   r(   r   r   r   r?      s    zObjectIdentitySet.addc                s    j  fdd|D  d S )Nc                s   g | ]}  |qS r   )r)   )r6   item)r   r   r   
<listcomp>   s    z,ObjectIdentitySet.update.<locals>.<listcomp>)r'   update)r   itemsr   )r   r   rB      s    zObjectIdentitySet.updatec             C   s   | j   d S )N)r'   clear)r   r   r   r   rD      s    zObjectIdentitySet.clearc                s    j  fdd|D S )Nc                s   g | ]}  |qS r   )r)   )r6   r@   )r   r   r   rA      s    z2ObjectIdentitySet.intersection.<locals>.<listcomp>)r'   intersection)r   rC   r   )r   r   rE      s    zObjectIdentitySet.intersectionc                s    t  j fdd|D S )Nc                s   g | ]}  |qS r   )r)   )r6   r@   )r   r   r   rA      s    z0ObjectIdentitySet.difference.<locals>.<listcomp>)r5   r<   r'   
difference)r   rC   r   )r   r   rF      s    zObjectIdentitySet.differencec             C   s
   t | jS )N)r.   r'   )r   r   r   r   r/      s    zObjectIdentitySet.__len__c             c   s$   t | j}x|D ]}|jV  qW d S )N)r3   r'   r
   )r   r4   r(   r   r   r   r0      s    

zObjectIdentitySet.__iter__N)r   r   r   r   r   r	   staticmethodr<   r)   r=   r>   r?   rB   rD   rE   rF   r/   r0   r   r   r   r   r5      s   r5   c               @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
ObjectIdentityWeakSetz5Like weakref.WeakSet, but compares objects with "is".r   c             C   s   t |S )N)r   )r   r(   r   r   r   r)      s    zObjectIdentityWeakSet._wrap_keyc             C   s   t dd | D S )Nc             S   s   g | ]}|qS r   r   )r6   _r   r   r   rA      s    z1ObjectIdentityWeakSet.__len__.<locals>.<listcomp>)r.   )r   r   r   r   r/      s    zObjectIdentityWeakSet.__len__c             c   s<   t | j}x,|D ]$}|j}|d kr.| | q|V  qW d S )N)r3   r'   r
   r>   )r   r4   r(   r
   r   r   r   r0      s    

zObjectIdentityWeakSet.__iter__N)r   r   r   r   r   r)   r/   r0   r   r   r   r   rH      s
   rH   )r   collectionsr    objectr   r   r$   abcMutableMappingr&   r2   
MutableSetr5   rH   r   r   r   r   <module>   s   0$$0