
    '}h5                        U d dl Z d dlZddlmZmZmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZ d dlZd dlZd dlmZ d dlZd dlZd dlZ	 d dlZdZ ej8                         Zi Zeeej@                  f   e!d<    ed	d
      Z" G d d      Z#d Z$ G d dejJ                  jL                  e#      Z'd Z(ee#_)        ee#_*        ee#_+         ed      d        Z, ed      d        Z-d Z.d Z/da0d Z1d Z2d'dZ3d Z4de5fdZ6 G d d      Z7ejp                  e7jR                  _8        ejp                  e7jT                  _8        ejp                  e7jV                  _8         G d  d!e)      Z9 G d" d#e7e9$      Z:d%e5fd&Z;y# e$ r dZY 3w xY w)(    N   )_type_cuda_hpu)Storage)castAnyDictOptionalTypeVarTypeUnion)	lru_cacheT_share_memory_mapTz!Union[_StorageBase, TypedStorage])boundc                   
    e Zd ZU eed<   dZeed<   dZeed<   ej                  ed<   d Z
defdZd	 Zd
 ZdZdedee   defdZdefdZdefdZdefdZd[dee   dedefdZd[defdZd[defdZdefdZdefdZdefdZdefdZd Zd Zede e   dedefd       Z!ede e   dedefd       Z"ede e   defd        Z#eddd!de e   defd"       Z$ede e   defd#       Z%ede e   defd$       Z&defd%Z'd& Z(defd'Z)defd(Z*d) Z+d* Z,d+ Z-defd,Z.ede e   defd-       Z/d. Z0ed/        Z1e2d0        Z3e2d1        Z4edefd2       Z5edefd3       Z6d4 Z7dee   fd5Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z> fd<Z?d= Z@d> ZAd? ZBd@ ZCdA ZDdB ZEdC ZFdD ZGdE ZHdF ZdG ZIdH ZJdI ZKdJ ZdK ZLdL ZMdM ZNdN ZOdO ZPdP ZQdQ ZRd\deSeej                  f   fdRZTd\deSeej                  f   fdSZUdT ZVedUdVdW       ZWdX ZXdY ZY xZZS )]_StorageBase_cdataF	is_sparseis_sparse_csrdevicec                      y N selfargskwargss      L/var/www/html/test/engine/venv/lib/python3.12/site-packages/torch/storage.py__init__z_StorageBase.__init__           returnc                      y r   r   r   s    r    __len__z_StorageBase.__len__   r"   r#   c                      y r   r   r   idxs     r    __getitem__z_StorageBase.__getitem__   r"   r#   c                      y r   r   r   s      r    __setitem__z_StorageBase.__setitem__    r"   r#   Nsourcenon_blockingc                      y r   r   r   r.   r/   s      r    copy_z_StorageBase.copy_!   r"   r#   c                      y r   r   r&   s    r    newz_StorageBase.new"   r"   r#   c                      y r   r   r&   s    r    nbytesz_StorageBase.nbytes#   r"   r#   c                 "    | j                         S r   )r6   r&   s    r    sizez_StorageBase.size%   s    {{}r#   dtypec                      y r   r   )r   r9   r/   s      r    typez_StorageBase.type(   r"   r#   c                      y r   r   r   r   r/   r   s       r    cudaz_StorageBase.cuda)   r"   r#   c                      y r   r   r=   s       r    hpuz_StorageBase.hpu*   r"   r#   c                      y r   r   r&   s    r    element_sizez_StorageBase.element_size+   r"   r#   c                 .    | j                   j                  S r   )r   indexr&   s    r    
get_devicez_StorageBase.get_device-   s    {{   r#   c                      y r   r   r&   s    r    data_ptrz_StorageBase.data_ptr0   r"   r#   c                      y r   r   r&   s    r    	resizablez_StorageBase.resizable2   r"   r#   c                      y r   r   r   s      r    _share_filename_cpu_z!_StorageBase._share_filename_cpu_5   r"   r#   c                      y r   r   r   s      r    _share_fd_cpu_z_StorageBase._share_fd_cpu_6   r"   r#   clsr8   c                      y r   r   rN   r8   s     r    _new_using_filename_cpuz$_StorageBase._new_using_filename_cpu7   s    ?Br#   c                      y r   r   rP   s     r    _new_using_fd_cpuz_StorageBase._new_using_fd_cpu9       9<r#   c                      y r   r   rN   r   r   s      r    from_bufferz_StorageBase.from_buffer;   rT   r#   )r   r9   c                     y r   r   )rN   managerobjr8   r   r9   s         r    _new_shared_filename_cpuz%_StorageBase._new_shared_filename_cpu=   s    ehr#   c                      y r   r   rV   s      r    _release_ipc_counter_cudaz&_StorageBase._release_ipc_counter_cuda?   s    GJr#   c                      y r   r   rV   s      r    _new_with_weak_ptrz_StorageBase._new_with_weak_ptrA   s    @Cr#   c                      y r   r   r&   s    r    _shared_decrefz_StorageBase._shared_decrefC   r"   r#   c                      y r   r   r   s      r    _write_filez_StorageBase._write_fileD   r"   r#   c                      y r   r   r   r8   s     r    resize_z_StorageBase.resize_E   r"   r#   c                      y r   r   r   s      r    	_weak_refz_StorageBase._weak_refF   r"   r#   c                      y r   r   r   s      r    _set_from_filez_StorageBase._set_from_fileG   r"   r#   c                      y r   r   r   s      r    
_set_cdataz_StorageBase._set_cdataH   r"   r#   c                      y r   r   r   s      r    _share_cuda_z_StorageBase._share_cuda_I   r"   r#   c                      y r   r   r&   s    r    	is_sharedz_StorageBase.is_sharedJ   r"   r#   c                      y r   r   rV   s      r    _new_shared_cudaz_StorageBase._new_shared_cudaK   s    >Ar#   c                      y r   r   r   s      r    _shared_increfz_StorageBase._shared_increfM   r"   r#   c                      y r   r   rV   s      r    _free_weak_refz_StorageBase._free_weak_refN   s    .1r#   c                      y r   r   r&   s    r    is_cudaz_StorageBase.is_cudaP   s    r#   c                      y r   r   r&   s    r    is_hpuz_StorageBase.is_hpuR   s    r#   c                      y r   r   )rN   filenamesharedr6   s       r    	from_filez_StorageBase.from_fileT   s    7:r#   c                      y r   r   rV   s      r    _expiredz_StorageBase._expiredV   s    -0r#   c                      y r   r   r   s      r    	_byteswapz_StorageBase._byteswapX   r"   r#   c                      y r   r   r   s      r    _get_filenamez_StorageBase._get_filenameY   r"   r#   c                     dt        j                          d j                   dt                d} j                  j                  dk(  rd|z   S ddj                   fd	t         j                               D              z   }|d
z   |z   S )N[z(device=
) of size ]meta...
 
 c              3   :   K   | ]  }t        |           y wr   str.0ir   s     r    	<genexpr>z'_StorageBase.__str__.<locals>.<genexpr>b        'QDG'Q   
)torchtypenamer   lenr;   joinranger8   r   info_strdata_strs   `  r    __str__z_StorageBase.__str__[   s    t$%Xdkk] ;4yk$ 	 ;;v%X%%UZZ'QeDIIK>P'QQQHd?X--r#   c                     t        |       S r   r   r&   s    r    __repr__z_StorageBase.__repr__e   s    4yr#   c                 Z     t         fdt         j                               D              S )Nc              3   (   K   | ]	  }|     y wr   r   r   s     r    r   z(_StorageBase.__iter__.<locals>.<genexpr>i        8DG8   )iterr   r8   r&   s   `r    __iter__z_StorageBase.__iter__h   s    8U499;%7888r#   c                 "    | j                         S r   )cloner&   s    r    __copy__z_StorageBase.__copy__k   s    zz|r#   c                     |j                  di       }| j                  |v r|| j                     S | j                         }||| j                  <   |S )Nr   )
setdefaultr   r   )r   memonew_storages      r    __deepcopy__z_StorageBase.__deepcopy__n   sL    w+;;$$$jjl'T[[r#   c                     t        j                         }t        j                  | |d       t        |j                         ffS NF)_use_new_zipfile_serializationioBytesIOr   save_load_from_bytesgetvaluer   bs     r    
__reduce__z_StorageBase.__reduce__v   0    JJL

