
    iri/                        d dl mZ d dlmZ d dl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          Z G d	 d
ej                  Z G d dej                  Z G d de          ZeZ G d d          ZdS )    )annotationsN)MappingMutableMapping)ref)Tensor)TensorWeakRef	WeakIdRefWeakIdKeyDictionaryWeakTensorKeyDictionaryc                  "    e Zd ZddZd Zd ZdS )_IterationGuardreturnNonec                .    t          |          | _        d S N)r   weakcontainer)selfr   s     h/var/www/html/bestrading.cuttalo.com/models/btc_v9/venv/lib/python3.11/site-packages/torch/utils/weak.py__init__z_IterationGuard.__init__   s     //    c                f    |                                  }||j                            |            | S r   )r   
_iteratingadd)r   ws     r   	__enter__z_IterationGuard.__enter__#   s3      =LT"""r   c                    |                                  }|4|j        }|                    |            |s|                                 d S d S d S r   )r   r   remove_commit_removals)r   etbr   ss         r   __exit__z_IterationGuard.__exit__)   s_      =AHHTNNN %""$$$$$	 =% %r   Nr   r   )__name__
__module____qualname__r   r   r#    r   r   r   r      sF        0 0 0 0  % % % % %r   r   c                  >     e Zd ZdgZd	d
 fdZ fdZd Zd Z xZS )r	   _idNr   r   c                t    t          |          | _        t                                          ||           d S r   )idr*   superr   r   keycallback	__class__s      r   r   zWeakIdRef.__init__N   s2     c77h'''''r   c                    t                                                      }t          |d          r|                                 |S N_fix_weakrefr-   __call__hasattrr4   r   rr1   s     r   r6   zWeakIdRef.__call__W   ?    GG1n%% 	NNr   c                    | j         S r   r*   r   s    r   __hash__zWeakIdRef.__hash__^   	    xr   c                B     |             } |            }||||u S | |u S r   r(   r   otherar!   s       r   __eq__zWeakIdRef.__eq__a   s6     DFFEGG=Q]6Mu}r   r   r$   	r%   r&   r'   	__slots__r   r6   r>   rD   __classcell__r1   s   @r   r	   r	   K   s        I( ( ( ( ( ( (            r   r	   c                  >     e Zd ZdgZd	d
 fdZ fdZd Zd Z xZS )_WeakHashRefr*   Nr   r   c                t    t          |          | _        t                                          ||           d S r   )hashr*   r-   r   r.   s      r   r   z_WeakHashRef.__init__z   s2     99h'''''r   c                    t                                                      }t          |d          r|                                 |S r3   r5   r8   s     r   r6   z_WeakHashRef.__call__   r:   r   c                    | j         S r   r<   r=   s    r   r>   z_WeakHashRef.__hash__   r?   r   c                z     |             } |            }|"| t          |          t          |          k    S | |u S r   )rL   rA   s       r   rD   z_WeakHashRef.__eq__   sD     DFFEGG=Q]77d1gg%%u}r   r   r$   rE   rH   s   @r   rJ   rJ   w   s        I( ( ( ( ( ( (            r   rJ   c                      e Zd ZdefddZddZddZddZd Zd d
Z	d!dZ
ddZd ZeZd Zd"dZd#dZd Zd ZeZd Zd Zd Zd Zd"dZd"ddZd Zd Zd Zd ZdS )$r
   Nr   r   c                    i | _         || _        t          |           fdd}|| _        g | _        t                      | _        d| _        ||                     |           d S d S )Nr   r   c                     |            }|?|j         r|j                            |            d S 	 |j        | = d S # t          $ r Y d S w xY wd S r   )r   _pending_removalsappenddataKeyError)kselfrefr   s      r   r   z,WeakIdKeyDictionary.__init__.<locals>.remove   sv    799D? *11!44444 IaLLL#     s   ; 
