
    0h                         d Z ddlZddlZ G d d      Z G d de      Z G d de      Z G d	 d
ej                  j                        Z G d de      Z	 G d dej                  j                        Z G d de      Zy)z:Utilities for collecting objects based on "is" comparison.    Nc                   X    e Zd ZdZddgZd Zed        Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)_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                     || _         y Nr   )selfwrappeds     \/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/utils/object_identity.py__init__z_ObjectIdentityWrapper.__init__    s	        c                     | j                   S r   r	   r
   s    r   	unwrappedz _ObjectIdentityWrapper.unwrapped#   s    }}r   c                 @    t        |t              st        d|       y )NzlCannot compare wrapped object with unwrapped object. Expect the object to be `_ObjectIdentityWrapper`. Got: )
isinstancer   	TypeErrorr
   others     r   _assert_typez#_ObjectIdentityWrapper._assert_type'   s.    %!78w   9r   c                 z    | j                  |       t        | j                        t        |j                        k  S r   r   idr   r   s     r   __lt__z_ObjectIdentityWrapper.__lt__/   -    % $-- 2enn#555r   c                 z    | j                  |       t        | j                        t        |j                        kD  S r   r   r   s     r   __gt__z_ObjectIdentityWrapper.__gt__3   r   r   c                 Z    |y| j                  |       | j                  |j                  u S )NF)r   r   r   s     r   __eq__z_ObjectIdentityWrapper.__eq__7   s+    =% }}..r   c                 &    | j                  |       S r   )r    r   s     r   __ne__z_ObjectIdentityWrapper.__ne__=   s    ;;u%%%r   c                 ,    t        | j                        S r   )r   r   r   s    r   __hash__z_ObjectIdentityWrapper.__hash__@   s     $--  r   c                 N    dt        |       j                   d| j                  dS )N<z
 wrapping >)type__name__r   r   s    r   __repr__z_ObjectIdentityWrapper.__repr__F   s'    4:&&'z$--1B!DDr   N)r)   
