
    sg                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
mZmZmZmZmZ d dlmZ d dlZd dlmZmZ d dlmZmZmZ ddgZ	 d dlZd	Z ejB                         Z"i Z#de$d<    edd      Z% G d d      Z&d Z' G d dejP                  jR                  e&      Z*d Z+ ejX                  d      d        Z- ejX                  d      d        Z. ejX                  d      d        Z/d Z0d Z1d
a2d Z3d Z4d'dZ5d Z6d(dZ7 G d  d      Z8ejr                  e8jt                  _9        e&jv                  jr                  e8jv                  _9        e&jx                  jr                  e8jx                  _9        ejr                  e8jz                  _9         G d! d"e:      Z> G d# d$e8e>%      Z?d)d&Z@y# e $ r d
ZdZY iw xY w)*    )annotationsN)AnycastDictOptionalTypeTypeVarUnion)Self)_to_type)_bool_intStorageTypedStorageUntypedStorageTFz_Dict[int, threading.RLock]_share_memory_mapT!Union[_StorageBase, TypedStorage])boundc                      e Zd ZU ded<   dZded<   dZded<   ded<   d	Zd
ed<   d ZdZdZd Z	d Z
d[d\dZd]dZdZdZdZdZ	 d^	 	 	 	 	 d_dZ	 d^	 d]dZd^d]dZdZdZdZdZdZdZd`dZd Zd Zedad       Zedad       Zedbd       Zed	d	d 	 	 	 dbd!       Zedbd"       Zedbd#       Zd]d$Zd% Z dcd&Z!d]d'Z"d( Z#d) Z$d* Z%d`d+Z&edbd,       Z'd- Z(ed.        Z)e*d/        Z+e*d0        Z,ed]d1       Z-ed]d2       Z.d3 Z/ddd4Z0d5 Z1d6 Z2d7 Z3d8 Z4d9 Z5 fd:Z6d; Z7d< Z8d= Z9d> Z:d? Z;dd@	 	 	 	 	 dedAZ<dB Z=dC Z>dD Z?dE Z@dF ZAdG ZBdH ZCdI ZDdJ ZEdK ZFdL ZGdM ZHdN ZIdO ZJdP ZKdQ ZLdfdgdRZMdfdgdSZNdT ZOedUdVdW       ZPdX ZQdY ZR xZSS )h_StorageBaser   _cdataFr   	is_sparseis_sparse_csrtorch.devicedeviceN_Optional[torch.device]_fake_devicec                     y N selfargskwargss      @/var/www/html/venv/lib/python3.12/site-packages/torch/storage.py__init__z_StorageBase.__init__-   s        c                    t         r!   NotImplementedErrorr$   s    r'   __len__z_StorageBase.__len__0       !!r)   c                    t         r!   r+   r$   idxs     r'   __getitem__z_StorageBase.__getitem__3   r/   r)   c                    t         r!   r+   r#   s      r'   __setitem__z_StorageBase.__setitem__6   r/   r)   c                    t         r!   r+   r$   sourcenon_blockings      r'   copy_z_StorageBase.copy_9   r/   r)   c                    t         r!   r+   r-   s    r'   newz_StorageBase.new<   r/   r)   c                    t         r!   r+   r-   s    r'   nbytesz_StorageBase.nbytes?   r/   r)   c                "    | j                         S r!   )r>   r-   s    r'   sizez_StorageBase.sizeB   s    {{}r)   c                    t        | ||      S r!   )r   )r$   dtyper9   s      r'   typez_StorageBase.typeE   s     T5,//r)   c                    |rt        j                  d|      nt        j                  d      }| j                  ||      S )a  Returns a copy of this object in CUDA memory.

        If this object is already in CUDA memory and on the correct device, then
        no copy is performed and the original object is returned.

        Args:
            device (int): The destination GPU id. Defaults to the current device.
            non_blocking (bool): If ``True`` and the source is in pinned memory,
                the copy will be asynchronous with respect to the host. Otherwise,
                the argument has no effect.
        cudar   r9   torchr   tor$   r   r9   device2s       r'   rE   z_StorageBase.cudaJ   s4     39%,,vv.ell6>RwwgLwAAr)   c                    |rt        j                  d|      nt        j                  d      }| j                  ||      S )a  Returns a copy of this object in HPU memory.

        If this object is already in HPU memory and on the correct device, then
        no copy is performed and the original object is returned.

        Args:
            device (int): The destination HPU id. Defaults to the current device.
            non_blocking (bool): If ``True`` and the source is in pinned memory,
                the copy will be asynchronous with respect to the host. Otherwise,
                the argument has no effect.
        hpurF   rG   rJ   s       r'   rM   z_StorageBase.hpu[   s4     28%,,uf-U\\%=PwwgLwAAr)   c                    t         r!   r+   r-   s    r'   element_sizez_StorageBase.element_sizej   r/   r)   c                .    | j                   j                  S r!   )r   indexr-   s    r'   