45A 1::</22r#   c                 B    t         |          | j                         z   S r   )super
__sizeof__r8   r   	__class__s    r    r   z_StorageBase.__sizeof__{   s    w!#diik11r#   c                 v     t        |       | j                         | j                        j                  |       S )Return a copy of this storage.r   )r;   r6   r   r2   r&   s    r    r   z_StorageBase.clone~   s*    tDz$++-<BB4HHr#   c                     t        |       S z6Return a list containing the elements of this storage.)listr&   s    r    tolistz_StorageBase.tolist   s    Dzr#   c                     | j                   j                  dk7  r3t        j                  | j	                               j                  | d      S | S )AReturn a CPU copy of this storage if it's not already on the CPU.cpuFr   r;   r   UntypedStorager8   r2   r&   s    r    r   z_StorageBase.cpu   s=    ;;u$''		4::4GGKr#   c                     | j                   j                  dk7  r5t        j                  | j	                         d      j                  | d      S | S )zAReturn a MPS copy of this storage if it's not already on the MPS.mpsr   Fr   r&   s    r    r   z_StorageBase.mps   s?    ;;u$''		EBHHuUUKr#   c                    t        |t        j                        st        dt	        |             t        j
                  g t        j                  | j                        j                  t        t        |             j                  |      j                         }|j                         | j                         k(  r|j                         }|S Nz*Argument 'dtype' must be torch.dtype, not r9   r   )
isinstancer   r9   	TypeErrorr;   tensoruint8r   set_r   r   to_typed_storagerG   r   r   r9   storages      r    _toz_StorageBase._to   s    %-HeVWW,,rT[[INNtT[]aObcffglm||~0mmoGr#   c                 @    | j                  t        j                        S z"Casts this storage to double type.)r   r   doubler&   s    r    r   z_StorageBase.double       xx%%r#   c                 @    | j                  t        j                        S z!Casts this storage to float type.)r   r   floatr&   s    r    r   z_StorageBase.float       xx$$r#   c                 @    | j                  t        j                        S z Casts this storage to half type.)r   r   halfr&   s    r    r   z_StorageBase.half       xx

##r#   c                 @    | j                  t        j                        S z Casts this storage to long type.)r   r   longr&   s    r    r   z_StorageBase.long   r   r#   c                 @    | j                  t        j                        S zCasts this storage to int type.)r   r   intr&   s    r    r   z_StorageBase.int   s    xx		""r#   c                 @    | j                  t        j                        S z!Casts this storage to short type.)r   r   shortr&   s    r    r   z_StorageBase.short   r   r#   c                 @    | j                  t        j                        S z Casts this storage to char type.)r   r   int8r&   s    r    charz_StorageBase.char   r   r#   c                 @    | j                  t        j                        S z Casts this storage to byte type.)r   r   r   r&   s    r    bytez_StorageBase.byte   r   r#   c                 @    | j                  t        j                        S z Casts this storage to bool type.)r   r   boolr&   s    r    r   z_StorageBase.bool   r   r#   c                 @    | j                  t        j                        S z$Casts this storage to bfloat16 type.)r   r   bfloat16r&   s    r    r   z_StorageBase.bfloat16   s    xx''r#   c                 @    | j                  t        j                        S z*Casts this storage to complex double type.)r   r   cdoubler&   s    r    complex_doublez_StorageBase.complex_double   s    xx&&r#   c                 @    | j                  t        j                        S z)Casts this storage to complex float type.)r   r   cfloatr&   s    r    complex_floatz_StorageBase.complex_float   r   r#   c                 @    | j                  t        j                        S z&Casts this storage to float8_e5m2 type)r   r   float8_e5m2r&   s    r    r	  z_StorageBase.float8_e5m2   s    xx))**r#   c                 @    | j                  t        j                        S z(Casts this storage to float8_e4m3fn type)r   r   float8_e4m3fnr&   s    r    r  z_StorageBase.float8_e4m3fn   s    xx++,,r#   c                 @    | j                  t        j                        S z*Casts this storage to float8_e5m2fnuz type)r   r   float8_e5m2fnuzr&   s    r    r  z_StorageBase.float8_e5m2fnuz       xx--..r#   c                 @    | j                  t        j                        S z*Casts this storage to float8_e4m3fnuz type)r   r   float8_e4m3fnuzr&   s    r    r  z_StorageBase.float8_e4m3fnuz   r  r#   c                     t        j                  g t         j                  | j                        j	                  t        t        |             j                  |      S )zDetermine whether the CPU storage is already pinned on device.

        Args:
            device (str or torch.device): The device to pin memory on. Default: ``'cuda'``.

        Returns:
            A boolean variable.
        r   )r   r   r   r   r   r   r   	is_pinnedr   r   s     r    r  z_StorageBase.is_pinned   s@     ||Bekk$++FKK$!!*6!2	3r#   c                 F   | j                   j                  dk7  rt        d| j                          d      t        j                  g t        j
                  | j                         j                  t        t        |             j                  |      }|j                         S )zCopy the CPU storage to pinned memory, if it's not already pinned.

        Args:
            device (str or torch.device): The device to pin memory on. Default: ``'cuda'``.

        Returns:
            A pinned CPU storage.
        r   zcannot pin 'z' only CPU memory can be pinnedr   )r   r;   r   r   r   r   r   r   r   
