
    BVhP                         d Z ddlmZmZ ddlZddlmZ  G d d      Z G d de      Z G d	 d
e      Z	 G d dej                        Z G d de      Z G d dej                        Z G d de      Zy)z:Utilities for collecting objects based on "is" comparison.    )AnySetN)collections_abcc                   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     V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/object_identity.py__init__z_ObjectIdentityWrapper.__init__!   s	    DM    c                     | j                   S r   r   r   s    r   	unwrappedz _ObjectIdentityWrapper.unwrapped$   s    ==r   c                 :    t        |t              st        d      y )Nz3Cannot compare wrapped object with unwrapped object)
isinstancer   	TypeErrorr   others     r   _assert_typez#_ObjectIdentityWrapper._assert_type(   s    e34KLL 5r   c                 z    | j                  |       t        | j                        t        |j                        k  S r   r   idr   r   s     r   __lt__z_ObjectIdentityWrapper.__lt__,   -    edmmr%..111r   c                 z    | j                  |       t        | j                        t        |j                        kD  S r   r   r   s     r   __gt__z_ObjectIdentityWrapper.__gt__0   r   r   c                 Z    |y| j                  |       | j                  |j                  u S )NF)r   r   r   s     r   __eq__z_ObjectIdentityWrapper.__eq__4   s+    }e==ENN**r   c                 &    | j                  |       S r   )r#   r   s     r   __ne__z_ObjectIdentityWrapper.__ne__:   s    {{5!!!r   c                 ,    t        | j                        S r   )r   r   r   s    r   __hash__z_ObjectIdentityWrapper.__hash__=   s     dmmr   c                 `    dj                  t        |       j                  | j                        S )Nz<{} wrapping {!r}>)formattype__name__r   r   s    r   __repr__z_ObjectIdentityWrapper.__repr__C   s#    &&tDz':':DMMJJr   N)r+   
__module____qualname____doc__	__slots__r   propertyr   r   r   r!   r#   r%   r'   r,    r   r   r   r      sQ     =))  M22+"Kr   r   c                   2     e Zd ZdZ fdZed        Z xZS )_WeakObjectIdentityWrapperr2   c                 R    t         t        |   t        j                  |             y r   )superr4   r   weakrefref)r   r   	__class__s     r   r   z#_WeakObjectIdentityWrapper.__init__K   s    	
$d4W[[5IJr   c                 "    | j                         S r   r   r   s    r   r   z$_WeakObjectIdentityWrapper.unwrappedN   s    ==?r   )r+   r-   r.   r0   r   r1   r   __classcell__)r9   s   @r   r4   r4   G   s"    )K  r   r4   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
  ```
  r2   c                     | j                   S )z~Returns the referenced object.

    ```python
    x_ref = Reference(x)
    print(x is x_ref.deref())
    ==> True
    ```
    r   r   s    r   derefzReference.derefk   s     ==r   N)r+   r-   r.   r/   r0   r1   r   r?   r2   r   r   r=   r=   S   s    $ ) j)	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   )rB   r   s    r   r   z!ObjectIdentityDictionary.__init__   s	    DMr   c                     t        |      S r   r   r   keys     r   	_wrap_keyz"ObjectIdentityDictionary._wrap_key       !#&&r   c                 >    | j                   | j                  |         S r   rB   rH   rF   s     r   __getitem__z$ObjectIdentityDictionary.__getitem__   s    ==,--r   c                 @    || j                   | j                  |      <   y r   rK   )r   rG   values      r   __setitem__z$ObjectIdentityDictionary.__setitem__   s    ).DMM$..%&r   c                 <    | j                   | j                  |      = y r   rK   rF   s     r   __delitem__z$ObjectIdentityDictionary.__delitem__   s    dnnS)*r   c                 ,    t        | j                        S r   lenrB   r   s    r   __len__z ObjectIdentityDictionary.__len__       t}}r   c              #   J   K   | j                   D ]  }|j                    y wr   )rB   r   rF   s     r   __iter__z!ObjectIdentityDictionary.__iter__   s#     }} MMs   !#c                 2    dt        | j                        z  S )NzObjectIdentityDictionary(%s))reprrB   r   s    r   r,   z!ObjectIdentityDictionary.__repr__   s    )D,???r   N)r+   r-   r.   r/   r0   r   rH   rL   rO   rQ   rU   rX   r,   r2   r   r   rA   rA   w   s9     l)'./+@r   rA   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   r4   rF   s     r   rH   z)ObjectIdentityWeakKeyDictionary._wrap_key       %c**r   c                 >    t        t        | j                              S r   )rT   listrB   r   s    r   rU   z'ObjectIdentityWeakKeyDictionary.__len__   s    tDMM"##r   c              #   z   K   | j                   j                         }|D ]  }|j                  }|| |= |  y wr   )rB   keysr   r   rc   rG   r   s       r   rX   z(ObjectIdentityWeakKeyDictionary.__iter__   sB     ==D --i		Is   9;Nr+   r-   r.   r/   r0   rH   rU   rX   r2   r   r   r\   r\      s    Go)+$r   r\   c                       e Zd ZdZddgZd Zdee   defdZ	dee   def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".rB   r	   c                 D     t         fdt        | D               _        y )Nc              3   @   K   | ]  }j                  |        y wr   )rH   ).0objr   s     r   	<genexpr>z-ObjectIdentitySet.__init__.<locals>.<genexpr>   s     Cs+Cs   )setra   rB   )r   argss   ` r   r   zObjectIdentitySet.__init__   s    CtT{CCDMr   r   returnc                     t        |t              st        S t        |       t        |      kD  ry| j                  D ]  }||vs y yNFT)r   r   NotImplementedrT   rB   r   r   items      r   __le__zObjectIdentitySet.__le__   sH    eS!
