
    9i.                        S SK Jr  S SKJr  S SKrS SKJrJr  S SKJr  S SK	J
r
  \r/ SQr " S S5      r " S	 S
\R                  5      r " S S\R                  5      r " S S\5      r\r " S S5      rg)    )annotationsN)MappingMutableMappingref)Tensor)TensorWeakRef	WeakIdRefWeakIdKeyDictionaryWeakTensorKeyDictionaryc                  &    \ rS rSrS rS rS rSrg)_IterationGuard   c                $    [        U5      U l        g N)r   weakcontainer)selfr   s     P/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/utils/weak.py__init___IterationGuard.__init__   s     /    c                b    U R                  5       nUb  UR                  R                  U 5        U $ r   )r   
_iteratingadd)r   ws     r   	__enter___IterationGuard.__enter__#   s,     =LLT"r   c                    U R                  5       nUb6  UR                  nUR                  U 5        U(       d  UR                  5         g g g r   )r   r   remove_commit_removals)r   etbr   ss         r   __exit___IterationGuard.__exit__)   sB     =AHHTN""$  r   )r   N)__name__
__module____qualname____firstlineno__r   r   r%   __static_attributes__ r   r   r   r      s    0%r   r   c                  J   ^  \ rS rSrS/rSU 4S jjrU 4S jrS rS rSr	U =r
$ )	r
   K   _idc                D   > [        U5      U l        [        TU ]  X5        g r   )idr/   superr   r   keycallback	__class__s      r   r   WeakIdRef.__init__N   s     c7'r   c                f   > [         TU ]  5       n[        US5      (       a  UR                  5         U$ N_fix_weakrefr2   __call__hasattrr:   r   rr6   s     r   r<   WeakIdRef.__call__W   ,    G1n%%NNr   c                    U R                   $ r   r/   r   s    r   __hash__WeakIdRef.__hash__^       xxr   c                6    U " 5       nU" 5       nUb  Ub  X#L $ XL $ r   r,   r   otherar#   s       r   __eq__WeakIdRef.__eq__a   s*     FG=Q]6M}r   rC   r   r'   r(   r)   r*   	__slots__r   r<   rE   rL   r+   __classcell__r6   s   @r   r
   r
   K   s#    I( r   r
   c                  J   ^  \ rS rSrS/rSU 4S jjrU 4S jrS rS rSr	U =r