__module____qualname____doc__	__slots__r   propertyr   r   r   r   r    r"   r$   r*    r   r   r   r      sP     ]+I   66/&!Er   r   c                   2     e Zd ZdZ fdZed        Z xZS )_WeakObjectIdentityWrapperr0   c                 J    t         |   t        j                  |             y r   )superr   weakrefref)r
   r   	__class__s     r   r   z#_WeakObjectIdentityWrapper.__init__M   s    W-.r   c                 "    | j                         S r   r	   r   s    r   r   z$_WeakObjectIdentityWrapper.unwrappedP   s    }}r   )r)   r+   r,   r.   r   r/   r   __classcell__)r7   s   @r   r2   r2   J   s!    I/  r   r2   c                   (    e Zd ZdZdZ e       Zd Zy)	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
    ```
    r0   c                     | j                   S )zReturns the referenced object.

        ```python
        x_ref = Reference(x)
        print(x is x_ref.deref())
        ==> True
        ```
        r	   r   s    r   derefzReference.derefm   s     }}r   N)r)   r+   r,   r-   r.   r/   r   r=   r0   r   r   r;   r;   U   s    $ I 
I	r   r;   c                   F    e Zd ZdZdgZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)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                     i | _         y r   )r@   r   s    r   r   z!ObjectIdentityDictionary.__init__   s	    r   c                     t        |      S r   r   r
   keys     r   	_wrap_keyz"ObjectIdentityDictionary._wrap_key       %c**r   c                 >    | j                   | j                  |         S r   r@   rF   rD   s     r   __getitem__z$ObjectIdentityDictionary.__getitem__   s    }}T^^C011r   c                 @    || j                   | j                  |      <   y r   rI   )r
   rE   values      r   __setitem__z$ObjectIdentityDictionary.__setitem__   s    -2dnnS)*r   c                 <    | j                   | j                  |      = y r   rI   rD   s     r   __delitem__z$ObjectIdentityDictionary.__delitem__   s    MM$..-.r   c                 ,    t        | j                        S r   lenr@   r   s    r   __len__z ObjectIdentityDictionary.__len__       4==!!r   c              #   J   K   | j                   D ]  }|j                    y wr   )r@   r   rD   s     r   __iter__z!ObjectIdentityDictionary.__iter__   s#     == 	 C--	 s   !#c                 4    dt        | j                         dS )NzObjectIdentityDictionary())reprr@   r   s    r   r*   z!ObjectIdentityDictionary.__repr__   s    *4+>*?qAAr   N)r)   r+   r,   r-   r.   r   rF   rJ   rM   rO   rS   rV   r*   r0   r   r   r?   r?   y   s9     I+23/" Br   r?   c                   (    e Zd ZdZdgZd Zd Zd Zy)ObjectIdentityWeakKeyDictionaryz?Like weakref.WeakKeyDictionary, but compares objects with "is".r   c                     t        |      S r   r2   rD   s     r   rF   z)ObjectIdentityWeakKeyDictionary._wrap_key       )#..r   c                 >    t        t        | j                              S r   )rR   listr@   r   s    r   rS   z'ObjectIdentityWeakKeyDictionary.__len__   s    4&''r   c              #   z   K   | j                   j                         }|D ]  }|j                  }|| |= |  y wr   )r@   keysr   r
   rb   rE   r   s       r   rV   z(ObjectIdentityWeakKeyDictionary.__iter__   sB     }}!!# 	 CI I	 s   9;Nr)   r+   r,   r-   r.   rF   rS   rV   r0   r   r   r[   r[      s    II/( r   r[   c                   j    e Zd ZdZddgZd Zed        Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)ObjectIdentitySetz6Like the built-in set, but compares objects with "is".r@   r   c                 D     t         fdt        | D               _        y )Nc              3   @   K   | ]  }j                  |        y wr   )rF   ).0objr
   s     r   	<genexpr>z-ObjectIdentitySet.__init__.<locals>.<genexpr>   s     GCDNN3/Gs   )setr`   r@   )r
   argss   ` r   r   zObjectIdentitySet.__init__   s    G4;GGr   c                 (    t               }| |_        |S r   )rf   r@   )storageresults     r   _from_storagezObjectIdentitySet._from_storage   s    "$!r   c                     t        |      S r   rC   rD   s     r   rF   zObjectIdentitySet._wrap_key   rG   r   c                 <    | j                  |      | j                  v S r   )rF   r@   rD   s     r   __contains__zObjectIdentitySet.__contains__   s    ~~c"dmm33r   c                 X    | j                   j                  | j                  |             y r   )r@   discardrF   rD   s     r   rv   zObjectIdentitySet.discard   s    dnnS12r   c                 X    | j                   j                  | j                  |             y r   )r@   addrF   rD   s     r   rx   zObjectIdentitySet.add   s    $..-.r   c                 ~    | j                   j                  |D cg c]  }| j                  |       c}       y c c}w r   )r@   updaterF   r
   itemsitems      r   rz   zObjectIdentitySet.update   s+    uEtdnnT2EFEs   :c                 8    | j                   j                          y r   )r@   clearr   s    r   r   zObjectIdentitySet.clear   s    r   c                 |    | j                   j                  |D cg c]  }| j                  |       c}      S c c}w r   )r@   intersectionrF   r{   s      r   r   zObjectIdentitySet.intersection   s3    }})).34dT^^D!4
 	
4s   9c           
          t         j                  | j                  j                  |D cg c]  }| j	                  |       c}            S c c}w r   )rf   rq   r@   
differencerF   r{   s      r   r   zObjectIdentitySet.difference   s>     ..MM$$u%MtdnnT&:%MN
 	
%Ms   Ac                 ,    t        | j                        S r   rQ   r   s    r   rS   zObjectIdentitySet.__len__   rT   r   c              #   `   K   t        | j                        }|D ]  }|j                    y wr   )r`   r@   r   )r
   rb   rE   s      r   rV   zObjectIdentitySet.__iter__   s-     DMM" 	 C--	 s   ,.N)r)   r+   r,   r-   r.   r   staticmethodrq   rF   rt   rv   rx   rz   r   r   r   rS   rV   r0   r   r   rf   rf      s\    @]+IH  
+43/G



" r   rf   c                   &    e Zd ZdZdZd Zd Zd Zy)ObjectIdentityWeakSetz5Like weakref.WeakSet, but compares objects with "is".r0   c                     t        |      S r   r]   rD   s     r   rF   zObjectIdentityWeakSet._wrap_key   r^   r   c                 >    t        | D cg c]  }| c}      S c c}w r   )rR   )r
   _s     r   rS   zObjectIdentityWeakSet.__len__   s    t$!A$%%$s   	c              #      K   t        | j                        }|D ]&  }|j                  }|| j                  |       #| ( y wr   )r`   r@   r   rv   rc   s       r   rV   zObjectIdentityWeakSet.__iter__   sC     DMM" 	 CI S!	 s   AANrd   r0   r   r   r   r      s    ?I/& r   r   )r-   collectionsr5   r   r2   r;   abcMutableMappingr?   r[   
MutableSetrf   r   r0   r   r   <module>r      s    @   1E 1Eh!7 !& !H!B{== !BH &>  ,0 22 0 f -  r   