4y3u: 	U	 r   c                 z    t        |t              st        S t        |       t        |      k  ry|D ]  }|| vs y yrq   )r   r   rr   rT   rs   s      r   __ge__zObjectIdentitySet.__ge__   sD    eS!
4y3u: 	T	 r   c                 (    t               }| |_        |S r   )rg   rB   )storageresults     r   _from_storagezObjectIdentitySet._from_storage   s     FFOMr   c                     t        |      S r   rE   rF   s     r   rH   zObjectIdentitySet._wrap_key   rI   r   c                 <    | j                  |      | j                  v S r   )rH   rB   rF   s     r   __contains__zObjectIdentitySet.__contains__   s    >>#$--//r   c                 X    | j                   j                  | j                  |             y r   )rB   discardrH   rF   s     r   r   zObjectIdentitySet.discard   s    MM$..-.r   c                 X    | j                   j                  | j                  |             y r   )rB   addrH   rF   s     r   r   zObjectIdentitySet.add   s    MMdnnS)*r   c                 ~    | j                   j                  |D cg c]  }| j                  |       c}       y c c}w r   )rB   updaterH   r   itemsrt   s      r   r   zObjectIdentitySet.update   s+    MM5A4$...ABAs   :c                 8    | j                   j                          y r   )rB   clearr   s    r   r   zObjectIdentitySet.clear   s    MMr   c                 |    | j                   j                  |D cg c]  }| j                  |       c}      S c c}w r   )rB   intersectionrH   r   s      r   r   zObjectIdentitySet.intersection   s.    ==%%&Nt~~d';&NOO&Ns   9c           
          t         j                  | j                  j                  |D cg c]  }| j	                  |       c}            S c c}w r   )rg   r{   rB   
differencerH   r   s      r   r   zObjectIdentitySet.difference   s@    **  5!I4$.."6!IJL L!Is   Ac                 ,    t        | j                        S r   rS   r   s    r   rU   zObjectIdentitySet.__len__   rV   r   c              #   `   K   t        | j                        }|D ]  }|j                    y wr   )ra   rB   r   )r   rc   rG   s      r   rX   zObjectIdentitySet.__iter__   s-     D MMs   ,.N)r+   r-   r.   r/   r0   r   r   r   boolru   rw   staticmethodr{   rH   r~   r   r   r   r   r   r   rU   rX   r2   r   r   rg   rg      s    >=))D#c( t #c( t   
'0/+CPLr   rg   c                   &    e Zd ZdZdZd Zd Zd Zy)ObjectIdentityWeakSetz5Like weakref.WeakSet, but compares objects with "is".r2   c                     t        |      S r   r^   rF   s     r   rH   zObjectIdentityWeakSet._wrap_key   r_   r   c                 >    t        | D cg c]  }| c}      S c c}w r   )rT   )r   _s     r   rU   zObjectIdentityWeakSet.__len__   s    4 a !! s   	c              #      K   t        | j                        }|D ]&  }|j                  }|| j                  |       #| ( y wr   )ra   rB   r   r   rd   s       r   rX   zObjectIdentityWeakSet.__iter__  sC     D --i		Ss   AANre   r2   r   r   r   r      s    =)+"r   r   )r/   typingr   r   r7   tensorflow.python.util.compatr   r   r4   r=   MutableMappingrA   r\   
MutableSetrg   r   r2   r   r   <module>r      s    @   9-K -K`	!7 	!& !H!@== !@H&> ,A22 AH- r   