$ )	_WeakHashRefw   r/   c                D   > [        U5      U l        [        TU ]  X5        g r   )hashr/   r2   r   r3   s      r   r   _WeakHashRef.__init__z   s     9'r   c                f   > [         TU ]  5       n[        US5      (       a  UR                  5         U$ r9   r;   r>   s     r   r<   _WeakHashRef.__call__   rA   r   c                    U R                   $ r   rC   rD   s    r   rE   _WeakHashRef.__hash__   rG   r   c                ^    U " 5       nU" 5       nUb  Ub  [        U5      [        U5      :H  $ XL $ r   )rV   rI   s       r   rL   _WeakHashRef.__eq__   s6     FG=Q]7d1g%%}r   rC   r   rN   rQ   s   @r   rS   rS   w   s#    I( r   rS   c                      \ rS rSrS\4S jrS rS rS rS r	S r
S	 rS
 rS r\rS rSS jrS rS rS r\rS rS rS rS rSS jrSS jrS rS rS rS rSrg)r      Nc                    0 U l         X l        [        U 5      4S jnX0l        / U l        [        5       U l        SU l        Ub  U R                  U5        g g )Nc                    U" 5       nUb<  UR                   (       a  UR                  R                  U 5        g  UR                  U 	 g g ! [         a     g f = fr   )r   _pending_removalsappenddataKeyError)kselfrefr   s      r   r   ,WeakIdKeyDictionary.__init__.<locals>.remove   sS    9D??**11!4 IIaL   $ s   A 
AAF)	rd   ref_typer   _removerb   setr   
_dirty_lenupdate)r   dictri   r   s       r   r   WeakIdKeyDictionary.__init__   sP    	 !$i 		 !#%KK r   c                    U R                   R                  nU R                  n  U" 5       n X#	 M  ! [         a     g f = f! [         a     Nf = fr   )rb   poprd   
IndexErrorre   )r   rq   dr4   s       r   r    $WeakIdKeyDictionary._commit_removals   sc    
 $$((IIeF   
  s   1 A 
>>
AAc                    U R                   nU R                   Vs/ s H  o"U;   d  M
  UPM     snU l        SU l        g s  snf NF)rd   rb   rl   )r   rs   rf   s      r   _scrub_removals#WeakIdKeyDictionary._scrub_removals   s;    II-1-C-C!N-CAv!-C!N "Os   	>>c                J    SU l         U R                  U R                  U5      	 g NT)rl   rd   ri   r   r4   s     r   __delitem__WeakIdKeyDictionary.__delitem__   s    IIdmmC()r   c                >    U R                   U R                  U5         $ r   )rd   ri   r{   s     r   __getitem__WeakIdKeyDictionary.__getitem__   s    yys+,,r   c                    U R                   (       a!  U R                  (       a  U R                  5         [        U R                  5      [        U R                  5      -
  $ r   )rl   rb   rw   lenrd   rD   s    r   __len__WeakIdKeyDictionary.__len__   s=    ??t55   "499~D$:$: ;;;r   c                P    SU R                   R                   S[        U 5      S S3$ )N<z at z#x>)r6   r'   r1   rD   s    r   __repr__WeakIdKeyDictionary.__repr__   s(    4>>**+44}A>>r   c                R    X R                   U R                  XR                  5      '   g r   )rd   ri   rj   )r   r4   values      r   __setitem__WeakIdKeyDictionary.__setitem__   s    6;		$--\\23r   c                    [        5       n[        U 5         U R                  R                  5        H  u  p#U" 5       nUc  M  X1U'   M     S S S 5        U$ ! , (       d  f       U$ = fr   )r   r   rd   items)r   newr4   r   os        r   copyWeakIdKeyDictionary.copy   sX    !#T""iioo/
E="F 0 #
 
 #"
 
s   (AA
A#c                    SSK Jn  U R                  5       n[        U 5         U R                  R                  5        H  u  pEU" 5       nUc  M  U" XQ5      X6'   M     S S S 5        U$ ! , (       d  f       U$ = f)Nr   )deepcopy)r   r   r6   r   rd   r   )r   memor   r   r4   r   r   s          r   __deepcopy__ WeakIdKeyDictionary.__deepcopy__   sd    !nnT""iioo/
E=%e2CF 0 #
 
 #"
 
s   (A&A&&
A5c                X    U R                   R                  U R                  U5      U5      $ r   )rd   getri   r   r4   defaults      r   r   WeakIdKeyDictionary.get   s     yy}}T]]3/99r   c                b     U R                  U5      nX R                  ;   $ ! [         a     gf = frv   )ri   	TypeErrorrd   )r   r4   wrs      r   __contains__ WeakIdKeyDictionary.__contains__   s7    	s#B YY  		s   ! 
..c              #     #    [        U 5         U R                  R                  5        H  u  pU" 5       nUc  M  X24v   M     S S S 5        g ! , (       d  f       g = f7fr   r   rd   r   )r   r   r   r4   s       r   r   WeakIdKeyDictionary.items   sC     T"!YY__.	d?*$ / #""s!   A(A	A	A
AAc              #     #    [        U 5         U R                   H  nU" 5       nUc  M  Uv   M     S S S 5        g ! , (       d  f       g = f7fr   )r   rd   )r   r   objs      r   keysWeakIdKeyDictionary.keys  s7     T"iid?I   #""s   A;;	A
A	Ac              #     #    [        U 5         U R                  R                  5        H  u  pU" 5       c  M  Uv   M     S S S 5        g ! , (       d  f       g = f7fr   r   )r   r   r   s      r   valuesWeakIdKeyDictionary.values  s<     T"!YY__.	4#K / #""s!   A&A	A	 	A	
AAc                ,    [        U R                  5      $ )aJ  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.

)listrd   rD   s    r   keyrefsWeakIdKeyDictionary.keyrefs  s     DIIr   c                h    SU l          U R                  R                  5       u  pU" 5       nUb  X24$ M+  rz   )rl   rd   popitem)r   r4   r   r   s       r   r   WeakIdKeyDictionary.popitem  s8    **,JCA}x	 r   c                h    SU l         U R                  R                  " U R                  U5      /UQ76 $ rz   )rl   rd   rq   ri   )r   r4   argss      r   rq   WeakIdKeyDictionary.pop'  s*    yy}}T]]3/7$77r   c                l    U R                   R                  U R                  XR                  5      U5      $ r   )rd   
setdefaultri   rj   r   s      r   r   WeakIdKeyDictionary.setdefault+  s+    yy##MM#||,g
 	