get_devicez_StorageBase.get_devicem   s    {{   r)   c                    t         r!   r+   r-   s    r'   data_ptrz_StorageBase.data_ptrp   r/   r)   c                    t         r!   r+   r-   s    r'   	resizablez_StorageBase.resizables   r/   r)   c                    t         r!   r+   r#   s      r'   _share_filename_cpu_z!_StorageBase._share_filename_cpu_w   r/   r)   c                    t         r!   r+   r#   s      r'   _share_fd_cpu_z_StorageBase._share_fd_cpu_z   r/   r)   c                    t         r!   r+   clsr@   s     r'   _new_using_filename_cpuz$_StorageBase._new_using_filename_cpu}       !!r)   c                    t         r!   r+   r\   s     r'   _new_using_fd_cpuz_StorageBase._new_using_fd_cpu   r_   r)   c                    t         r!   r+   r]   r%   r&   s      r'   from_bufferz_StorageBase.from_buffer   r_   r)   )r   rB   c                   t         r!   r+   )r]   managerobjr@   r   rB   s         r'   _new_shared_filename_cpuz%_StorageBase._new_shared_filename_cpu   s
     "!r)   c                    t         r!   r+   rc   s      r'   _release_ipc_counter_cudaz&_StorageBase._release_ipc_counter_cuda   r_   r)   c                    t         r!   r+   rc   s      r'   _new_with_weak_ptrz_StorageBase._new_with_weak_ptr   r_   r)   c                    t         r!   r+   r-   s    r'   _shared_decrefz_StorageBase._shared_decref   r/   r)   c                    t         r!   r+   r#   s      r'   _write_filez_StorageBase._write_file   r/   r)   c                    t         r!   r+   r$   r@   s     r'   resize_z_StorageBase.resize_   r/   r)   c                    t         r!   r+   r#   s      r'   	_weak_refz_StorageBase._weak_ref   r/   r)   c                    t         r!   r+   r#   s      r'   _set_from_filez_StorageBase._set_from_file   r/   r)   c                    t         r!   r+   r#   s      r'   
_set_cdataz_StorageBase._set_cdata   r/   r)   c                    t         r!   r+   r#   s      r'   _share_cuda_z_StorageBase._share_cuda_   r/   r)   c                    t         r!   r+   r-   s    r'   	is_sharedz_StorageBase.is_shared   r/   r)   c                    t         r!   r+   rc   s      r'   _new_shared_cudaz_StorageBase._new_shared_cuda   r_   r)   c                    t         r!   r+   r#   s      r'   _shared_increfz_StorageBase._shared_incref   r/   r)   c                    t         r!   r+   rc   s      r'   _free_weak_refz_StorageBase._free_weak_ref   r_   r)   c                    t         r!   r+   r-   s    r'   is_cudaz_StorageBase.is_cuda   r_   r)   c                    t         r!   r+   r-   s    r'   is_hpuz_StorageBase.is_hpu   r_   r)   c                    t         r!   r+   )r]   filenamesharedr>   s       r'   	from_filez_StorageBase.from_file   r_   r)   c                    t         r!   r+   rc   s      r'   _expiredz_StorageBase._expired   r_   r)   c                    t         r!   r+   r#   s      r'   	_byteswapz_StorageBase._byteswap   r/   r)   c                    t         r!   r+   r#   s      r'   _get_filenamez_StorageBase._get_filename   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.__repr__.<locals>.<genexpr>   s     #MQCQL#M   
)rH   typenamer   lenrC   joinranger@   r$   info_strdata_strs   `  r'   __repr__z_StorageBase.__repr__   s    u~~d+,HT[[MCPTI;VWX;;v%X%%#M%		:L#MMM$))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>        8DG8   )iterr   r@   r-   s   `r'   __iter__z_StorageBase.__iter__   s    8U499;%7888r)   c                "    | j                         S r!   )cloner-   s    r'   __copy__z_StorageBase.__copy__   s    zz|r)   c                    |j                  di       }| j                  |v r|| j                     S | j                         }||| j                  <   |S )NrH   )
setdefaultr   r   )r$   memonew_storages      r'   __deepcopy__z_StorageBase.__deepcopy__   sL    w+;;$$$jjl'T[[r)   c                    t        j                         }t        j                  | |d       t        |j                         ffS NF)_use_new_zipfile_serializationioBytesIOrH   save_load_from_bytesgetvaluer$   bs     r'   
__reduce__z_StorageBase.__reduce__   0    JJL