pin_memoryuntyped_storage)r   r   pinned_tensors      r    r  z_StorageBase.pin_memory   s|     ;;u$l499;-7VWXXRu{{4;;OTT$!!+F!3 	,,..r#   c                     ddl m} | j                  j                  dt        j
                  j                         fv r	 | S  |       dk(  r| j                          | S | j                          | S ).See :meth:`torch.UntypedStorage.share_memory_`r   get_sharing_strategyr>   file_system)	torch.multiprocessingr  r   r;   r   _C_get_privateuse1_backend_namerK   rM   )r   r  s     r    share_memory_z_StorageBase.share_memory_   sf    >;;(N(N(PQQ
 	 "#}4%%'  !r#   r   r   c                    ddl m} t        j                  |      }|j                  dt        j
                  j                         dfv r
 | ||      S  |       dk(  r| j                  |      S | j                  |      S )>Create a new storage in shared memory with the same data type.r   r  r>   r@   r   r  )	r   r  r   r   r;   r!  r"  rQ   rS   )rN   r8   r   r  s       r    _new_sharedz_StorageBase._new_shared  so     	?f%;;6588#I#I#KUSStF++!#}4..t44((..r#   c                     | S r   r   r&   s    r    untypedz_StorageBase.untyped  s    r#   c                     t         j                  j                  |      }|j                  rt	        t        |dz        d      }| j                  |       y)zSwap bytes in underlying data.   r   N)r   _utils_element_size
is_complexmaxr   r   )r   r9   	elem_sizes      r    byteswapz_StorageBase.byteswap  s@    LL..u5	C	A.2Iy!r#   r   NFr>   )[__name__
__module____qualname__r	   __annotations__r   r   r   r   r   r!   r   r'   r+   r-   r   	_Optionalr2   r4   r6   r8   r   r;   r>   r@   rB   rE   rG   rI   rK   rM   classmethodr   rQ   rS   rW   r[   r]   r_   ra   rc   rf   rh   rj   rl   rn   rp   rr   rt   rv   propertyrx   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r   r  r  r#  r&  r(  r0  __classcell__r   s   @r    r   r      s   KItM4LL,!!#/NANYt_NNQ  c  W)C.VtVPQVGGFF&c&!C ! ##"$4$ 92BT!WBCBAB B<tAw<c<a< <<a<a< <MQY]hd1ghbch hJtAwJAJ JCQCQC C&&/%C%2A22.0$4$Ad1gA1A A21 1  :A: :0!0 0-C	#C.93
2I&%$$#%$%$('&+-//
3c5<<&7 8 
3/sELL'8!9 / 	 ). 	/ 	/"r#   r   c                 B     t        j                          fd       }|S )Nc                 r   d }d }t         5  | j                  }|t        v r
t        |   }n4t        j                         t        |<   t        |   j                          |}d d d        ||5  	 d d d        	  | g|i ||?| j                  |k(  sJ t         5  t        |   j                          t        |= d d d        S S # 1 sw Y   exY w# 1 sw Y   cxY w# 1 sw Y   S xY w# |K| j                  |k(  sJ t         5  t        |   j                          t        |= d d d        w # 1 sw Y   w xY ww xY wr   )_share_memory_lockr   r   	threadingRLockacquirerelease)r   r   r   to_freeto_waitkeyfns         r    wrapperz-_share_memory_lock_protected.<locals>.wrapper  sM    	++C''+C0)2):!#&!#&..0	  	3d,T,V, " {{g---' 3%g.668)'23 3	 #)	 	 3 3	 " {{g---' 3%g.668)'23 3 3	 #sH   AC+C6C' CCCC$	'D6D) 	D6)D2.D6)	functoolswraps)rF  rG  s   ` r    _share_memory_lock_protectedrJ    s%    __R3 3< Nr#   c                        e Zd Z fdZed        Zed        Zedee   fd       Z	e
 fd       Ze
 fd       Ze
 fd       Z xZS )	r   c                 j    | j                   j                  dk(  rt        d      t        |   |i |S )Nr   $Not available for 'meta' device type)r   r;   NotImplementedErrorr   r+   r   r   r   r   s      r    r+   zUntypedStorage.__getitem__>  s6    ;;v%%&LMMw"D3F33r#   c                 4    | j                   j                  dk(  S Nr>   r   r;   r&   s    r    rx   zUntypedStorage.is_cudaC  s    {{6))r#   c                 4    | j                   j                  dk(  S Nr@   rR  r&   s    r    rz   zUntypedStorage.is_hpuG  s    {{5((r#   r$   c                 "    | j                         S zReturns the file name associated with this storage if the storage was memory mapped from a file.
           or ``None`` if the storage was not created by memory mapping a file.)r   r&   s    r    r|   zUntypedStorage.filenameK  s     !!##r#   c                 "    t        |   |i |S )a{  
        Moves the storage to shared memory.

        This is a no-op for storages already in shared memory and for CUDA
        storages, which do not need to be moved for sharing across processes.
        Storages in shared memory cannot be resized.

        Note that to mitigate issues like `this <https://github.com/pytorch/pytorch/issues/95606>`_
        it is thread safe to call this function from multiple threads on the same object.
        It is NOT thread safe though to call any other function on self without proper
        synchronization. Please see :doc:`/notes/multiprocessing` for more details.

        .. note::
            When all references to a storage in shared memory are deleted, the associated shared memory
            object will also be deleted. PyTorch has a special cleanup process to ensure that this happens
            even if the current process exits unexpectedly.

            It is worth noting the difference between :meth:`share_memory_` and :meth:`from_file` with ``shared = True``

            #. ``share_memory_`` uses `shm_open(3) <https://man7.org/linux/man-pages/man3/shm_open.3.html>`_ to create a
               POSIX shared memory object while :meth:`from_file` uses
               `open(2) <https://man7.org/linux/man-pages/man2/open.2.html>`_ to open the filename passed by the user.
            #. Both use an `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_ with ``MAP_SHARED``
               to map the file/object into the current virtual address space
            #. ``share_memory_`` will call ``shm_unlink(3)`` on the object after mapping it to make sure the shared memory
               object is freed when no process has the object open. ``torch.from_file(shared=True)`` does not unlink the
               file. This file is persistent and will remain until it is deleted by the user.

        Returns:
            ``self``
        )r   r#  rO  s      r    r#  zUntypedStorage.share_memory_Q  s    B w$d5f55r#   c                 "    t        |   |i |S r   )r   rM   rO  s      r    rM   zUntypedStorage._share_fd_cpu_t  s    w%t6v66r#   c                 "    t        |   |i |S r   )r   rK   rO  s      r    rK   z#UntypedStorage._share_filename_cpu_x  s    w+T<V<<r#   )r3  r4  r5  r+   r9  rx   rz   r7  r   r|   rJ  r#  rM   rK   r:  r;  s   @r    r   r   =  s    4
 * * ) ) $)C. $ $
 " 6 " 6D "7 "7 "= "=r#   r   c                 R    t        j                  t        j                  |             S r   )r   loadr   r   )r   s    r    r   r   |  s    ::bjjm$$r#   )maxsizec                  H   i t         j                  dt         j                  dt         j                  dt         j                  dt         j
                  dt         j                  dt         j                  dt         j                  dt         j                  d	t         j                  d
