o
    Ne                     @   s   d Z ddlZddlZG dd d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
   KD:\Projects\ConvertPro\env\Lib\site-packages\keras/utils/object_identity.py__init__       
z_ObjectIdentityWrapper.__init__c                 C      | j S r   r   r   r
   r
   r   	unwrapped#   s   z _ObjectIdentityWrapper.unwrappedc                 C   s   t |tstd| d S )NzlCannot compare wrapped object with unwrapped object. Expect the object to be `_ObjectIdentityWrapper`. Got: )
isinstancer   	TypeErrorr   otherr
   r
   r   _assert_type'   s   
z#_ObjectIdentityWrapper._assert_typec                 C   s   |  | t| jt|jk S r   r   idr   r   r
   r
   r   __lt__/      
z_ObjectIdentityWrapper.__lt__c                 C   s   |  | t| jt|jkS r   r   r   r
   r
   r   __gt__3   r   z_ObjectIdentityWrapper.__gt__c                 C   s"   |d u rdS |  | | j|ju S )NF)r   r   r   r
   r
   r   __eq__7   s   
z_ObjectIdentityWrapper.__eq__c                 C   s   |  | S r   )r   r   r
   r
   r   __ne__=   s   z_ObjectIdentityWrapper.__ne__c                 C   
   t | jS r   )r   r   r   r
   r
   r   __hash__@   s   
z_ObjectIdentityWrapper.__hash__c                 C   s   dt | j d| jdS )N<z
 wrapping >)type__name__r   r   r
   r
   r   __repr__F   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| d S r   )superr   weakrefrefr   	__class__r
   r   r   N      z#_WeakObjectIdentityWrapper.__init__c                 C   s   |   S r   r   r   r
   r
   r   r   Q   s   z$_WeakObjectIdentityWrapper.unwrapped)r"   r$   r%   r'   r   r(   r   __classcell__r
   r
   r-   r   r)   J   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   r   )zReturns the referenced object.

        ```python
        x_ref = Reference(x)
        print(x is x_ref.deref())
        ==> True
        ```
        r   r   r
   r
   r   derefn   s   	zReference.derefN)r"   r$   r%   r&   r'   r(   r   r2   r
   r
   r
   r   r1   V   s
    r1   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 r   )r4   r   r
   r
   r   r      r   z!ObjectIdentityDictionary.__init__c                 C      t |S r   r   r   keyr
   r
   r   	_wrap_key      z"ObjectIdentityDictionary._wrap_keyc                 C   s   | j | | S r   r4   r9   r7   r
   r
   r   __getitem__      z$ObjectIdentityDictionary.__getitem__c                 C   s   || j | |< d S r   r;   )r   r8   valuer
   r
   r   __setitem__   s   z$ObjectIdentityDictionary.__setitem__c                 C   s   | j | |= d S r   r;   r7   r
   r
   r   __delitem__      z$ObjectIdentityDictionary.__delitem__c                 C   r   r   lenr4   r   r
   r
   r   __len__   r   z ObjectIdentityDictionary.__len__c                 c   s    | j D ]}|jV  qd S r   )r4   r   r7   r
   r
   r   __iter__   s   

z!ObjectIdentityDictionary.__iter__c                 C   s   dt | j dS )NzObjectIdentityDictionary())reprr4   r   r
   r
   r   r#      rA   z!ObjectIdentityDictionary.__repr__N)r"   r$   r%   r&   r'   r   r9   r<   r?   r@   rD   rE   r#   r
   r
   r
   r   r3   z   s    r3   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   r5   r   r)   r7   r
   r
   r   r9      r:   z)ObjectIdentityWeakKeyDictionary._wrap_keyc                 C   s   t t| jS r   )rC   listr4   r   r
   r
   r   rD      s   z'ObjectIdentityWeakKeyDictionary.__len__c                 c   s6    | j  }|D ]}|j}|d u r| |= q|V  qd S r   )r4   keysr   r   rK   r8   r   r
   r
   r   rE      s   
z(ObjectIdentityWeakKeyDictionary.__iter__Nr"   r$   r%   r&   r'   r9   rD   rE   r
   r
   r
   r   rH      s    rH   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".r4   r   c                    s    t  fddt| D  _d S )Nc                 3   s    | ]}  |V  qd S r   r9   ).0objr   r
   r   	<genexpr>   s    z-ObjectIdentitySet.__init__.<locals>.<genexpr>)setrJ   r4   )r   argsr
   r   r   r      s    zObjectIdentitySet.__init__c                 C   s   t  }| |_|S r   )rN   r4   )Zstorageresultr
   r
   r   _from_storage   s   zObjectIdentitySet._from_storagec                 C   r5   r   r6   r7   r
   r
   r   r9      r:   zObjectIdentitySet._wrap_keyc                 C   s   |  || jv S r   )r9   r4   r7   r
   r
   r   __contains__   r=   zObjectIdentitySet.__contains__c                 C      | j | | d S r   )r4   discardr9   r7   r
   r
   r   rY      r/   zObjectIdentitySet.discardc                 C   rX   r   )r4   addr9   r7   r
   r
   r   rZ      r/   zObjectIdentitySet.addc                    s    j  fdd|D  d S )Nc                       g | ]}  |qS r
   rO   rP   itemr   r
   r   
<listcomp>       z,ObjectIdentitySet.update.<locals>.<listcomp>)r4   updater   itemsr
   r   r   r`      s   zObjectIdentitySet.updatec                 C   s   | j   d S r   )r4   clearr   r
   r
   r   rc      s   zObjectIdentitySet.clearc                    s    j  fdd|D S )Nc                    r[   r
   rO   r\   r   r
   r   r^      r_   z2ObjectIdentitySet.intersection.<locals>.<listcomp>)r4   intersectionra   r
   r   r   rd      s   zObjectIdentitySet.intersectionc                    s    t  j fdd|D S )Nc                    r[   r
   rO   r\   r   r
   r   r^      r_   z0ObjectIdentitySet.difference.<locals>.<listcomp>)rN   rV   r4   
differencera   r
   r   r   re      s   zObjectIdentitySet.differencec                 C   r   r   rB   r   r
   r
   r   rD      r   zObjectIdentitySet.__len__c                 c   s"    t | j}|D ]}|jV  qd S r   )rJ   r4   r   )r   rK   r8   r
   r
   r   rE      s
   

zObjectIdentitySet.__iter__N)r"   r$   r%   r&   r'   r   staticmethodrV   r9   rW   rY   rZ   r`   rc   rd   re   rD   rE   r
   r
   r
   r   rN      s     
rN   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   r5   r   rI   r7   r
   r
   r   r9      r:   zObjectIdentityWeakSet._wrap_keyc                 C   s   t dd | D S )Nc                 S   s   g | ]}|qS r
   r
   )rP   _r
   r
   r   r^      s    z1ObjectIdentityWeakSet.__len__.<locals>.<listcomp>)rC   r   r
   r
   r   rD      s   zObjectIdentityWeakSet.__len__c                 c   s:    t | j}|D ]}|j}|d u r| | q|V  qd S r   )rJ   r4   r   rY   rL   r
   r
   r   rE      s   
zObjectIdentityWeakSet.__iter__NrM   r
   r
   r
   r   rg      s    rg   )r&   collectionsr+   r   r)   r1   abcMutableMappingr3   rH   
MutableSetrN   rg   r
   r
   r
   r   <module>   s    4$$3