r   c                   U R                   nUbX  [        US5      (       d  [        0 5      " U5      nUR                  5        H"  u  pEXSU R	                  X@R
                  5      '   M$     [        U5      (       a  U R                  U5        g g )Nr   )rd   r=   typer   ri   rj   r   rm   )r   rn   kwargsrs   r4   r   s         r   rm   WeakIdKeyDictionary.update0  sl    II4))Bx~"jjl
6;$--\\23 +v;;KK r   c                (    U R                  U5        U $ r   )rm   )r   rJ   s     r   __ior__WeakIdKeyDictionary.__ior__:  s    Er   c                    [        U[        R                  5      (       a#  U R                  5       nUR	                  U5        U$ [
        $ r   )
isinstance_collections_abcr   r   rm   NotImplementedr   rJ   cs      r   __or__WeakIdKeyDictionary.__or__>  s7    e-5566		AHHUOHr   c                    [        U[        R                  5      (       a4  U R                  5       nUR	                  U5        UR	                  U 5        U$ [
        $ r   )r   r   r   r6   rm   r   r   s      r   __ror__WeakIdKeyDictionary.__ror__E  sC    e-5566 AHHUOHHTNHr   c                   [        U[        5      (       d  [        $ U R                  5        VVs0 s H  u  p#[	        U5      U_M     snnUR                  5        VVs0 s H  u  p#[	        U5      U_M     snn:H  $ s  snnf s  snnf r   )r   r   r   r   r1   )r   rJ   rf   vs       r   rL   WeakIdKeyDictionary.__eq__O  sp    %))!!%)ZZ\2\TQ1q\2!&7
!.BqE1H7
 
 	
2 7
s   A;B)rl   r   rb   rj   rd   ri   r   ) r'   r(   r)   r*   r
   r   r    rw   r|   r   r   r   r   r   __copy__r   r   r   r   r   __iter__r   r   r   rq   r   rm   r   r   r   rL   r+   r,   r   r   r   r      s     9 0$ 
*-<?< H	:% H 
 8

 
r   r   c                  4    \ rS rSr% SrS\S'   S	S jrS rSrg)
r	   i[  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                h    [        U[        5      (       d   e[        R                  " U5      U l        g r   )r   r   weakrefr   )r   tensors     r   r   TensorWeakRef.__init__`  s%    &&))));;v&r   c                ~    U R                  5       nUc  U$ [        U[        5      (       d   eUR                  5         U$ r   )r   r   r   r:   )r   outs     r   r<   TensorWeakRef.__call__d  s;    hhj;J#v&&&&
r   r   N)r   r   )	r'   r(   r)   r*   __doc____annotations__r   r<   r+   r,   r   r   r	   r	   [  s    	'r   r	   )
__future__r   collections.abcabcr   r   r   r   r   torchr   WeakRef__all__r   r
   rS   r   r   r	   r,   r   r   <module>r      ss    " *  3   % %d' 'X7;; D{
. {
~ .  r   