t         j                  dt         j                  dt         j                  dt         j                  dt         j                  dt         j                   dt         j"                  dS )NDoubleStorageFloatStorageHalfStorageLongStorage
IntStorageShortStorageCharStorageByteStorageBoolStorageBFloat16StorageComplexDoubleStorageComplexFloatStorageQInt8StorageQInt32StorageQUInt8StorageQUInt4x2StorageQUInt2x4Storage)r   r   r   r   r   r   int16r   r   r   r   r  r  qint8qint32quint8quint4x2quint2x4r   r#   r    _dtype_to_storage_type_mapru    s   o^ 	

M 	

M	
 			< 	^ 	

M 	] 	

M 	) 	- 	+ 	^ 	o 	o  	)!" 	)# r#   c                  h    t               j                         D  ci c]  \  } }|| 
 }} }|S c c}} w r   )ru  items)rE  val	dtype_maps      r    _storage_type_to_dtype_maprz    sA     "<!=!C!C!EGS#SGI GGs   .c           
      l   |t         j                  t         j                  t         j                  t         j                  t         j
                  fv rt         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  i}t        j                  | ||   |      }nt        j                  | ||      }|j                         j                  S )Nr   )r   rr  rs  rt  rq  rp  r   int32r   r   r   _untyped_storage)sequencer9   r   interpret_dtypes
tmp_tensors        r    _get_storage_from_sequencer    s    u~~u~~u||U[[YYLL%++NNEKKNNEKKLL%++KK
 \\"5)
 \\

 $$&777r#   c                 n    t         r t        | t        t        j                  f      S t        | t              S r   )	HAS_NUMPYr   r   npinteger)xs    r    _isintr    s(    !c2::.//!S!!r#   Fc                      t         S r   )"_always_warn_typed_storage_removalr   r#   r    &_get_always_warn_typed_storage_removalr    s    --r#   c                 ,    t        | t              sJ | ay r   )r   r   r  )always_warns    r    &_set_always_warn_typed_storage_removalr    s    k4((()4&r#   c                     d }t               s |       r5d}t        j                  |t        | dz          dt        j
                  d<   y y )Nc                  L    t        t        d      syt        j                  d    S )N
has_warnedT)hasattr_warn_typed_storage_removal__dict__r   r#   r    is_first_timez2_warn_typed_storage_removal.<locals>.is_first_time  s$    2LA2;;LIIIr#   a  TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()r   )
stacklevelTr  )r  warningswarnUserWarningr  r  )r  r  messages      r    r  r    sL    J ./=?Q 	 	g{zA~F=A#,,\: 4Cr#   c                  *    dt         j                  d<   y )NFr  )r  r  r   r#   r    !_reset_warn_typed_storage_removalr    s    9>((6r#   modulec                 x    | j                  dd      d   }|dt        j                  j                         dfv r|S y)N.r   r>   r@   r   )rsplitr   r!  r"  )r  	last_parts     r    _get_device_from_moduler    s<    c1%b)IVUXXCCEuMMr#   c            	           e Zd ZU dZej
                  ed<   ed        Zede	e
   fd       Zd Zddddd fd	
Zddddd
dZed        Zed        Zd Zd Zd ZdcdZd Zd Zd Zd Zdddede	e   fdZd Zd Zdede	e
   dedeee
f   fdZdedefdZ dedefdZ!d Z"d Z#de$fd Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+ fd'Z,d( Z-d) Z.d* Z/dfd+ee
ej`                  f   fd,Z1dfd+ee
ej`                  f   fd-Z2d. Z3d/ Z4dd0d1Z5ed2        Z6ed3        Z0d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@eAd>        ZBd? ZCeAd@        ZDeAdddAdB       ZEdC ZFdD ZGdE ZHdF ZIdG ZJdH Z$dI ZKdJ ZLdK ZMdL ZdM ZNdN ZOdO ZPdP ZQdQ ZRdR ZSdS ZTeAdT        ZUeAdU        ZVdV ZWdW ZXdX ZYdY ZZdZ Z[d[ Z\eAd\        Z]d] Z^d^ Z_eAdd0d_       Z`d` Zada Zbdb Zc xZdS )gTypedStorageFr9   c                     | j                   S r   )r9   r&   s    r    _dtypezTypedStorage._dtype  s    zzr#   r$   c                 .    | j                   j                  S rV  )r}  r|   r&   s    r    r|   zTypedStorage.filename  s     $$---r#   c                 n    t                | j                  t        d| j                               |       | S )Nr   )r  _setitemslice_size)r   values     r    fill_zTypedStorage.fill_  s(    #%eAtzz|,e4r#   N)wrap_storager9   r   	_internalc                   |s
t                | t        j                  j                  k(  rt	        d      | t
        k(  rt        |   |       S |  d}|t	        |dz         |t	        |dz         |t        |      dkD  rt	        |dz         t        |      dk(  rRt        |d         sDt        |d   t        j                  j                        st        |dt        |d          z         t        || j                   t#        | j$                        d	d
S t        |      dk7  rt	        |dz         t        |t        j&                        st        |dt        |       z         t#        | j$                        }|j(                  j                  |k7  r(t	        |d| d|j(                  j                   z         t        ||| j*                  d	dS )Nz8Only child classes of _LegacyStorage can be instantiatedz.__new__ received an invalid combination of arguments. Expected one of:
 * no arguments
 * (int size)
 * (Sequence data)
 * (*, UntypedStorage wrap_storage)z.
Keyword argument 'device' cannot be specifiedz-
Keyword argument 'dtype' cannot be specifiedr   
Too many positional argumentsr   
Argument type not recognized: T)r9   r   r  B
No positional arguments should be given when using 'wrap_storage'9
Argument 'wrap_storage' must be UntypedStorage, but got z"
Device of 'wrap_storage' must be z
, but got r  r9   r  )r  r   r   _LegacyStorageRuntimeErrorr  r   __new__r   r  r   collectionsabcSequencer   r;   r  r  r4  r   r   r9   )	rN   r  r9   r   r  r   arg_error_msg
cls_devicer   s	           r    r  zTypedStorage.__new__  s+   ')%--...YZZ,7?3'' % 6 6  !"!EFG G  "!DEF F #t9q=&%9:; ; t9>&a/*TRSWVaVeVeVnVnBo#%:4Q=/JKL L $**23>>B"	$ $ t9>&%))* *
 ",0D0DE#%TUYZfUgThijk k 5S^^D