A	A	Fr$   )	rU   ref_typer   _removerS   setr   
_dirty_lenupdate)r   dictrY   r   s       r   r   zWeakIdKeyDictionary.__init__   s{    	 !$ii 		 		 		 		 		 !#%%KK r   c                    | j         j        }| j        }	 	  |            }n# t          $ r Y d S w xY w	 ||= n# t          $ r Y nw xY w3r   )rS   poprU   
IndexErrorrV   )r   r`   dr/   s       r   r   z$WeakIdKeyDictionary._commit_removals   s    
 $(I		cee   cFF   		s   
! 
//7 
AAc                T    | j         fd| j        D             | _        d| _        d S )Nc                    g | ]}|v |	S r(   r(   ).0rW   rb   s     r   
<listcomp>z7WeakIdKeyDictionary._scrub_removals.<locals>.<listcomp>   s    !N!N!NqAvv!vvvr   F)rU   rS   r\   )r   rb   s    @r   _scrub_removalsz#WeakIdKeyDictionary._scrub_removals   s4    I!N!N!N!NT-C!N!N!Nr   c                J    d| _         | j        |                     |          = d S NT)r\   rU   rY   r   r/   s     r   __delitem__zWeakIdKeyDictionary.__delitem__   s%    IdmmC(()))r   c                B    | j         |                     |                   S r   )rU   rY   rj   s     r   __getitem__zWeakIdKeyDictionary.__getitem__   s    ys++,,r   intc                    | j         r| j        r|                                  t          | j                  t          | j                  z
  S r   )r\   rS   rg   lenrU   r=   s    r   __len__zWeakIdKeyDictionary.__len__   sH    ? 	#t5 	#   """49~~D$: ; ;;;r   strc                D    d| j         j         dt          |           ddS )N<z at z#x>)r1   r%   r,   r=   s    r   __repr__zWeakIdKeyDictionary.__repr__   s)    >4>*>>4>>>>>r   c                L    || j         |                     || j                  <   d S r   )rU   rY   rZ   )r   r/   values      r   __setitem__zWeakIdKeyDictionary.__setitem__   s$    6;	$--T\22333r   c                    t                      }t          |           5  | j                                        D ]\  }} |            }||||<   	 d d d            n# 1 swxY w Y   |S r   )r
   r   rU   items)r   newr/   rx   os        r   copyzWeakIdKeyDictionary.copy   s    !##T"" 	# 	#"ioo// # #
UCEE="CF#	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#
 
s   1AA #A c                    ddl m} |                                 }t          |           5  | j                                        D ] \  }} |            }| |||          ||<   !	 d d d            n# 1 swxY w Y   |S )Nr   )deepcopy)r~   r   r1   r   rU   r{   )r   memor   r|   r/   rx   r}   s          r   __deepcopy__z WeakIdKeyDictionary.__deepcopy__   s    !!!!!!nnT"" 	3 	3"ioo// 3 3
UCEE=%XeT22CF3	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3
 
s   ;A22A69A6c                ^    | j                             |                     |          |          S r   )rU   getrY   r   r/   defaults      r   r   zWeakIdKeyDictionary.get   s$    y}}T]]3//999r   boolc                d    	 |                      |          }n# t          $ r Y dS w xY w|| j        v S )NF)rY   	TypeErrorrU   )r   r/   wrs      r   __contains__z WeakIdKeyDictionary.__contains__   sH    	s##BB 	 	 	55	TYs    
&&c              #     K   t          |           5  | j                                        D ]\  }} |            }|||fV  	 d d d            d S # 1 swxY w Y   d S r   r   rU   r{   )r   r   rx   r/   s       r   r{   zWeakIdKeyDictionary.items   s      T"" 	% 	%!Y__.. % %	Ebdd?u*$$$%	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   2AAAc              #     K   t          |           5  | j        D ]} |            }||V  	 d d d            d S # 1 swxY w Y   d S r   )r   rU   )r   r   objs      r   keyszWeakIdKeyDictionary.keys  s      T"" 	 	i  bdd?III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ;??c              #     K   t          |           5  | j                                        D ]\  }} |            |V  	 d d d            d S # 1 swxY w Y   d S r   r   )r   r   rx   s      r   valueszWeakIdKeyDictionary.values  s      T"" 	  	 !Y__..    	E244#KKK 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   .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.

        )listrU   r=   s    r   keyrefszWeakIdKeyDictionary.keyrefs  s     DIr   c                l    d| _         	 | j                                        \  }} |            }|||fS -ri   )r\   rU   popitem)r   r/   rx   r}   s       r   r   zWeakIdKeyDictionary.popitem  sC    	 **,,JCA}%x		 r   c                \    d| _          | j        j        |                     |          g|R  S ri   )r\   rU   r`   rY   )r   r/   argss      r   r`   zWeakIdKeyDictionary.pop(  s1    ty}T]]3//7$7777r   c                j    | j                             |                     || j                  |          S r   )rU   
setdefaultrY   rZ   r   s      r   r   zWeakIdKeyDictionary.setdefault-  s1    y##MM#t|,,g
 
 	
r   c                
   | j         }|`t          |d          s t          i           |          }|                                D ]#\  }}|||                     || j                  <   $|r|                     |           d S d S )Nr{   )rU   r7   typer{   rY   rZ   r]   )r   r^   kwargsrb   r/   rx   s         r   r]   zWeakIdKeyDictionary.update2  s    I4)) &tBxx~~"jjll < <
