
    6bi                         S r SSKrSSKr " S S5      r " S S\5      r " S S\5      r " S	 S
\R                  R                  5      r " S S\5      r	 " S S\R                  R                  5      r " S S\5      rg)z:Utilities for collecting objects based on "is" comparison.    Nc                   `    \ rS rSrSrSS/rS r\S 5       rS r	S r
S	 rS
 rS rS rS rSrg)_ObjectIdentityWrapper   a  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                     Xl         g Nr   )selfwrappeds     \/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/utils/object_identity.py__init___ObjectIdentityWrapper.__init__    s        c                     U R                   $ r	   r
   r   s    r   	unwrapped _ObjectIdentityWrapper.unwrapped#   s    }}r   c                 J    [        U[        5      (       d  [        SU 35      eg )NzlCannot compare wrapped object with unwrapped object. Expect the object to be `_ObjectIdentityWrapper`. Got: )
isinstancer   	TypeErrorr   others     r   _assert_type#_ObjectIdentityWrapper._assert_type'   s1    %!788w   9r   c                 z    U R                  U5        [        U R                  5      [        UR                  5      :  $ r	   r   idr   r   s     r   __lt___ObjectIdentityWrapper.__lt__/   -    % $-- 2enn#555r   c                 z    U R                  U5        [        U R                  5      [        UR                  5      :  $ r	   r   r   s     r   __gt___ObjectIdentityWrapper.__gt__3   r!   r   c                 \    Uc  gU R                  U5        U R                  UR                  L $ )NF)r   r   r   s     r   __eq___ObjectIdentityWrapper.__eq__7   s+    =% }}..r   c                 .    U R                  U5      (       + $ r	   )r&   r   s     r   __ne___ObjectIdentityWrapper.__ne__=   s    ;;u%%%r   c                 ,    [        U R                  5      $ r	   )r   r   r   s    r   __hash___ObjectIdentityWrapper.__hash__@   s     $--  r   c                 P    S[        U 5      R                   SU R                  < S3$ )N<z
 wrapping >)type__name__r   r   s    r   __repr___ObjectIdentityWrapper.__repr__F   s'    4:&&'z$--1B!DDr   r
   N)r2   
__module____qualname____firstlineno____doc__	__slots__r   propertyr   r   r   r#   r&   r)   r,   r3   __static_attributes__ r   r   r   r      sP     ]+I   66/&!Er   r   c                   <   ^  \ rS rSrSrU 4S jr\S 5       rSrU =r	$ )_WeakObjectIdentityWrapperJ   r<   c                 L   > [         TU ]  [        R                  " U5      5        g r	   )superr   weakrefref)r   r   	__class__s     r   r   #_WeakObjectIdentityWrapper.__init__M   s    W-.r   c                 "    U R                  5       $ r	   r
   r   s    r   r   $_WeakObjectIdentityWrapper.unwrappedP   s    }}r   )
r2   r5   r6   r7   r9   r   r:   r   r;   __classcell__)rD   s   @r   r>   r>   J   s!    I/  r   r>   c                   0    \ rS rSrSrSr\" 5       rS rSr	g)	ReferenceU   zReference 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                     U R                   $ )zfReturns the referenced object.

```python
x_ref = Reference(x)
print(x is x_ref.deref())
==> True
```
r
   r   s    r   derefReference.derefm   s     }}r   N)
r2   r5   r6   r7   r8   r9   r:   r   rM   r;   r<   r   r   rJ   rJ   U   s    $ I 
I	r   rJ   c                   N    \ rS rSrSrS/rS rS rS rS r	S r
S	 rS
 rS rSrg)ObjectIdentityDictionaryy   a  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                     0 U l         g r	   rR   r   s    r   r   !ObjectIdentityDictionary.__init__   s	    r   c                     [        U5      $ r	   r   r   keys     r   	_wrap_key"ObjectIdentityDictionary._wrap_key       %c**r   c                 >    U R                   U R                  U5         $ r	   rR   rZ   rX   s     r   __getitem__$ObjectIdentityDictionary.__getitem__   s    }}T^^C011r   c                 >    X R                   U R                  U5      '   g r	   r^   )r   rY   values      r   __setitem__$ObjectIdentityDictionary.__setitem__   s    -2dnnS)*r   c                 <    U R                   U R                  U5      	 g r	   r^   rX   s     r   __delitem__$ObjectIdentityDictionary.__delitem__   s    MM$..-.r   c                 ,    [        U R                  5      $ r	   lenrR   r   s    r   __len__ ObjectIdentityDictionary.__len__       4==!!r   c              #   N   #    U R                    H  nUR                  v   M     g 7fr	   )rR   r   rX   s     r   __iter__!ObjectIdentityDictionary.__iter__   s     ==C-- !s   #%c                 4    S[        U R                  5       S3$ )NzObjectIdentityDictionary())reprrR   r   s    r   r3   !ObjectIdentityDictionary.__repr__   s    *4+>*?qAAr   rT   N)r2   r5   r6   r7   r8   r9   r   rZ   r_   rc   rf   rk   ro   r3   r;   r<   r   r   rP   rP   y   s9     I+23/" Br   rP   c                   0    \ rS rSrSrS/rS rS rS rSr	g)	ObjectIdentityWeakKeyDictionary   z?Like weakref.WeakKeyDictionary, but compares objects with "is".r   c                     [        U5      $ r	   r>   rX   s     r   rZ   )ObjectIdentityWeakKeyDictionary._wrap_key       )#..r   c                 >    [        [        U R                  5      5      $ r	   )rj   listrR   r   s    r   rk   'ObjectIdentityWeakKeyDictionary.__len__   s    4&''r   c              #      #    U R                   R                  5       nU H  nUR                  nUc  X	 M  Uv   M     g 7fr	   )rR   keysr   r   r   rY   r   s       r   ro   (ObjectIdentityWeakKeyDictionary.__iter__   s:     }}!!#CI I s   <>r<   N