&&++z9&%=j\$\%8%8%=%=$>@@A A
 $!-))"	$ $r#   )r   r9   r  r  c                   |s
t                d}|t        |      dk7  rt        |dz         |t        |dz         t        |t        j
                        st        |dt        |       z         |t        |dz         || _        t        |t        j                        st        |dt        |       z         || _	        y |t	        j                         n|| _        t	        j                  |dn|      }| j
                  t        j                  t        j                  t        j                  t        j                  t        j                   fv r|j                  d	k(  rt        d
      t        |      dk(  rt	        j                  |      | _	        y t        |      dk(  rt#        |d         r:t	        j                  t%        |d         | j'                         z  |      | _	        y t        |d   t(        j*                  j,                        r t/        |d   | j
                  |      | _	        y t        |dt        |d          z         t        |dz         )Na1  TypedStorage.__init__ received an invalid combination of arguments. Expected one of:
 * (*, torch.device device, torch.dtype dtype)
 * (int size, *, torch.device device, torch.dtype dtype)
 * (Sequence data, *, torch.device device, torch.dtype dtype)
 * (*, UntypedStorage wrap_storage, torch.dtype dtype)r   r  z#
Argument 'dtype' must be specifiedz+
Argument 'dtype' must be torch.dtype, not zG
Argument 'device' should not be specified when 'wrap_storage' is givenr  r   r>   /Cannot create CUDA storage with quantized dtyper   r   r  r  )r  r   r  r   r   r9   r   r;   r   r}  get_default_dtyper   rr  rs  rt  rq  rp  r  r   r,  r  r  r  r  )r   r   r9   r  r  r   r  s          r    r!   zTypedStorage.__init__E  sT   ')E 	 #4yA~"!%%& &
 }"!:;< < eU[[1!B4;-PQR R !"!^_` ` DJlE,@,@A!PQUVbQcPdefg g %1D! 7<m002DJ\\6>%vFFzzellENNENNELLZ_ZeZeff;;&(&'XYY4yA~(-(<(<F(K%Ta$q'?,1,@,@T!WPTPbPbPdAdms,tD)Q)A)AB,FtAwPTPZPZ\b,cD)#%:4Q=/JKL L
 #!567 7r#   c                 \    t                | j                  j                  j                  dk(  S rQ  r  r}  r   r;   r&   s    r    rx   zTypedStorage.is_cuda  s%    #%$$++00F::r#   c                 \    t                | j                  j                  j                  dk(  S rT  r  r&   s    r    rz   zTypedStorage.is_hpu  s%    #%$$++00E99r#   c                 .    t                | j                  S )z2Return the internal :class:`torch.UntypedStorage`.)r  r}  r&   s    r    r(  zTypedStorage.untyped  s    #%$$$r#   c                     t        |      t        j                  k(  sJ t        |       t        k(  rt        || j                  d      S  t        |       |      S )NTr  r  )r;   r   r   r  r9   )r   r  s     r    _new_wrapped_storagez!TypedStorage._new_wrapped_storage  sT    O$(<(<<<<:%,jj   
 4:?;;r#   c                 6    t                | j                         S r   r  r  r&   s    r    r'   zTypedStorage.__len__      #%zz|r#   c                    ||r| j                         S yt        |      t        k7  r#t        dt        |        dt        |             |r`|| j                         kD  s|| j                          k  rt	        d| d| j                                |dkD  r|S || j                         z  S || j                         k\  s|| j                          k  rt	        d| d| j                                || j                         z  S )Nr   can't index a  with zindex z" out of range for storage of size )r  r;   r   r   
IndexErrorr8   )r   r*   is_stops      r    _maybe_wrap_indexzTypedStorage._maybe_wrap_index  s   ;zz|# CyC$T$ZLtCykBD D$**,&C4::<-,?$ %G		}UW W7J--4::<'SDJJL=-@$ %G		}UW WTZZ\))r#   c                 :    t                | j                  ||      S r   )r  r  )r   r*   r  s      r    r-   zTypedStorage.__setitem__  s    #%}}S%((r#   c           
      
   t        |t        t        f      s#t        dt	        |        dt	        |             t        j                  |      rt        dt	        |             | j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  fv rt
        j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  i}|| j                     }t        j                   g || j"                  j$                        }|j'                  t)        | j"                  |d             nEt        j                   g | j                  | j"                  j$                        j'                  |       }|||<   y )Nr  r  z cannot set item with value type r   Tr  )r   r   r  r  r;   r   
is_storager9   rr  rs  rt  rq  rp  r   r|  r   r   r}  r   r   r  )r   r*   r  r  	tmp_dtyper  s         r    r  zTypedStorage._setitem  sU   #U|,T
|6$s)MNNE"!A$u+OPP::%,,V[VaVabbekkekkUZZ  )4Ib	$BWBWB^B^_JOOL!22  !
 b

