
    Ph&                        d dl mZ d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ eZg dZ G d d	ej                        Z G d
 de      ZeZ G d d      Zy)    )annotationsN)ref)_IterationGuard)MutableMappingMapping)Tensor)TensorWeakRef	WeakIdRefWeakIdKeyDictionaryWeakTensorKeyDictionaryc                  <     e Zd ZdgZd fd	Z fdZd Zd Z xZS )r
   _idc                F    t        |      | _        t        |   ||       y N)idr   super__init__)selfkeycallback	__class__s      [C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/utils/weak.pyr   zWeakIdRef.__init__-   s     c7h'    c                \    t         |          }t        |d      r|j                          |S )N_fix_weakref)r   __call__hasattrr   )r   rr   s     r   r   zWeakIdRef.__call__6   s)    G1n%NNr   c                    | j                   S r   )r   r   s    r   __hash__zWeakIdRef.__hash__=   s    xxr   c                6     |        } |       }||||u S | |u S r    )r   otherabs       r   __eq__zWeakIdRef.__eq__@   s.     FG=Q]6Mu}r   r   )	__name__
__module____qualname__	__slots__r   r   r!   r'   __classcell__)r   s   @r   r
   r
   *   s    I(r   r
   c                      e Zd ZU ded<   ddZd Zd Zd Zd Zd	 Z	d
 Z
d Zd ZeZd ZddZd Zd Zd ZeZd Zd Zd Zd ZddZddZd Zd Zd Zd Zy)r   zdict[WeakIdRef, object]dataNc                    i | _         t        |       fd}|| _        g | _        t	               | _        d| _        || j                  |       y y )Nc                     |       }|7|j                   r|j                  j                  |        y 	 |j                  | = y y # t        $ r Y y w xY wr   )
_iterating_pending_removalsappendr.   KeyError)kselfrefr   s      r   removez,WeakIdKeyDictionary.__init__.<locals>.removeZ   sS    9D??**11!4 IIaL   $ s   A 	AAF)r.   r   _remover2   setr1   
_dirty_lenupdate)r   dictr7   s      r   r   zWeakIdKeyDictionary.__init__W   sM    	!$i 		 !#%KK r   c                    | j                   j                  }| j                  }	 	  |       }	 ||= # t        $ r Y y w xY w# t        $ r Y w xY wr   )r2   popr.   
IndexErrorr4   )r   r>   dr   s       r   _commit_removalsz$WeakIdKeyDictionary._commit_removalsl   se    
 $$((IIecF   
  s   1 A  	== 	AAc                |    | j                   }| j                  D cg c]	  }||v s| c}| _        d| _        y c c}w NF)r.   r2   r:   )r   r@   r5   s      r   _scrub_removalsz#WeakIdKeyDictionary._scrub_removals~   s=    II-1-C-C!N-CqAv!-C!N "Os   	99c                >    d| _         | j                  t        |      = y NT)r:   r.   r
   r   r   s     r   __delitem__zWeakIdKeyDictionary.__delitem__   s    IIin%r   c                2    | j                   t        |         S r   )r.   r
   rG   s     r   __getitem__zWeakIdKeyDictionary.__getitem__   s    yy3((r   c                    | j                   r| j                  r| j                          t        | j                        t        | j                        z
  S r   )r:   r2   rD   lenr.   r    s    r   __len__zWeakIdKeyDictionary.__len__   s=    ??t55   "499~D$:$: ;;;r   c                P    d| j                   j                   dt        |       ddS )N<z at z#x>)r   r(   r   r    s    r   __repr__zWeakIdKeyDictionary.__repr__   s(    4>>**+44}A>>r   c                J    || j                   t        || j                        <   y r   )r.   r
   r8   )r   r   values      r   __setitem__zWeakIdKeyDictionary.__setitem__   s    27		)C./r   c                    t               }t        |       5  | j                  j                         D ]  \  }} |       }||||<    	 d d d        |S # 1 sw Y   |S xY wr   )r   r   r.   items)r   newr   rS   os        r   copyzWeakIdKeyDictionary.copy   sY    !#T""iioo/
UE="CF 0 #
 
 #
 
s   *AAAc                    ddl m} | j                         }t        |       5  | j                  j                         D ]  \  }} |       }| |||      ||<    	 d d d        |S # 1 sw Y   |S xY w)Nr   )deepcopy)rY   r[   r   r   r.   rV   )r   memor[   rW   r   rS   rX   s          r   __deepcopy__z WeakIdKeyDictionary.__deepcopy__   sg    !nnT""iioo/
UE=%eT2CF 0 #
 
 #
 