45A 1::</22r)   c                B    t         |          | j                         z   S r!   )super
__sizeof__r@   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   )rC   r>   r   r:   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   rC   rH   r   r@   r:   r-   s    r'   r   z_StorageBase.cpu   s=    ;;u$''		4::4GGr)   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r)   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 rB   r   )
isinstancerH   rB   	TypeErrorrC   tensoruint8r   set_r   r   rI   _typed_storagerT   r   r$   rB   storages      r'   r   z_StorageBase._to  s    %-HeVWWLL5;;t{{CT$w%&RY^	 	 0mmoGr)   r9   c                   t        | ||      S r!   )r   )r$   r   r9   s      r'   rI   z_StorageBase.to  s     4..r)   c                @    | j                  t        j                        S z"Casts this storage to double type.)r   rH   doubler-   s    r'   r   z_StorageBase.double      xx%%r)   c                @    | j                  t        j                        S z!Casts this storage to float type.)r   rH   floatr-   s    r'   r   z_StorageBase.float      xx$$r)   c                @    | j                  t        j                        S z Casts this storage to half type.)r   rH   halfr-   s    r'   r   z_StorageBase.half!      xx

##r)   c                @    | j                  t        j                        S z Casts this storage to long type.)r   rH   longr-   s    r'   r   z_StorageBase.long%  r   r)   c                @    | j                  t        j                        S zCasts this storage to int type.)r   rH   intr-   s    r'   r   z_StorageBase.int)  s    xx		""r)   c                @    | j                  t        j                        S z!Casts this storage to short type.)r   rH   shortr-   s    r'   r   z_StorageBase.short-  r   r)   c                @    | j                  t        j                        S z Casts this storage to char type.)r   rH   int8r-   s    r'   charz_StorageBase.char1  r   r)   c                @    | j                  t        j                        S z Casts this storage to byte type.)r   rH   r   r-   s    r'   bytez_StorageBase.byte5  r   r)   c                @    | j                  t        j                        S z Casts this storage to bool type.)r   rH   boolr-   s    r'   r  z_StorageBase.bool9  r   r)   c                @    | j                  t        j                        S z$Casts this storage to bfloat16 type.)r   rH   bfloat16r-   s    r'   r  z_StorageBase.bfloat16=  s    xx''r)   c                @    | j                  t        j                        S z*Casts this storage to complex double type.)r   rH   cdoubler-   s    r'   complex_doublez_StorageBase.complex_doubleA  s    xx&&r)   c                @    | j                  t        j                        S z)Casts this storage to complex float type.)r   rH   cfloatr-   s    r'   complex_floatz_StorageBase.complex_floatE  r   r)   c                @    | j                  t        j                        S z&Casts this storage to float8_e5m2 type)r   rH   float8_e5m2r-   s    r'   r  z_StorageBase.float8_e5m2I  s    xx))**r)   c                @    | j                  t        j                        S z(Casts this storage to float8_e4m3fn type)r   rH   float8_e4m3fnr-   s    r'   r  z_StorageBase.float8_e4m3fnM  s    xx++,,r)   c                @    | j                  t        j                        S z*Casts this storage to float8_e5m2fnuz type)r   rH   float8_e5m2fnuzr-   s    r'   r  z_StorageBase.float8_e5m2fnuzQ      xx--..r)   c                @    | j                  t        j                        S z*Casts this storage to float8_e4m3fnuz type)r   rH   float8_e4m3fnuzr-   s    r'   r  z_StorageBase.float8_e4m3fnuzU  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   )rH   r   r   r   r   r   r   	is_pinnedr$   r   s     r'   r  z_StorageBase.is_pinnedY  s<     LL5;;t{{CT$w%&Yv	
r)   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   rC   r   rH   r   r   r   r   r   
pin_memoryuntyped_storage)r$   r   pinned_tensors      r'   r   z_StorageBase.pin_memoryh  s|     ;;u$l499;-7VWXX LL5;;t{{CT$w%&Z 	
 ,,..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_strategyrE   file_system)	torch.multiprocessingr&  r   rC   rH   _C_get_privateuse1_backend_namerX   rZ   )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%  rE   rM   r   r'  )	r(  r&  rH   r   rC   r)  r*  r^   ra   )r]   r@   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.      N)rH   _utils_element_size