4CXCXC_C_`eefjkJ
3r#   c                 8    t                | j                  |      S r   )r  _getitemr)   s     r    r+   zTypedStorage.__getitem__  s    #%}}S!!r#   c           
      \   | j                   j                  j                  dk(  rt        d      t	        |t
              rt        d      t	        |t              s#t        dt        |        dt        |             | j                  t        j                  t        j                  t        j                  t        j                  t        j                  fv rt        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                   t        j                  t        j"                  i}t%        | j                   || j                     d      j'                  |      S | j)                  |      }dd	lm}  |       5  t        j.                  g | j                  | j                   j                  
      j1                  |       }||   j3                         cd d d        S # 1 sw Y   y xY w)Nr   rM  z7slices are only supported in UntypedStorage.__getitem__r  r  Tr  r   )unset_fake_temporarilyr   )r}  r   r;   rN  r   r  r  r   r9   r   rr  rs  rt  rq  rp  r   r|  r   r  r  r  torch._subclasses.fake_tensorr  r   r   item)r   r*   r  idx_wrappedr  r  s         r    r  zTypedStorage._getitem  s     '',,6%&LMM c5!XYYC%T
|6$s)MNN::%,,V[VaVabbekkekkUZZ   !22&tzz2  !).
 ,,S1H#% 	2b

4CXCXC_C_`eefjkJk*//1	2 	2 	2s    AH""H+r.   r/   c                     t                t        |t              r(| j                  j	                  |j                  |       | S | j                  j	                  ||       | S r   )r  r   r  r}  r2   r1   s      r    r2   zTypedStorage.copy_  sR    #%fl+!!''(?(?N  !!''=r#   c                 6    t                | j                         S r   )r  _nbytesr&   s    r    r6   zTypedStorage.nbytes	  s    #%||~r#   c                 6    | j                   j                         S r   )r}  r6   r&   s    r    r  zTypedStorage._nbytes  s    $$++--r#   c                    t                |^| j                         }||j                  dz   |j                  z   S dj	                  | j                  t        |       j                  g      S | j                  j                  ||      S )Nr  )r  _get_legacy_storage_classr4  r3  r   r;   r}  )r   r9   r/   legacy_classs       r    r;   zTypedStorage.type  sz    #%=99;L'#..4|7L7LLL88T__d4j.A.ABCC ((--e\BBr#   c                 <   t                | j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv rt        d       | j                  j                  ||fi |}| j                  |      S )Nr  )r  r9   r   rr  rs  rt  rq  rp  r  r}  r>   r  )r   r   r/   r   cuda_storages        r    r>   zTypedStorage.cuda  st    #%::%,,V[VaVabbPQQ-GT-B-B-G-GP\-g`f-g((66r#   c                 <   t                | j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv rt        d       | j                  j                  ||fi |}| j                  |      S )Nz.Cannot create HPU storage with quantized dtype)r  r9   r   rr  rs  rt  rq  rp  r  r}  r@   r  )r   r   r/   r   hpu_storages        r    r@   zTypedStorage.hpu%  ss    #%::%,,V[VaVabbOPP,ED,A,A,E,Efl,e^d,e((55r#   c                 6    t                | j                         S r   )r  r,  r&   s    r    rB   zTypedStorage.element_size,  s    #%!!##r#   c                 T    t         j                  j                  | j                        S r   )r   r+  r,  r9   r&   s    r    r,  zTypedStorage._element_size1  s    ||))$**55r#   c                 J    t                | j                  j                         S r   )r  r}  rE   r&   s    r    rE   zTypedStorage.get_device4  s    #%$$//11r#   c           
      J    t                dt        j                          d j                   d j                   dt                d	} j                  j                  dk(  rd|z   S dd	j                   fd
t         j                               D              z   }|dz   |z   S )Nr   z(dtype=z	, device=r   r   r   r   r   r   c              3   :   K   | ]  }t        |           y wr   r   r   s     r    r   z'TypedStorage.__str__.<locals>.<genexpr>@  r   r   r   )
r  r   r   r9   r   r   r;   r   r   r8   r   s   `  r    r   zTypedStorage.__str__8  s    #%t$%WTZZL 9kk]*SYKq: 	 ;;v%X%%UZZ'QeDIIK>P'QQQHd?X--r#   c                 ,    t                t        |       S r   )r  r   r&   s    r    r   zTypedStorage.__repr__C  s    #%4yr#   c                 n     t                t         fdt         j                               D              S )Nc              3   (   K   | ]	  }|     y wr   r   r   s     r    r   z(TypedStorage.__iter__.<locals>.<genexpr>I  r   r   )r  r   r   r8   r&   s   `r    r   zTypedStorage.__iter__G  s%    #%8U499;%7888r#   c                 r    t                | j                  t        j                  | j                              S r   )r  r  copyr}  r&   s    r    r   zTypedStorage.__copy__K  s(    #%((43H3H)IJJr#   c                 8    t                | j                  |      S r   )r  	_deepcopyr   r   s     r    r   zTypedStorage.__deepcopy__O  s    #%~~d##r#   c                 `    | j                  t        j                  | j                  |            S r   )r  r  deepcopyr}  r  s     r    r  zTypedStorage._deepcopyT  s$    ((t7L7Ld)STTr#   c                 V    t                t        | 	         | j                         z   S r   )r  r   r   r6   r   s    r    r   zTypedStorage.__sizeof__W  s"    #%w!#dkkm33r#   c                 h    t                | j                  | j                  j                               S )r   )r  r  r}  r   r&   s    r    r   zTypedStorage.clone[  s(    #%(()>)>)D)D)FGGr#   c                 ,    t                t        |       S r   )r  r   r&   s    r    r   zTypedStorage.tolist`  s    #%Dzr#   c                 h    t                | j                  | j                  j                               S )r   )r  r  r}  r   r&   s    r    r   zTypedStorage.cpue  s(    #%(()>)>)B)B)DEEr#   r   c                 L    t                | j                  j                  |      S )zDetermine whether the CPU TypedStorage is already pinned on device.

        Args:
            device (str or torch.device): The device to pin memory on. Default: ``'cuda'``

        Returns:
            A boolean variable.
        )r  r}  r  r  s     r    r  zTypedStorage.is_pinnedj  s!     	$%$$..v66r#   c                 l    t                | j                  | j                  j                  |            S )zCopy the CPU TypedStorage to pinned memory, if it's not already pinned.

        Args:
            device (str or torch.device): The device to pin memory on. Default: ``'cuda'``.

        Returns:
            A pinned CPU storage.
        r   )r  r  r}  r  r  s     r    r  zTypedStorage.pin_memoryv  s0     	$%(()>)>)I)IQW)I)XYYr#   c                 6    t                | j                         S )r  )r  _share_memory_r&   s    r    r#  zTypedStorage.share_memory_  s    #%""$$r#   c                 :    | j                   j                          | S r   )r}  r#  r&   s    r    r  zTypedStorage._share_memory_  s    ++-r#   r   c                    |d}t        j                  |      }t         j                  j                  || j	                         z  |      }t        || j                  d      S )r%  r   r   Tr  )r   r   r   r&  r,  r  r9   )r   r8   r   r  s       r    r&  zTypedStorage._new_shared  s^    >Ff%..::4$BTBTBV;V_e:f(** 	r#   c                 .    | j                   j                  S r   )r}  r   r&   s    r    r   zTypedStorage._cdata  s    $$+++r#   c                 B    t                | j                  j                  S r   )r  r}  r   r&   s    r    r   zTypedStorage.device  s    #%$$+++r#   c                 6    t                | j                         S r   r  r&   s    r    r8   zTypedStorage.size  r  r#   c                 X    | j                   j                         | j                         z  S r   )r}  r6   r,  r&   s    r    r  zTypedStorage._size  s'     $$++-1C1C1EEEr#   c                 6    t                | j                         S r   )r  _pickle_storage_typer&   s    r    pickle_storage_typez TypedStorage.pickle_storage_type  s    #%((**r#   c                     	 t               | j                     S # t        $ r}t        d| j                   d      |d }~ww xY w)Nzdtype z is not recognized)ru  r9   KeyError)r   es     r    r  z!TypedStorage._pickle_storage_type  sG    	K-/