U6;$--T\2233 	 KK	  	 r   c                0    |                      |           | S r   )r]   r   rB   s     r   __ior__zWeakIdKeyDictionary.__ior__<  s    Er   c                    t          |t          j                  r+|                                 }|                    |           |S t
          S r   )
isinstance_collections_abcr   r~   r]   NotImplementedr   rB   cs      r   __or__zWeakIdKeyDictionary.__or__@  s?    e-566 			AHHUOOOHr   c                    t          |t          j                  r@|                                 }|                    |           |                    |            |S t
          S r   )r   r   r   r1   r]   r   r   s      r   __ror__zWeakIdKeyDictionary.__ror__G  sP    e-566 	  AHHUOOOHHTNNNHr   c                    t          |t                    st          S d |                                 D             d |                                D             k    S )Nc                4    i | ]\  }}t          |          |S r(   r,   re   rW   vs      r   
<dictcomp>z.WeakIdKeyDictionary.__eq__.<locals>.<dictcomp>T  s$    222TQ1q222r   c                4    i | ]\  }}t          |          |S r(   r   r   s      r   r   z.WeakIdKeyDictionary.__eq__.<locals>.<dictcomp>T  s1     7
 7
 7
ABqEE17
 7
 7
r   )r   r   r   r{   r   s     r   rD   zWeakIdKeyDictionary.__eq__Q  sa    %)) 	"!!22TZZ\\222 7
 7
!&7
 7
 7
 
 	
r   r$   )r   rn   )r   rr   r   )r   r   )r%   r&   r'   r	   r   r   rg   rk   rm   rq   rv   ry   r~   __copy__r   r   r   r{   r   __iter__r   r   r   r`   r   r]   r   r   r   rD   r(   r   r   r
   r
      s        9     0   $       
* * * *- - -< < < <? ? ? ?< < < <   H	 	 	: : : :   % % %   H     
 
 
     8 8 8

 
 
 

               
 
 
 
 
r   r
   c                  ,    e Zd ZU dZded<   ddZd	 Zd
S )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   tensorr   r   r   c                    t          |t                    s t          dt          |           d          t	          j        |          | _        d S Nzexpected torch.Tensor, got .)r   r   AssertionErrorr   weakrefr   )r   r   s     r   r   zTensorWeakRef.__init__b  sJ    &&)) 	P !NtF||!N!N!NOOO;v&&r   c                    |                                  }||S t          |t                    s t          dt	          |           d          |                                 |S r   )r   r   r   r   r   r4   )r   outs     r   r6   zTensorWeakRef.__call__g  sc    hhjj;J#v&& 	M !KtCyy!K!K!KLLL
r   N)r   r   r   r   )r%   r&   r'   __doc____annotations__r   r6   r(   r   r   r   r   ]  sK         ' ' ' '
    r   r   )
__future__r   collections.abcabcr   r   r   r   r   torchr   WeakRef__all__r   r	   rJ   r
   r   r   r(   r   r   <module>r      sv   " " " " " " * * * * * *  3 3 3 3 3 3 3 3               % % % % % % % %d' ' ' ' ' ' ' 'X    7;   D}
 }
 }
 }
 }
. }
 }
 }
B .          r   