is_complexmaxr   r   )r$   rB   	elem_sizes      r'   byteswapz_StorageBase.byteswap  s@    LL..u5	C	A.2Iy!r)   returnr   r!   )r8   r   r9   z_Optional[_bool]r;  r   )r;  r   NF)rB   _Optional[str]r9   r   r;  r   )r;  r   )r]   Type[T]r@   r   r;  r   )r]   r>  r;  r   )r@   r   r;  r=  )r   r   r9   r   r;  r   rE   r   zUnion[str, torch.device])T__name__
__module____qualname____annotations__r   r   r   r(   r.   r3   r5   r:   r<   r>   r@   rC   rE   rM   rO   rR   rT   rV   rX   rZ   classmethodr^   ra   rd   rh   rj   rl   rn   rp   rs   ru   rw   ry   r{   r}   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rI   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r  r   r+  r.  r0  r9  __classcell__r   s   @r'   r   r   %   s   KIu M5 ,0L)0"""""" CH0#0:?0	*0 ).B	*B"B"!"""" " " " " " "  	"	" 
	" 	" " " " """"""""" " "" " " " " " " " " " """*93
2I >C/%/5:/	*/
&%$$#%$%$('&+-//
/&
 ). 
/ 
/"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)rT  rU  s   ` r'   _share_memory_lock_protectedrX    s%    __R3 3> Nr)   c                       e Zd Z fdZed        Zed        Zed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   rC   r,   r   r3   r$   r%   r&   r   s      r'   r3   zUntypedStorage.__getitem__  s6    ;;v%%&LMMw"D3F33r)   c                4    | j                   j                  dk(  S NrE   r   rC   r-   s    r'   r   zUntypedStorage.is_cuda  s    {{6))r)   c                4    | j                   j                  dk(  S NrM   r_  r-   s    r'   r   zUntypedStorage.is_hpu  s    {{5((r)   c                "    | j                         S )zReturns the file name associated with this storage.

        The file name will be a string if the storage is on CPU and was created via
        :meth:`~torch.from_file()` with ``shared`` as ``True``. This attribute is ``None`` otherwise.
        )r   r-   s    r'   r   zUntypedStorage.filename  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+  r\  s      r'   r+  zUntypedStorage.share_memory_  s    B w$d5f55r)   c                "    t        |   |i |S r!   )r   rZ   r\  s      r'   rZ   zUntypedStorage._share_fd_cpu_  s    w%t6v66r)   c                "    t        |   |i |S r!   )r   rX   r\  s      r'   rX   z#UntypedStorage._share_filename_cpu_  s    w+T<V<<r)   r?  )rB  rC  rD  r3   rG  r   r   r   rX  r+  rZ   rX   rH  rI  s   @r'   r   r     s    4
 * * ) ) $ $ " 6 " 6D "7 "7 "= "=r)   c                V    t        j                  t        j                  |       d      S )NF)weights_only)rH   loadr   r   )r   s    r'   r   r     s    ::bjjm%88r)   )maxsizec            
     2   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  h
S r!   )rH   r  r  r  r  bits8bits16bits1x8bits2x4bits4x2	complex32r"   r)   r'   _new_dtypesrq    s\    
 	 r)   c                 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)rH   r   r   r   r   r   int16r   r   r  r  r	  r  qint8qint32quint8quint4x2quint2x4r"   r)   r'   _dtype_to_storage_type_mapr    s   o^ 	

M 	

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

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

M 	) 	- 	+ 	^ 	o 	o  	)!" 	)# r)   c                 h    t               j                         D  ci c]  \  } }|| 
 }} }|S c c}} w r!   )r  items)rS  val	dtype_maps      r'   _storage_type_to_dtype_mapr  9  s5    *D*F*L*L*NOhc3cOIO P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   )rH   r  r  r  r  r  r   int32r   r   r   _untyped_storage)sequencerB   r   interpret_dtypes
tmp_tensors        r'   _get_storage_from_sequencer  ?  s      LL%++NNEKKNNEKKLL%++KK
 \\,U3F


 \\(%G
$$&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  X  s(    !c2::.//!S!!r)   c                     t         S r!   )"_always_warn_typed_storage_removalr"   r)   r'   &_get_always_warn_typed_storage_removalr  b  s    --r)   c                ,    t        | t              sJ | ay r!   )r   r  r  )always_warns    r'   &_set_always_warn_typed_storage_removalr  f  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_timeo  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()r3  )
stacklevelTr  )r  warningswarnUserWarningr  r  )r  r  messages      r'   r  r  l  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)   c                x    | j                  dd      d   }|dt        j                  j                         dfv r|S y)N.r3  rE   rM   r   )rsplitrH   r)  r*  )module	last_parts     r'   _get_device_from_moduler    s<    c1%b)IVUXXCCEuMMr)   c                  8    e Zd ZU dZded<   dZded<   ded<   ed	        Zedfd
       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dgdZd ZdhdZd Zd Zd Zd ZdidjdZd Zd Z	 	 dk	 	 	 	 	 dldZdkdgdZdkdgdZdd dmd!Zd" Zd# Zdnd$Zd% Z d& Z!d' Z"d( Z#d) Z$d* Z% fd+Z&d, Z'd- Z(d. Z)dodpd/Z*dodpd0Z+d1 Z,d2 Z-dd3d4Z.ed5        Z/ed6        Z0d7 Z1d8 Z2d9 Z3d: Z4d; Z5d< Z6d= Z7d> Z8d? Z9d@ Z:e;dA        Z<dB Z=e;dC        Z>e;dddDdE       Z?dF Z@dG ZAdH ZBdI ZCdJ ZDdK ZEdL ZFdM ZGdN ZHdO ZIdP ZJdQ ZKdR ZLdS ZMdT ZNdU ZOdV ZPe;dW        ZQe;dX        ZRdY ZSdZ ZTd[ ZUd\ ZVd] ZWd^ ZXe;d_        ZYd` ZZda Z[e;dd3db       Z\dc Z]dd Z^de Z_ xZ`S )qr   Fr   r   Nr   r   torch.dtyperB   c                    | j                   S r!   )rB   r-   s    r'   _dtypezTypedStorage._dtype  s    zzr)   c                .    | j                   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   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)   )wrap_storagerB   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 specifiedr3  
Too many positional argumentsr   
Argument type not recognized: T)rB   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  rB   r  )r  rH   r   _LegacyStorageRuntimeErrorr   r   __new__r   r  r   collectionsabcSequencer   rC   r  r  rC  r   r   rB   )	r]   r  rB   r   r  r%   arg_error_msg
cls_devicer   s	           r'   r  zTypedStorage.__new__  s    ')%--...J  ,7?3'' % 6 6  !"!$UU   "!$TT  #t9q=&%(II 
 IN"47O&tAw0H0HI#%<T$q']OLM 
 $**23>>B"	  t9>&%))  ",0D0DE#%VW[\hWiVjkl 
 5S^^D
&&++z9&%?
|$\%8%8%=%=$>@@  $!-))"	 r)   )r   rB   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   rE   /Cannot create CUDA storage with quantized dtyper   r3  r  r  )r  r   r  r   rH   rB   r   rC   r   r  get_default_dtyper   r  r  r  r  r  r  r   r5  r  r  r  r  )r$   r   rB   r  r  r%   r  s          r'   r(   zTypedStorage.__init__  sW    ')E 	 #4yA~"!%%  }"!$JJ  eU[[1!DT%[MRS 
 !"!`a 
 DJlE,@,@A!RSWXdSeRfgh 
 %1D! 7<m002DJ\\6>%vFFzz  ;;&(&I  4yA~(-(<(<F(K%Ta$q'?,1,@,@DGt'9'9';;F-D)  Q)A)AB,FQV-D) $%<T$q']OLM  #=3T#TUUr)   c                \    t                | j                  j                  j                  dk(  S r^  r  r  r   rC   r-   s    r'   r   zTypedStorage.is_cudaY  s%    #%$$++00F::r)   c                \    t                | j                  j                  j                  dk(  S ra  r  r-   s    r'   r   zTypedStorage.is_hpu^  s%    #%$$++00E99r)   c                .    t                | j                  S )z2Return the internal :class:`torch.UntypedStorage`.)r  r  r-   s    r'   r0  zTypedStorage.untypedc  s    #%$$$r)   c                    t        |      t        j                  k(  sJ t        |       t        k(  r&t	        t
        t        || j                  d            S  t        |       |      S )NTr  r  )rC   rH   r   r   r   r   rB   )r$   r!  s     r'   _new_wrapped_storagez!TypedStorage._new_wrapped_storageh  s]    O$(<(<<<<:%!0

d  4:?;;r)   c                6    t                | j                         S r!   r  r  r-   s    r'   r.   zTypedStorage.__len__u      #%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  rC   r   r   
IndexErrorr@   )r$   r2   is_stops      r'   _maybe_wrap_indexzTypedStorage._maybe_wrap_indexy  s    ;zz|# CyC.dF49+ NOO$**,&C4::<-,?$ %G		}U  7J--4::<'SDJJL=-@$ %G		}U  TZZ\))r)   c                :    t                | j                  ||      S r!   )r  r  )r$   r2   r  s      r'   r5   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  rC   rH   
is_storagerB   r  r  r  r  r  r   r  r   r   r  r   r   r   )r$   r2   r  r  	tmp_dtyper  s         r'   r  zTypedStorage._setitem  sg   #U|,T
|6$s)MNNE"!A$u+OPP::LLNNNNLLKK
 
 ekkekkUZZ  )4I)D,A,A,H,HJ OO!%!6!6iSW $**T-B-B-I-Id4j   
3r)   c                8    t                | j                  |      S r!   )r  _getitemr1   s     r'   r3   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   r[  z7slices are only supported in UntypedStorage.__getitem__r  r  Tr  r   )unset_fake_temporarilyr   )r  r   rC   r,   r   r  r  r   rB   rH   r  r  r  r  r  r   r  r   r   r  r  torch._subclasses.fake_tensorr  r   r   item)r$   r2   r  idx_wrappedr  r  s         r'   r  zTypedStorage._getitem  s     '',,6%&LMM c5!I  C%T
|6$s)MNN::LLNNNNLLKK
 
 ekkekkUZZ   !22&tzz2 hsm	 ,,S1H#% 	2$**T-B-B-I-Id4j  k*//1		2 	2 	2s    AH""H+c                    t                t        |t              r(| j                  j	                  |j                  |       | S | j                  j	                  ||       | S r!   )r  r   r   r  r:   r7   s      r'   r:   zTypedStorage.copy_  sR    #%fl+!!''(?(?N  !!''=r)   c                6    t                | j                         S r!   )r  _nbytesr-   s    r'   r>   zTypedStorage.nbytes  s    #%||~r)   c                6    | j                   j                         S r!   )r  r>   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_classrC  rB  r   rC   r  )r$   rB   r9   legacy_classs       r'   rC   zTypedStorage.type  s|    
 	$%=99;L'#..4|7L7LLL88T__d4j.A.ABCC ((--e\BBr)   c                8   t                | j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv rt        d      | j                  j                  ||      }| j                  |      S )Nr  )r  rB   rH   r  r  r  r  r  r  r  rE   r  )r$   r   r9   cuda_storages       r'   rE   zTypedStorage.cuda  ss    #%::LLNNNNLLKK
 
 PQQ,,11&,G((66r)   c                8   t                | j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv rt        d      | j                  j                  ||      }| j                  |      S )Nz.Cannot create HPU storage with quantized dtype)r  rB   rH   r  r  r  r  r  r  r  rM   r  )r$   r   r9   hpu_storages       r'   rM   zTypedStorage.hpu  ss    #%::LLNNNNLLKK
 
 OPP++//E((55r)   r   c               r   t                | j                  t        j                  t        j                  t        j
                  t        j                  t        j                  fv r't        d|j                  j                          d      | j                  j                  ||      }| j                  |      S )NzCannot create z storage with quantized dtyperF   )r  rB   rH   r  r  r  r  r  r  rC   upperr  rI   r  )r$   r   r9   
to_storages       r'   rI   zTypedStorage.to%  s    #%::LLNNNNLLKK
 
  !2!2!4 55RS  **--V,-W
((44r)   c                6    t                | j                         S r!   )r  r5  r-   s    r'   rO   zTypedStorage.element_size4  s    #%!!##r)   c                T    t         j                  j                  | j                        S r!   )rH   r4  r5  rB   r-   s    r'   r5  zTypedStorage._element_size9  s    ||))$**55r)   c                J    t                | j                  j                         S r!   )r  r  rR   r-   s    r'   rR   zTypedStorage.get_device<  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>I  s     'QDG'Qr   r   )
r  rH   r   rB   r   r   rC   r   r   r@   r   s   `  r'   __str__zTypedStorage.__str__@  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__L  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>R  r   r   )r  r   r   r@   r-   s   `r'   r   zTypedStorage.__iter__P  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__T  s(    #%((43H3H)IJJr)   c                8    t                | j                  |      S r!   )r  	_deepcopyr$   r   s     r'   r   zTypedStorage.__deepcopy__X  s    #%~~d##r)   c                `    | j                  t        j                  | j                  |            S r!   )r  r	  deepcopyr  r  s     r'   r  zTypedStorage._deepcopy]  s$    ((t7L7Ld)STTr)   c                V    t                t        | 	         | j                         z   S r!   )r  r   r   r>   r   s    r'   r   zTypedStorage.__sizeof__`  s"    #%w!#dkkm33r)   c                h    t                | j                  | j                  j                               S )r   )r  r  r  r   r-   s    r'   r   zTypedStorage.cloned  s(    #%(()>)>)D)D)FGGr)   c                ,    t                t        |       S r   )r  r   r-   s    r'   r   zTypedStorage.tolisti  s    #%Dzr)   c                h    t                | j                  | j                  j                               S )r   )r  r  r  r   r-   s    r'   r   zTypedStorage.cpun  s(    #%(()>)>)B)B)DEEr)   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_pinneds  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_memory  s4     	$%((!!,,F,;
 	
r)   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  )rH   r   r   r.  r5  r   rB   )r$   r@   r   r!  s       r'   r.  zTypedStorage._new_shared  sb    >Ff%..::4%%'' ; 
 (

d
 	
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'   r@   zTypedStorage.size  r  r)   c                X    | j                   j                         | j                         z  S r!   )r  r>   r5  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)r  rB   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'   rT   zTypedStorage.data_ptr  s    #%~~r)   c                6    | j                   j                         S r!   )r  rT   r-   s    r'   r%  zTypedStorage._data_ptr  s    $$--//r)   c                J    t                | j                  j                         S r!   )r  r  rV   r-   s    r'   rV   zTypedStorage.resizable  s    #%$$..00r)   c                :    t                | j                  |       y r!   )r  _resize_rr   s     r'   rs   zTypedStorage.resize_  s    #%dr)   c                \    | j                   j                  || j                         z         y r!   )r  rs   r5  rr   s     r'   r)  zTypedStorage._resize_  s$    %%dT-?-?-A&ABr)   c                ,    t        j                  |i |S r!   )r   r   rc   s      r'   r   zTypedStorage._free_weak_ref  s    ,,d=f==r)   c                :     | j                   j                  |i |S r!   )r  ru   r#   s      r'   ru   zTypedStorage._weak_ref  s     .t$$..???r)   c                :    t                 | j                  |i |S r!   )r  _from_bufferrc   s      r'   rd   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 rB      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   rH   r  r   rC   r  r   rd   r   r  )r]   rB   r   r%   r&   r!  s         r'   r.  zTypedStorage._from_buffer  s
   ,16E++-EE\\6>%vFF{{e#"I&++W  5:4H4H4T4T5"5&,5O
  CIN"N  !"N 
 JJE#22>>"&,O QUVVr)   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   rH   rB   r   rC   r   r   r   rI   r   rT   r   r   s      r'   r   zTypedStorage._to  s    %-HeVWWLL4::dkkBT$ZRY^	 	 0mmoGr)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.double      #%xx%%r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.float      #%xx$$r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.half      #%xx

##r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.long"  r7  r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.int'  s    #%xx		""r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.short,  r5  r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.char1  r7  r)   c                T    t                | j                  t        j                        S r   )r  r   rH   r   r-   s    r'   r   zTypedStorage.byte6  r5  r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.bool;  r7  r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.bfloat16@  s    #%xx''r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r	  r-   s    r'   r
  zTypedStorage.complex_doubleE  s    #%xx&&r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.complex_floatJ  r3  r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.float8_e5m2O  s    #%xx))**r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.float8_e4m3fnT  s    #%xx++,,r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.float8_e5m2fnuzY      #%xx--..r)   c                T    t                | j                  t        j                        S r  )r  r   rH   r  r-   s    r'   r  zTypedStorage.float8_e4m3fnuz^  rD  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   rH   r4  r5  rB   )r]   r   r   r@   r!  r   s         r'   r   zTypedStorage.from_filec  s^    ( 	$%,PQQ(22fdU\\%?%?		%JJ
 ?3r)   c                ,    t        j                  |i |S r!   )r   r   rc   s      r'   r   zTypedStorage._expired  s    &&777r)   c                :     | j                   j                  |i |S r!   )r  rp   r#   s      r'   rp   zTypedStorage._write_file  s     0t$$00$A&AAr)   c                :     | j                   j                  |i |S r!   )r  rw   r#   s      r'   rw   zTypedStorage._set_from_file       3t$$33TDVDDr)   c                :     | j                   j                  |i |S r!   )r  ry   r#   s      r'   ry   zTypedStorage._set_cdata  s     /t$$//@@@r)   c                :     | j                   j                  |i |S r!   )r  r{   r#   s      r'   r{   zTypedStorage._share_cuda_  s     1t$$114B6BBr)   c                6    t                | j                         S r!   )r  
_is_sharedr-   s    r'   r}   zTypedStorage.is_shared  s    #%  r)   c                6    | j                   j                         S r!   )r  r}   r-   s    r'   rN  zTypedStorage._is_shared  s    $$..00r)   c                @    t        j                  j                  |i |S r!   )rH   r   r   rc   s      r'   r   zTypedStorage._new_shared_cuda  s    ##44dEfEEr)   c                n     | j                   j                  |i |\  }}}|||| j                         z  fS r!   )r  rX   r5  )r$   r%   r&   manager_handlestorage_handler@   s         r'   rX   z!TypedStorage._share_filename_cpu_  sH    
 7D!!66GG		
~tt7I7I7K/KKKr)   c                :    | j                   j                          | S r!   )r  rn   r-   s    r'   rn   zTypedStorage._shared_decref  s    ,,.r)   c               @    t        j                  j                  |i |S r!   rH   r   rj   )r]   r   r%   r&   s       r'   _release_ipc_counterz!TypedStorage._release_ipc_counter      ##==tNvNNr)   c                :     | j                   j                  |i |S r!   )r  r   r#   s      r'   r   zTypedStorage._shared_incref  rJ  r)   c                j     | j                   j                  |i |\  }}||| j                         z  fS r!   )r  rZ   r5  )r$   r%   r&   fdr@   s        r'   rZ   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   rE   rM   )	rB   r  r   rC   rH   r)  r*  getattrAttributeError)r$   storage_namer  s      r'   r  z&TypedStorage._get_legacy_storage_class  s    ::79913DJJ?;;HH224	$
 
  [[%%.EGE4;;CSCS4T 		6<00 		s   ,B8 8	CCr?  )r;  r   )Fr!   )r8   r   r9   z_Optional[bool]r<  )rB   r=  r9   r  r;  z&Union[_StorageBase, TypedStorage, str])r   r   r9   r  r;  r   r:  r@  rA  )arB  rC  rD  r   rE  r   rG  r  r   r  r  r(   r   r   r0  r  r.   r  r5   r  r3   r  r:   r>   r  rC   rE   rM   rI   rO   r5  rR   r  r   r   r   r   r  r   r   r   r   r  r   r+  r  r.  r   r   r@   r  r  r  r   rT   r%  rV   rs   r)  rF  r   ru   rd   r.  r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r   r   rp   rw   ry   r{   r}   rN  r   rX   rn   rW  r   rZ   r  rH  rI  s   @r'   r   r     s
   Iu,0L)0  . .
 Z~ YVv ; ; : :%
<*4)! F"*2X
.
 !%"CC C 
0	C"76 @E 5$
62
.9K$
U4H

F

7
% +/ 

 , , , ,
F
+
K3
 
01
C > >@ 1 1 '+D W W>&
%
$
$
#
%
$
%
$
(
'
&
+
-
/
/
  8 8 8BEAC!
1 F FL 04 O OE0r)   c                      e Zd ZU ded<   d Zy)_LegacyStorageMetar  rB   c                    t        |      t        k(  rIt        | j                        }||j                  j                   k(  xr | j
                  |j
                  k(  S yr<  )rC   r   r  rC  r   rB   )r]   instancer  s      r'   __instancecheck__z$_LegacyStorageMeta.__instancecheck__  sM    >\)0@J(//"6"66 		X^^+ r)   N)rB  rC  rD  rE  rd  r"   r)   r'   ra  ra    s    r)   ra  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  )rH   r   r.  r5  )r]   r@   r!  s      r'   r.  z_LegacyStorage._new_shared  s5      ..::4#%BUBUBW;WX00r)   c                @    t        j                  j                  |i |S r!   rV  rc   s      r'   rW  z#_LegacyStorage._release_ipc_counter  rX  r)   c                    |t         j                  j                  | j                        z  } | t         j                  j                  |||            S )Nr  )rH   r4  r5  rB   r   rh   )r]   rf   rg   r@   
bytes_sizes        r'   _new_shared_filenamez#_LegacyStorage._new_shared_filename  sG    ELL66syyAA
--FFj
 	
r)   N)rB  rC  rD  rF  r.  rW  rj  r"   r)   r'   r  r    s>    1 1
 O O 
 
r)   r  )	metaclassc                `    	 t               |    S # t        $ r}t        d|  d      |d }~ww xY w)Nzpickle storage type "z" is not recognized)r  r!  )r  r"  s     r'   #_get_dtype_from_pickle_storage_typerm    sE    )+,?@@ #$7#88KL
	s    	-(-)r2  )r  r   )r  r   )A
__future__r   r  r	  rV  r   rM  r  typingr   r   r   _Dictr   	_Optionalr   r	   r
   typing_extensionsr   rH   torch._utilsr   r   torch.typesr   r   r   __all__numpyr  r  ModuleNotFoundErrorLockrL  r   rE  r   r   rX  r)  StorageBaser   r   	lru_cacherq  r  r  r  r  r  r  r  r  r  r  r   __doc__rC   rE   rM   rI   ra  r  rm  r"   r)   r'   <module>r|     s   #    	   X X X "  # , , +
,I $Y^^% 13 . 3C:;x" x"v!H@=UXX))< @=F9 T" #" T" #6 T" #
82" &+ ".5B(?| |~ "MM   (--55   '++33   ++ 	 	
\-? 
*q.  I	Bs   F6 6	GG