r2   r5   r6   r7   r8   r9   rZ   rk   ro   r;   r<   r   r   rv   rv      s    II/( r   rv   c                   r    \ rS rSrSrSS/rS r\S 5       rS r	S r
S	 rS
 rS rS rS rS rS rS rSrg)ObjectIdentitySet   z6Like the built-in set, but compares objects with "is".rR   r   c                 F   ^  [        U 4S j[        U6  5       5      T l        g )Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7fr	   )rZ   ).0objr   s     r   	<genexpr>-ObjectIdentitySet.__init__.<locals>.<genexpr>   s     G;CDNN3//;s   !)setr}   rR   )r   argss   ` r   r   ObjectIdentitySet.__init__   s    G4;GGr   c                 &    [        5       nXl        U$ r	   )r   rR   )storageresults     r   _from_storageObjectIdentitySet._from_storage   s    "$!r   c                     [        U5      $ r	   rW   rX   s     r   rZ   ObjectIdentitySet._wrap_key   r\   r   c                 >    U R                  U5      U R                  ;   $ r	   )rZ   rR   rX   s     r   __contains__ObjectIdentitySet.__contains__   s    ~~c"dmm33r   c                 X    U R                   R                  U R                  U5      5        g r	   )rR   discardrZ   rX   s     r   r   ObjectIdentitySet.discard   s    dnnS12r   c                 X    U R                   R                  U R                  U5      5        g r	   )rR   addrZ   rX   s     r   r   ObjectIdentitySet.add   s    $..-.r   c                     U R                   R                  U Vs/ s H  o R                  U5      PM     sn5        g s  snf r	   )rR   updaterZ   r   itemsitems      r   r   ObjectIdentitySet.update   s-    uEutnnT2uEFEs   <c                 8    U R                   R                  5         g r	   )rR   clearr   s    r   r   ObjectIdentitySet.clear   s    r   c                     U R                   R                  U Vs/ s H  o R                  U5      PM     sn5      $ s  snf r	   )rR   intersectionrZ   r   s      r   r   ObjectIdentitySet.intersection   s5    }})).34ed^^D!e4
 	
4s   ;c           
          [         R                  U R                  R                  U Vs/ s H  o R	                  U5      PM     sn5      5      $ s  snf r	   )r   r   rR   
differencerZ   r   s      r   r   ObjectIdentitySet.difference   s@     ..MM$$u%MutnnT&:u%MN
 	
%Ms   Ac                 ,    [        U R                  5      $ r	   ri   r   s    r   rk   ObjectIdentitySet.__len__   rm   r   c              #   d   #    [        U R                  5      nU H  nUR                  v   M     g 7fr	   )r}   rR   r   )r   r   rY   s      r   ro   ObjectIdentitySet.__iter__   s'     DMM"C-- s   .0rT   N)r2   r5   r6   r7   r8   r9   r   staticmethodr   rZ   r   r   r   r   r   r   r   rk   ro   r;   r<   r   r   r   r      s\    @]+IH  
+43/G



" r   r   c                   .    \ rS rSrSrSrS rS rS rSr	g)ObjectIdentityWeakSet   z5Like weakref.WeakSet, but compares objects with "is".r<   c                     [        U5      $ r	   ry   rX   s     r   rZ   ObjectIdentityWeakSet._wrap_key   r{   r   c                 B    [        U  Vs/ s H  oPM     sn5      $ s  snf r	   )rj   )r   _s     r   rk   ObjectIdentityWeakSet.__len__   s    t$t!At$%%$s   c              #      #    [        U R                  5      nU H)  nUR                  nUc  U R                  U5        M%  Uv   M+     g 7fr	   )r}   rR   r   r   r   s       r   ro   ObjectIdentityWeakSet.__iter__   s=     DMM"CI S! s   AANr   r<   r   r   r   r      s    ?I/& r   r   )r8   collectionsrB   r   r>   rJ   abcMutableMappingrP   rv   
MutableSetr   r   r<   r   r   <module>r      s    @   1E 1Eh!7 !& !H!B{== !BH &>  ,0 22 0 f -  r   