;; 	KVDJJ</ABCJ	Ks    	A<Ac                     t        j                         }t        j                  | |d       t        |j                         ffS r   r   r   s     r    r   zTypedStorage.__reduce__  r   r#   c                 6    t                | j                         S r   )r  	_data_ptrr&   s    r    rG   zTypedStorage.data_ptr  s    #%~~r#   c                 6    | j                   j                         S r   )r}  rG   r&   s    r    r  zTypedStorage._data_ptr  s    $$--//r#   c                 J    t                | j                  j                         S r   )r  r}  rI   r&   s    r    rI   zTypedStorage.resizable  s    #%$$..00r#   c                 :    t                | j                  |       y r   )r  _resize_re   s     r    rf   zTypedStorage.resize_  s    #%dr#   c                 \    | j                   j                  || j                         z         y r   )r}  rf   r,  re   s     r    r  zTypedStorage._resize_  s$    %%dT-?-?-A&ABr#   c                 ,    t        j                  |i |S r   )r   rv   rV   s      r    rv   zTypedStorage._free_weak_ref  s    ,,d=f==r#   c                 :     | j                   j                  |i |S r   )r}  rh   r   s      r    rh   zTypedStorage._weak_ref  s     .t$$..???r#   c                 :    t                 | j                  |i |S r   )r  _from_bufferrV   s      r    rW   zTypedStorage.from_buffer  s     #%s000r#   r   c                   | t         k(  rz|t        j                         n|}t        j                  |dn|      }|j                  dk7  rt        d|j                         t        j                  j                  |d|i|}nU|t        |      dk(  rt        d      |t        d      | j                  }t        j                  j                  |d|i|}t        ||d      S )	Nr   z3TypedStorage.from_buffer: Not available for device r9      zefrom_buffer: 'dtype' can only be specified in UntypedStorage.from_buffer and TypedStorage.from_bufferzffrom_buffer: 'device' can only be specified in UntypedStorage.from_buffer and TypedStorage.from_bufferTr  )
r  r   r  r   r;   r  r   rW   r   r  )rN   r9   r   r   r   r  s         r    r  zTypedStorage._from_buffer  s   ,16E++-EE\\6>%vFF{{e#"%XY_YdYdXe#fgg494H4H4T4TVZ4rbg4rkq4rO  CIN"NO O !"NO O JJE#22>>\E\U[\O( 	r#   c                 z   t        |t        j                        st        dt	        |             t        j
                  g | j                  | j                        j                  |       j                  |      j                         }|j                         | j                         k(  r|j                         }|S r   )r   r   r9   r   r;   r   r   r   r   r   rG   r   r   s      r    r   zTypedStorage._to  s    %-HeVWW,,rDKKHMMdSVVW\]lln0mmoGr#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.double      #%xx%%r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.float      #%xx$$r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.half      #%xx

