o
    ?e*                     @   s   d Z ddlZddlmZm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.    N)AnySetc                   @   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   n/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/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 )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 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__0   r   z_ObjectIdentityWrapper.__gt__c                 C   s"   |d u rdS |  | | j|ju S )NF)r   r   r   r   r   r   __eq__4   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| jS )Nz<{} wrapping {!r}>)formattype__name__r   r   r   r   r   __repr__C      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 r   )superr+   r   weakrefrefr	   	__class__r   r   r   K      z#_WeakObjectIdentityWrapper.__init__c                 C   s   |   S r   r   r   r   r   r   r   N   s   z$_WeakObjectIdentityWrapper.unwrapped)r#   r&   r'   r)   r   r*   r   __classcell__r   r   r/   r   r+   G   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   )z~Returns the referenced object.

    ```python
    x_ref = Reference(x)
    print(x is x_ref.deref())
    ==> True
    ```
    r   r   r   r   r   derefk   s   	zReference.derefN)r#   r&   r'   r(   r)   r*   r   r4   r   r   r   r   r3   S   s
    r3   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   )r6   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   r6   r;   r9   r   r   r   __getitem__      z$ObjectIdentityDictionary.__getitem__c                 C   s   || j | |< d S r   r=   )r
   r:   valuer   r   r   __setitem__   r%   z$ObjectIdentityDictionary.__setitem__c                 C   s   | j | |= d S r   r=   r9   r   r   r   __delitem__   s   z$ObjectIdentityDictionary.__delitem__c                 C   r   r   lenr6   r   r   r   r   __len__   r   z ObjectIdentityDictionary.__len__c                 c   s    | j D ]}|jV  qd S r   )r6   r   r9   r   r   r   __iter__   s   

z!ObjectIdentityDictionary.__iter__c                 C   s   dt | j S )NzObjectIdentityDictionary(%s))reprr6   r   r   r   r   r$         z!ObjectIdentityDictionary.__repr__N)r#   r&   r'   r(   r)   r   r;   r>   rA   rB   rE   rF   r$   r   r   r   r   r5   w   s    r5   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   r7   r   r+   r9   r   r   r   r;      r<   z)ObjectIdentityWeakKeyDictionary._wrap_keyc                 C   s   t t| jS r   )rD   listr6   r   r   r   r   rE      s   z'ObjectIdentityWeakKeyDictionary.__len__c                 c   s6    | j  }|D ]}|j}|d u r| |= q|V  qd S r   )r6   keysr   r
   rL   r:   r   r   r   r   rF      s   
z(ObjectIdentityWeakKeyDictionary.__iter__Nr#   r&   r'   r(   r)   r;   rE   rF   r   r   r   r   rI      s    rI   c                   @   s   e Zd ZdZddgZdd Zdee defdd	Z	dee def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".r6   r   c                    s    t  fddt| D  _d S )Nc                 3   s    | ]}  |V  qd S r   r;   ).0objr   r   r   	<genexpr>   s    z-ObjectIdentitySet.__init__.<locals>.<genexpr>)setrK   r6   )r
   argsr   r   r   r      s    zObjectIdentitySet.__init__r   returnc                 C   s@   t |tstS t| t|krdS | jD ]	}||vr dS qdS NFT)r   r   NotImplementedrD   r6   r
   r   itemr   r   r   __le__   s   

zObjectIdentitySet.__le__c                 C   s>   t |tstS t| t|k rdS |D ]	}|| vr dS qdS rW   )r   r   rX   rD   rY   r   r   r   __ge__   s   
zObjectIdentitySet.__ge__c                 C   s   t  }| |_|S r   )rO   r6   )Zstorageresultr   r   r   _from_storage   s   zObjectIdentitySet._from_storagec                 C   r7   r   r8   r9   r   r   r   r;      r<   zObjectIdentitySet._wrap_keyc                 C   s   |  || jv S r   )r;   r6   r9   r   r   r   __contains__   r?   zObjectIdentitySet.__contains__c                 C      | j | | d S r   )r6   discardr;   r9   r   r   r   ra         zObjectIdentitySet.discardc                 C   r`   r   )r6   addr;   r9   r   r   r   rc      rb   zObjectIdentitySet.addc                    s    j  fdd|D  d S )Nc                       g | ]}  |qS r   rP   rQ   rZ   r   r   r   
<listcomp>       z,ObjectIdentitySet.update.<locals>.<listcomp>)r6   updater
   itemsr   r   r   rh      s   zObjectIdentitySet.updatec                 C   s   | j   d S r   )r6   clearr   r   r   r   rk      rH   zObjectIdentitySet.clearc                    s    j  fdd|D S )Nc                    rd   r   rP   re   r   r   r   rf      rg   z2ObjectIdentitySet.intersection.<locals>.<listcomp>)r6   intersectionri   r   r   r   rl      r1   zObjectIdentitySet.intersectionc                    s    t  j fdd|D S )Nc                    rd   r   rP   re   r   r   r   rf      rg   z0ObjectIdentitySet.difference.<locals>.<listcomp>)rO   r^   r6   
differenceri   r   r   r   rm      s   zObjectIdentitySet.differencec                 C   r   r   rC   r   r   r   r   rE      r   zObjectIdentitySet.__len__c                 c   s"    t | j}|D ]}|jV  qd S r   )rK   r6   r   )r
   rL   r:   r   r   r   rF      s
   

zObjectIdentitySet.__iter__N)r#   r&   r'   r(   r)   r   r   r   boolr[   r\   staticmethodr^   r;   r_   ra   rc   rh   rk   rl   rm   rE   rF   r   r   r   r   rO      s$    


rO   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   r7   r   rJ   r9   r   r   r   r;      r<   zObjectIdentityWeakSet._wrap_keyc                 C   s   t dd | D S )Nc                 S   s   g | ]}|qS r   r   )rQ   _r   r   r   rf      s    z1ObjectIdentityWeakSet.__len__.<locals>.<listcomp>)rD   r   r   r   r   rE      s   zObjectIdentityWeakSet.__len__c                 c   s:    t | j}|D ]}|j}|d u r| | q|V  qd S r   )rK   r6   r   ra   rM   r   r   r   rF     s   
zObjectIdentityWeakSet.__iter__NrN   r   r   r   r   rp      s    rp   )r(   collectionstypingr   r   r-   objectr   r+   r3   abcMutableMappingr5   rI   
MutableSetrO   rp   r   r   r   r   <module>   s    0$$D