s   *A&A&&A0c                L    | j                   j                  t        |      |      S r   )r.   getr
   r   r   defaults      r   r_   zWeakIdKeyDictionary.get   s    yy}}Ys^W55r   c                T    	 t        |      }|| j                  v S # t        $ r Y yw xY wrC   )r
   	TypeErrorr.   )r   r   wrs      r   __contains__z WeakIdKeyDictionary.__contains__   s4    	3B TYY  		s    	''c              #     K   t        |       5  | j                  j                         D ]  \  }} |       }|||f  	 d d d        y # 1 sw Y   y xY wwr   r   r.   rV   )r   rd   rS   r   s       r   rV   zWeakIdKeyDictionary.items   sH     T"!YY__.	Ed?u*$ / #""s!   A*AA	AAAc              #     K   t        |       5  | j                  D ]  } |       }||  	 d d d        y # 1 sw Y   y xY wwr   )r   r.   )r   rd   objs      r   keyszWeakIdKeyDictionary.keys   s8     T"iid?I   #""s   A88	AAAc              #     K   t        |       5  | j                  j                         D ]  \  }} |       |  	 d d d        y # 1 sw Y   y xY wwr   rg   )r   rd   rS   s      r   valueszWeakIdKeyDictionary.values   s?     T"!YY__.	E4#K / #""s    A(AA	AAAc                ,    t        | j                        S )az  Return a list of weak references to the keys.

        The references are not guaranteed to be 'live' at the time
        they are used, so the result of calling the references needs
        to be checked before being used.  This can be used to avoid
        creating references that will cause the garbage collector to
        keep the keys around longer than needed.

        )listr.   r    s    r   keyrefszWeakIdKeyDictionary.keyrefs   s     DIIr   c                h    d| _         	 | j                  j                         \  }} |       }|||fS +rF   )r:   r.   popitem)r   r   rS   rX   s       r   rq   zWeakIdKeyDictionary.popitem   s<    **,JCA}%x	 r   c                \    d| _          | j                  j                  t        |      g| S rF   )r:   r.   r>   r
   )r   r   argss      r   r>   zWeakIdKeyDictionary.pop   s'    tyy}}Ys^3d33r   c                b    | j                   j                  t        || j                        |      S r   )r.   
setdefaultr
   r8   r`   s      r   ru   zWeakIdKeyDictionary.setdefault   s$    yy##Ic4<<$@'JJr   c                    | j                   }|Nt        |d      s t        i       |      }|j                         D ]  \  }}||t	        || j
                        <     t        |      r| j                  |       y y )NrV   )r.   r   typerV   r
   r8   rL   r;   )r   r<   kwargsr@   r   rS   s         r   r;   zWeakIdKeyDictionary.update   sk    II4)tBx~"jjl
U27)C./ +v;KK r   c                (    | j                  |       | S r   )r;   )r   r$   s     r   __ior__zWeakIdKeyDictionary.__ior__   s    Er   c                    t        |t        j                        r#| j                         }|j	                  |       |S t
        S r   )
isinstance_collections_abcr   rY   r;   NotImplementedr   r$   cs      r   __or__zWeakIdKeyDictionary.__or__   s4    e-556		AHHUOHr   c                    t        |t        j                        r4| j                         }|j	                  |       |j	                  |        |S t
        S r   )r|   r}   r   r   r;   r~   r   s      r   __ror__zWeakIdKeyDictionary.__ror__   s@    e-556 AHHUOHHTNHr   c                    t        |t              st        S | j                         D ci c]  \  }}t	        |      | c}}|j                         D ci c]  \  }}t	        |      | c}}k(  S c c}}w c c}}w r   )r|   r   r~   rV   r   )r   r$   r5   vs       r   r'   zWeakIdKeyDictionary.__eq__  se    %)!!%)ZZ\2\TQ1q\2EKKM6ZMDAqr!uaxM6ZZZ26Zs   A2A8r   )r(   r)   r*   __annotations__r   rA   rD   rH   rJ   rM   rQ   rT   rY   __copy__r]   r_   re   rV   rj   __iter__rl   ro   rq   r>   ru   r;   rz   r   r   r'   r#   r   r   r   r   T   s    
!!*$ 
&)<?8 H6% H 
 4K [r   r   c                  *    e Zd ZU dZded<   ddZd Zy)r	   zuWrapper around a weak ref of a Tensor that handles the _fix_weakref() call required when unwrapping a Tensor weakref.zWeakRef[Tensor]r   c                \    t        |t              sJ t        j                  |      | _        y r   )r|   r   weakrefr   )r   tensors     r   r   zTensorWeakRef.__init__  s"    &&)));;v&r   c                r    | j                         }||S t        |t              sJ |j                          |S r   )r   r|   r   r   )r   outs     r   r   zTensorWeakRef.__call__  s8    hhj;J#v&&&
r   N)r   r   )r(   r)   r*   __doc__r   r   r   r#   r   r   r	   r	     s    	'r   r	   )
__future__r   r   r   _weakrefsetr   collections.abcr   r   torchr   abcr}   WeakRef__all__r
   r   r   r	   r#   r   r   <module>r      s]    "   ' 3  *  [8' 'Tu[. u[p .  r   