##r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.long  r  r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.int  s    #%xx		""r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.short  r  r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.char  r  r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.byte   r  r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.bool%  r  r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r   r&   s    r    r   zTypedStorage.bfloat16*  s    #%xx''r#   c                 T    t                | j                  t        j                        S r   )r  r   r   r  r&   s    r    r  zTypedStorage.complex_double/  s    #%xx&&r#   c                 T    t                | j                  t        j                        S r  )r  r   r   r  r&   s    r    r  zTypedStorage.complex_float4  r  r#   c                 T    t                | j                  t        j                        S r  )r  r   r   r	  r&   s    r    r	  zTypedStorage.float8_e5m29  s    #%xx))**r#   c                 T    t                | j                  t        j                        S r  )r  r   r   r  r&   s    r    r  zTypedStorage.float8_e4m3fn>  s    #%xx++,,r#   c                 T    t                | j                  t        j                        S r  )r  r   r   r  r&   s    r    r  zTypedStorage.float8_e5m2fnuzC      #%xx--..r#   c                 T    t                | j                  t        j                        S r  )r  r   r   r  r&   s    r    r  zTypedStorage.float8_e4m3fnuzH  r+  r#   c                     t                | t        k(  rt        d      t        j	                  |||t
        j                  j                  | j                        z        } | |      }|S )a  from_file(filename, shared=False, size=0) -> Storage

        Creates a CPU storage backed by a memory-mapped file.

        If ``shared`` is ``True``, then memory is shared between all processes.
        All changes are written to the file. If ``shared`` is ``False``, then the changes on
        the storage do not affect the file.

        ``size`` is the number of elements in the storage. If ``shared`` is ``False``,
        then the file must contain at least ``size * sizeof(Type)`` bytes
        (``Type`` is the type of storage). If ``shared`` is ``True`` the file will be created if needed.

        Args:
            filename (str): file name to map
            shared (bool): whether to share memory (whether ``MAP_SHARED`` or ``MAP_PRIVATE`` is passed to the
                            underlying `mmap(2) call <https://man7.org/linux/man-pages/man2/mmap.2.html>`_)
            size (int): number of elements in the storage
        z/from_file can only be called on derived classesr  )	r  r  r  r   r~   r   r+  r,  r9   )rN   r|   r}   r8   r  r   s         r    r~   zTypedStorage.from_fileM  s`    ( 	$%,PQQ*8*B*B5<<--cii88+: ?3r#   c                 ,    t        j                  |i |S r   )r   r   rV   s      r    r   zTypedStorage._expiredk  s    &&777r#   c                 :     | j                   j                  |i |S r   )r}  rc   r   s      r    rc   zTypedStorage._write_fileo  s     0t$$00$A&AAr#   c                 :     | j                   j                  |i |S r   )r}  rj   r   s      r    rj   zTypedStorage._set_from_filer       3t$$33TDVDDr#   c                 :     | j                   j                  |i |S r   )r}  rl   r   s      r    rl   zTypedStorage._set_cdatau  s     /t$$//@@@r#   c                 :     | j                   j                  |i |S r   )r}  rn   r   s      r    rn   zTypedStorage._share_cuda_x  s     1t$$114B6BBr#   c                 6    t                | j                         S r   )r  
_is_sharedr&   s    r    rp   zTypedStorage.is_shared{  s    #%  r#   c                 6    | j                   j                         S r   )r}  rp   r&   s    r    r5  zTypedStorage._is_shared  s    $$..00r#   c                 @    t        j                  j                  |i |S r   )r   r   rr   rV   s      r    rr   zTypedStorage._new_shared_cuda  s    ##44dEfEEr#   c                 n     | j                   j                  |i |\  }}}|||| j                         z  fS r   )r}  rK   r,  )r   r   r   manager_handlestorage_handler8   s         r    rK   z!TypedStorage._share_filename_cpu_  sC    /Yt/D/D/Y/Y[_/jci/j,~tt7I7I7K/KKKr#   c                 :    | j                   j                          | S r   )r}  ra   r&   s    r    ra   zTypedStorage._shared_decref  s    ,,.r#   c                @    t        j                  j                  |i |S r   r   r   r]   )rN   r   r   r   s       r    _release_ipc_counterz!TypedStorage._release_ipc_counter      ##==tNvNNr#   c                 :     | j                   j                  |i |S r   )r}  rt   r   s      r    rt   zTypedStorage._shared_incref  r1  r#   c                 j     | j                   j                  |i |\  }}||| j                         z  fS r   )r}  rM   r,  )r   r   r   fdr8   s        r    rM   zTypedStorage._share_fd_cpu_  s<    74((77HHD44--////r#   c                    | j                   t               vry t               | j                      }| j                  j                  dddt        j
                  j                         fvry | j                  j                  dk(  rt        n#t        t        | j                  j                        }	 t        ||      S # t        $ r Y y w xY w)Nr   r>   r@   )	r9   ru  r   r;   r   r!  r"  getattrAttributeError)r   storage_namer  s      r    r  z&TypedStorage._get_legacy_storage_class  s    ::79913DJJ?;;E65%((:`:`:b#cc++**e3HXHX9Y	6<00 		s   ,B8 8	CC)Fr   r1  r2  )er3  r4  r5  r   r   r9   r6  r9  r  r7  r   r|   r  r  r!   rx   rz   r(  r  r'   r  r-   r  r+   r  r   r   r2   r6   r  r   r;   r>   r@   rB   r,  r   rE   r   r   r   r   r   r  r   r   r   r   r   r  r  r#  r  r&  r   r8   r  r  r  r   rG   r  rI   rf   r  r8  rv   rh   rW   r  r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r~   r   rc   rj   rl   rn   rp   r5  rr   rK   ra   r>  rt   rM   r  r:  r;  s   @r    r  r    sJ   I;;  .)C. . .

 *.T$RW F$P &*DTY B7H ; ; : :%
	<*2) 0"2BA Yt_ 
.C)C. Ct CPUVWY\V\P] C7 76 6$
62C 2	.9K$
U4H

F

7c5<<&7 8 
7
ZsELL'8!9 
Z% +/ 	 , , , ,
F
+
K3
 
01
C > >@ 1 1 '+D  4&
%
$
$
#
%
$
%
$
(
'
&
+
-
/
/
  : 8 8BEAC!
1 F FL 04 O OE0r#   r  c                   2    e Zd ZU ej                  ed<   d Zy)_LegacyStorageMetar9   c                     t        |      t        k(  rIt        | j                        }||j                  j                   k(  xr | j
                  |j
                  k(  S yr1  )r;   r  r  r4  r   r9   )rN   instancer  s      r    __instancecheck__z$_LegacyStorageMeta.__instancecheck__  sF    >\)0@J(//"6"66YSYY(..=XYr#   N)r3  r4  r5  r   r9   r6  rK  r   r#   r    rH  rH    s    ;;r#   rH  c                   <    e Zd Zed        Zed        Zed        Zy)r  c                 ~    t         j                  j                  | |        j                         z        } | |      S )r%  r  )r   r   r&  r,  )rN   r8   r  s      r    r&  z_LegacyStorage._new_shared  s5      ..::4#%BUBUBW;WX00r#   c                 @    t        j                  j                  |i |S r   r=  rV   s      r    r>  z#_LegacyStorage._release_ipc_counter  r?  r#   c                     |t         j                  j                  | j                        z  } | t         j                  j                  |||            S )Nr  )r   r+  r,  r9   r   r[   )rN   rY   rZ   r8   
bytes_sizes        r    _new_shared_filenamez#_LegacyStorage._new_shared_filename  sA    ELL66syyAA
 4 4 M MgWZ\f ghhr#   N)r3  r4  r5  r8  r&  r>  rQ  r   r#   r    r  r    s@    1 1
 O O i ir#   r  )	metaclassr  c                 `    	 t               |    S # t        $ r}t        d|  d      |d }~ww xY w)Nzpickle storage type "z" is not recognized)rz  r  )r  r	  s     r    #_get_dtype_from_pickle_storage_typerT    sJ    U)+,?@@ U#$7#88KLNST	UUs    	-(-)r*  )<r   r   r+  r   r   r   torch.typesr   typingr   r	   r
   _Dictr   r7  r   r   r   r  r  rH  r   r  r?  numpyr  r  ModuleNotFoundErrorLockr>  r   r   r@  r6  r   r   rJ  r!  StorageBaser   r   r;   r>   r@   ru  rz  r  r  r  r  r  r  r  r   r  r  __doc__rH  r  rT  r   r#   r    <module>r]     s   	  & &  X X X      I $Y^^% 13 5ioo-. 3C:;A" A"H D==UXX))< ==~%     4 4 4 
8," &+ ".5
B&?C 
 
B "MM   !MM   <<    i\-? i US Uo%  	Bs   E6 6F F