o
    *ôj5·  ã                   @   sì  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zd dlZdZW n eyX   dZY nw e ¡ Zi Zeeej f e!d< ed	d
d�Z"G dd„ dƒZ#dd„ Z$G dd„ dej%j&e#ƒZ'dd„ Z(ee#_)ee#_*ee#_+edd�dd„ ƒZ,edd�dd„ ƒZ-dd„ Z.dd„ Z/da0dd„ Z1d d!„ Z2d4d#d$„Z3d%d&„ Z4d'e5fd(d)„Z6G d*d+„ d+ƒZ7ej8e7j)_8ej8e7j*_8ej8e7j+_8G d,d-„ d-e)ƒZ9G d.d/„ d/e7e9d0�Z:d1e5fd2d3„Z;dS )5é    Né   )Ú_typeÚ_cudaÚ_hpu)ÚStorage)ÚcastÚAnyÚDictÚOptionalÚTypeVarÚTypeÚUnion)Ú	lru_cacheTÚ_share_memory_mapÚTz!Union[_StorageBase, TypedStorage])Úboundc                       sö  e Zd ZU eed< dZeed< dZeed< ej	ed< dd„ Z
defd	d
„Zdd„ Zdd„ Zd¥dedee defdd„Zdefdd„Zdefdd„Zdefdd„Zd¦dee dedefdd„Zd¦defdd„Zd¦defdd „Zdefd!d"„Zdefd#d$„Zdefd%d&„Zdefd'd(„Zd)d*„ Zd+d,„ Zed-e e d.edefd/d0„ƒZ!ed-e e d.edefd1d2„ƒZ"ed-e e defd3d4„ƒZ#eddd5œd-e e defd6d7„ƒZ$ed-e e defd8d9„ƒZ%ed-e e defd:d;„ƒZ&defd<d=„Z'd>d?„ Z(d.efd@dA„Z)defdBdC„Z*dDdE„ Z+dFdG„ Z,dHdI„ Z-defdJdK„Z.ed-e e defdLdM„ƒZ/dNdO„ Z0edPdQ„ ƒZ1e2dRdS„ ƒZ3e2dTdU„ ƒZ4edefdVdW„ƒZ5edefdXdY„ƒZ6dZd[„ Z7dee fd\d]„Z8d^d_„ Z9d`da„ Z:dbdc„ Z;ddde„ Z<dfdg„ Z=dhdi„ Z>‡ fdjdk„Z?dldm„ Z@dndo„ ZAdpdq„ ZBdrds„ ZCdtdu„ ZDdvdw„ ZEdxdy„ ZFdzd{„ ZGd|d}„ ZHd~d„ Zd€d�„ ZId‚dƒ„ ZJd„d…„ ZKd†d‡„ Zdˆd‰„ ZLdŠd‹„ ZMdŒd�„ ZNdŽd�„ ZOd�d‘„ ZPd’d“„ ZQd”d•„ ZRd§deSeej	f fd—d˜„ZTd§deSeej	f fd™dš„ZUd›dœ„ ZVed�džœdŸd „ƒZWd¡d¢„ ZXd£d¤„ ZY‡  ZZS )¨Ú_StorageBaseÚ_cdataFÚ	is_sparseÚis_sparse_csrÚdevicec                 O   ó   d S ©N© ©ÚselfÚargsÚkwargsr   r   ú`/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/storage.pyÚ__init__   ó    z_StorageBase.__init__Úreturnc                 C   r   r   r   ©r   r   r   r   Ú__len__   r    z_StorageBase.__len__c                 C   r   r   r   ©r   Úidxr   r   r   Ú__getitem__   r    z_StorageBase.__getitem__c                 O   r   r   r   r   r   r   r   Ú__setitem__    r    z_StorageBase.__setitem__NÚsourceÚnon_blockingc                 C   r   r   r   ©r   r(   r)   r   r   r   Úcopy_!   r    z_StorageBase.copy_c                 C   r   r   r   r"   r   r   r   Únew"   r    z_StorageBase.newc                 C   r   r   r   r"   r   r   r   Únbytes#   r    z_StorageBase.nbytesc                 C   ó   |   ¡ S r   )r-   r"   r   r   r   Úsize%   ó   z_StorageBase.sizeÚdtypec                 C   r   r   r   )r   r1   r)   r   r   r   Útype(   r    z_StorageBase.typec                 K   r   r   r   ©r   r   r)   r   r   r   r   Úcuda)   r    z_StorageBase.cudac                 K   r   r   r   r3   r   r   r   Úhpu*   r    z_StorageBase.hpuc                 C   r   r   r   r"   r   r   r   Úelement_size+   r    z_StorageBase.element_sizec                 C   ó   | j jS r   )r   Úindexr"   r   r   r   Ú
get_device-   r0   z_StorageBase.get_devicec                 C   r   r   r   r"   r   r   r   Údata_ptr0   r    z_StorageBase.data_ptrc                 C   r   r   r   r"   r   r   r   Ú	resizable2   r    z_StorageBase.resizablec                 O   r   r   r   r   r   r   r   Ú_share_filename_cpu_5   r    z!_StorageBase._share_filename_cpu_c                 O   r   r   r   r   r   r   r   Ú_share_fd_cpu_6   r    z_StorageBase._share_fd_cpu_Úclsr/   c                 C   r   r   r   ©r>   r/   r   r   r   Ú_new_using_filename_cpu7   ó   z$_StorageBase._new_using_filename_cpuc                 C   r   r   r   r?   r   r   r   Ú_new_using_fd_cpu9   rA   z_StorageBase._new_using_fd_cpuc                 O   r   r   r   ©r>   r   r   r   r   r   Úfrom_buffer;   rA   z_StorageBase.from_buffer)r   r1   c                C   r   r   r   )r>   ÚmanagerÚobjr/   r   r1   r   r   r   Ú_new_shared_filename_cpu=   rA   z%_StorageBase._new_shared_filename_cpuc                 O   r   r   r   rC   r   r   r   Ú_release_ipc_counter_cuda?   rA   z&_StorageBase._release_ipc_counter_cudac                 O   r   r   r   rC   r   r   r   Ú_new_with_weak_ptrA   rA   z_StorageBase._new_with_weak_ptrc                 C   r   r   r   r"   r   r   r   Ú_shared_decrefC   r    z_StorageBase._shared_decrefc                 O   r   r   r   r   r   r   r   Ú_write_fileD   r    z_StorageBase._write_filec                 C   r   r   r   ©r   r/   r   r   r   Úresize_E   r    z_StorageBase.resize_c                 O   r   r   r   r   r   r   r   Ú	_weak_refF   r    z_StorageBase._weak_refc                 O   r   r   r   r   r   r   r   Ú_set_from_fileG   r    z_StorageBase._set_from_filec                 O   r   r   r   r   r   r   r   Ú
_set_cdataH   r    z_StorageBase._set_cdatac                 O   r   r   r   r   r   r   r   Ú_share_cuda_I   r    z_StorageBase._share_cuda_c                 C   r   r   r   r"   r   r   r   Ú	is_sharedJ   r    z_StorageBase.is_sharedc                 O   r   r   r   rC   r   r   r   Ú_new_shared_cudaK   rA   z_StorageBase._new_shared_cudac                 O   r   r   r   r   r   r   r   Ú_shared_increfM   r    z_StorageBase._shared_increfc                 O   r   r   r   rC   r   r   r   Ú_free_weak_refN   rA   z_StorageBase._free_weak_refc                 C   r   r   r   r"   r   r   r   Úis_cudaP   rA   z_StorageBase.is_cudac                 C   r   r   r   r"   r   r   r   Úis_hpuR   rA   z_StorageBase.is_hpuc                 C   r   r   r   )r>   ÚfilenameÚsharedr-   r   r   r   Ú	from_fileT   rA   z_StorageBase.from_filec                 O   r   r   r   rC   r   r   r   Ú_expiredV   rA   z_StorageBase._expiredc                 O   r   r   r   r   r   r   r   Ú	_byteswapX   r    z_StorageBase._byteswapc                 O   r   r   r   r   r   r   r   Ú_get_filenameY   r    z_StorageBase._get_filenamec                    sh   dt  ˆ ¡› dˆ j› dtˆ ƒ› d�}ˆ jjdkrd| S dd ‡ fd	d
„tˆ  ¡ ƒD ƒ¡ }|d | S )Nú[z(device=ú
) of size ú]Úmetaú...
ú ú
 c                 3   ó   � | ]	}t ˆ | ƒV  qd S r   ©Ústr©Ú.0Úir"   r   r   Ú	<genexpr>b   ó   € z'_StorageBase.__str__.<locals>.<genexpr>Ú
)ÚtorchÚtypenamer   Úlenr2   ÚjoinÚranger/   ©r   Zinfo_strZdata_strr   r"   r   Ú__str__[   s   ÿÿ$z_StorageBase.__str__c                 C   ó   t | ƒS r   rf   r"   r   r   r   Ú__repr__e   r0   z_StorageBase.__repr__c                    s   t ‡ fdd„tˆ  ¡ ƒD ƒƒS )Nc                 3   ó   � | ]}ˆ | V  qd S r   r   rh   r"   r   r   rk   i   ó   € z(_StorageBase.__iter__.<locals>.<genexpr>)Úiterrr   r/   r"   r   r"   r   Ú__iter__h   s   z_StorageBase.__iter__c                 C   r.   r   )Úcloner"   r   r   r   Ú__copy__k   r0   z_StorageBase.__copy__c                 C   s6   |  di ¡}| j|v r|| j S |  ¡ }||| j< |S )Nrn   )Ú
setdefaultr   r{   )r   ÚmemoÚnew_storager   r   r   Ú__deepcopy__n   s   


z_StorageBase.__deepcopy__c                 C   ó&   t  ¡ }tj| |dd� t| ¡ ffS ©NF)Z_use_new_zipfile_serialization©ÚioÚBytesIOrn   ÚsaveÚ_load_from_bytesÚgetvalue©r   Úbr   r   r   Ú
__reduce__v   ó   z_StorageBase.__reduce__c                    s   t ƒ  ¡ |  ¡  S r   )ÚsuperÚ
__sizeof__r/   r"   ©Ú	__class__r   r   rŽ   {   ó   z_StorageBase.__sizeof__c                 C   s   t | ƒ|  ¡ | jd� | ¡S )úReturn a copy of this storage.©r   )r2   r-   r   r+   r"   r   r   r   r{   ~   s   z_StorageBase.clonec                 C   ru   ©z6Return a list containing the elements of this storage.)Úlistr"   r   r   r   Útolist‚   ó   z_StorageBase.tolistc                 C   s&   | j jdkrt |  ¡ ¡ | d¡S | S )úAReturn a CPU copy of this storage if it's not already on the CPU.ÚcpuF©r   r2   rn   ÚUntypedStorager/   r+   r"   r   r   r   r™   †   s   z_StorageBase.cpuc                 C   s*   | j jdkrtj|  ¡ dd� | d¡S | S )zAReturn a MPS copy of this storage if it's not already on the MPS.Úmpsr“   Frš   r"   r   r   r   rœ   �   s   z_StorageBase.mpsc                 C   sd   t |tjƒstdt|ƒ› �ƒ‚tjg tj| jd� t	t
| ƒ¡ |¡ ¡ }| ¡ |  ¡ kr0| ¡ }|S ©Nz*Argument 'dtype' must be torch.dtype, not ©r1   r   )Ú
isinstancern   r1   Ú	TypeErrorr2   ÚtensorÚuint8r   Úset_r   r   ÚtoÚ_typed_storager:   r{   ©r   r1   Ústorager   r   r   Ú_to”   s   *z_StorageBase._toc                 C   ó   |   tj¡S ©z"Casts this storage to double type.)r¨   rn   Údoubler"   r   r   r   r«   œ   ó   z_StorageBase.doublec                 C   r©   ©z!Casts this storage to float type.)r¨   rn   Úfloatr"   r   r   r   r®       r¬   z_StorageBase.floatc                 C   r©   ©z Casts this storage to half type.)r¨   rn   Úhalfr"   r   r   r   r°   ¤   r¬   z_StorageBase.halfc                 C   r©   ©z Casts this storage to long type.)r¨   rn   Úlongr"   r   r   r   r²   ¨   r¬   z_StorageBase.longc                 C   r©   ©zCasts this storage to int type.)r¨   rn   Úintr"   r   r   r   r´   ¬   r¬   z_StorageBase.intc                 C   r©   ©z!Casts this storage to short type.)r¨   rn   Úshortr"   r   r   r   r¶   °   r¬   z_StorageBase.shortc                 C   r©   ©z Casts this storage to char type.)r¨   rn   Úint8r"   r   r   r   Úchar´   r¬   z_StorageBase.charc                 C   r©   ©z Casts this storage to byte type.)r¨   rn   r¢   r"   r   r   r   Úbyte¸   r¬   z_StorageBase.bytec                 C   r©   ©z Casts this storage to bool type.)r¨   rn   Úboolr"   r   r   r   r½   ¼   r¬   z_StorageBase.boolc                 C   r©   ©z$Casts this storage to bfloat16 type.)r¨   rn   Úbfloat16r"   r   r   r   r¿   À   r¬   z_StorageBase.bfloat16c                 C   r©   ©z*Casts this storage to complex double type.)r¨   rn   Úcdoubler"   r   r   r   Úcomplex_doubleÄ   r¬   z_StorageBase.complex_doublec                 C   r©   ©z)Casts this storage to complex float type.)r¨   rn   Úcfloatr"   r   r   r   Úcomplex_floatÈ   r¬   z_StorageBase.complex_floatc                 C   r©   ©z&Casts this storage to float8_e5m2 type)r¨   rn   Úfloat8_e5m2r"   r   r   r   rÇ   Ì   r¬   z_StorageBase.float8_e5m2c                 C   r©   ©z(Casts this storage to float8_e4m3fn type)r¨   rn   Úfloat8_e4m3fnr"   r   r   r   rÉ   Ð   r¬   z_StorageBase.float8_e4m3fnc                 C   r©   ©z*Casts this storage to float8_e5m2fnuz type)r¨   rn   Úfloat8_e5m2fnuzr"   r   r   r   rË   Ô   r¬   z_StorageBase.float8_e5m2fnuzc                 C   r©   ©z*Casts this storage to float8_e4m3fnuz type)r¨   rn   Úfloat8_e4m3fnuzr"   r   r   r   rÍ   Ø   r¬   z_StorageBase.float8_e4m3fnuzr4   c                 C   s&   t jg t j| jd� tt| ƒ¡ |¡S )zäDetermine 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ž   )rn   r¡   r¢   r   r£   r   r   Ú	is_pinned©r   r   r   r   r   rÎ   Ü   s
   	ÿÿz_StorageBase.is_pinnedc                 C   sN   | j jdkrtd|  ¡ › d�ƒ‚tjg tj| j d� tt| ƒ¡ 	|¡}| 
¡ S )zêCopy 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   r2   r    rn   r¡   r¢   r£   r   r   Ú
pin_memoryÚuntyped_storage)r   r   Zpinned_tensorr   r   r   rÐ   è   s   	ÿÿz_StorageBase.pin_memoryc                 C   sJ   ddl m} | jjdtj ¡ fv r	 | S |ƒ dkr|  ¡  | S |  ¡  | S )ú.See :meth:`torch.UntypedStorage.share_memory_`r   ©Úget_sharing_strategyr4   Úfile_system)	Útorch.multiprocessingrÔ   r   r2   rn   Ú_CÚ_get_privateuse1_backend_namer<   r=   )r   rÔ   r   r   r   Úshare_memory_ø   s   
üÿz_StorageBase.share_memory_r™   r“   c                C   sV   ddl m} t |¡}|jdtj ¡ dfv r| ||d�S |ƒ dkr&|  |¡S |  |¡S )ú>Create a new storage in shared memory with the same data type.r   rÓ   r4   r5   r“   rÕ   )	rÖ   rÔ   rn   r   r2   r×   rØ   r@   rB   )r>   r/   r   rÔ   r   r   r   Ú_new_shared  s   



z_StorageBase._new_sharedc                 C   s   | S r   r   r"   r   r   r   Úuntyped  rA   z_StorageBase.untypedc                 C   s2   t j |¡}|jrtt|d ƒdƒ}|  |¡ dS )zSwap bytes in underlying data.é   r   N)rn   Ú_utilsÚ_element_sizeÚ
is_complexÚmaxr´   r\   )r   r1   Z	elem_sizer   r   r   Úbyteswap  s   z_StorageBase.byteswapr   ©NF©r4   )[Ú__name__Ú
__module__Ú__qualname__r   Ú__annotations__r   r½   r   rn   r   r   r´   r#   r&   r'   r   Ú	_Optionalr+   r,   r-   r/   rg   r2   r4   r5   r6   r9   r:   r;   r<   r=   Úclassmethodr   r@   rB   rD   rG   rH   rI   rJ   rK   rM   rN   rO   rP   rQ   rR   rS   rT   rU   ÚpropertyrV   rW   rZ   r[   r\   r]   rt   rv   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â   Ú__classcell__r   r   r�   r   r      s¸   
 
 



r   c                    s   t  ˆ ¡‡ fdd„ƒ}|S )Nc                    sB  d }d }t �" | j}|tv rt| }nt ¡ t|< t|  ¡  |}W d   ƒ n1 s+w   Y  |d urF|� W d   ƒ n1 sAw   Y  z3ˆ | g|¢R i |¤ŽW |d ury| j|ks]J ‚t � t|  ¡  t|= W d   ƒ S 1 ssw   Y  S S |d ur | j|ks…J ‚t � t|  ¡  t|= W d   ƒ w 1 s›w   Y  w r   )Ú_share_memory_lockr   r   Ú	threadingÚRLockÚacquireÚrelease)r   r   r   Zto_freeZto_waitÚkey©Úfnr   r   Úwrapper  s:   
€ùÿþ
üþz-_share_memory_lock_protected.<locals>.wrapper)Ú	functoolsÚwraps)rô   rõ   r   ró   r   Ú_share_memory_lock_protected  s   rø   c                       sz   e Zd Z‡ fdd„Zedd„ ƒZedd„ ƒZedee fdd	„ƒZ	e
‡ fd
d„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZ‡  ZS )r›   c                    s&   | j jdkr
tdƒ‚tƒ j|i |¤ŽS )Nra   ú$Not available for 'meta' device type)r   r2   ÚNotImplementedErrorr�   r&   r   r�   r   r   r&   >  s   zUntypedStorage.__getitem__c                 C   ó   | j jdkS ©Nr4   ©r   r2   r"   r   r   r   rV   C  r¬   zUntypedStorage.is_cudac                 C   rû   ©Nr5   rý   r"   r   r   r   rW   G  r¬   zUntypedStorage.is_hpur!   c                 C   r.   ©z°Returns 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   r   r   rX   K  ó   zUntypedStorage.filenamec                    ó   t ƒ j|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   r�   r   r   rÙ   Q  s   !zUntypedStorage.share_memory_c                    r  r   )r�   r=   r   r�   r   r   r=   t  ó   zUntypedStorage._share_fd_cpu_c                    r  r   )r�   r<   r   r�   r   r   r<   x  r  z#UntypedStorage._share_filename_cpu_)rå   ræ   rç   r&   rë   rV   rW   ré   rg   rX   rø   rÙ   r=   r<   rì   r   r   r�   r   r›   =  s    

"r›   c                 C   s   t  t | ¡¡S r   )rn   Úloadr„   r…   )rŠ   r   r   r   r‡   |  s   r‡   )Úmaxsizec                   C   sŒ   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)rn   r«   r®   r°   r²   r´   Úint16r¸   r¢   r½   r¿   rÁ   rÄ   Úqint8Úqint32Úquint8Úquint4x2Úquint2x4r   r   r   r   Ú_dtype_to_storage_type_map…  sF   ÿþýüûúùø	÷
öõôóòñðïr  c                  C   s   dd„ t ƒ  ¡ D ƒ} | S )Nc                 S   s   i | ]\}}||“qS r   r   )ri   rò   Úvalr   r   r   Ú
<dictcomp>¢  s    
ÿz._storage_type_to_dtype_map.<locals>.<dictcomp>)r  Úitems)Z	dtype_mapr   r   r   Ú_storage_type_to_dtype_map   s   ÿr   c              
   C   sx   |t jt jt jt jt jfv r/t jt jt jt jt jt jt jt jt jt ji}t j	| || |d�}nt j	| ||d�}| 
¡ jS )Nrž   )rn   r  r  r  r  r  r¢   Úint32r¸   r¡   r¥   Ú_untyped_storage)Úsequencer1   r   Úinterpret_dtypesÚ
tmp_tensorr   r   r   Ú_get_storage_from_sequence¦  s$   ûýý
r&  c                 C   s   t r
t| ttjfƒS t| tƒS r   )Ú	HAS_NUMPYrŸ   r´   ÚnpÚinteger)Úxr   r   r   Ú_isint¼  s   
r+  Fc                   C   s   t S r   )Ú"_always_warn_typed_storage_removalr   r   r   r   Ú&_get_always_warn_typed_storage_removalÄ  rA   r-  c                 C   s   t | tƒsJ ‚| ad S r   )rŸ   r½   r,  )Zalways_warnr   r   r   Ú&_set_always_warn_typed_storage_removalÇ  s   r.  rÝ   c                 C   s>   dd„ }t ƒ s
|ƒ rd}tj|t| d d� dtjd< d S d S )Nc                   S   s   t tdƒsdS tjd  S )NÚ
has_warnedT)ÚhasattrÚ_warn_typed_storage_removalÚ__dict__r   r   r   r   Úis_first_timeÏ  s   
z2_warn_typed_storage_removal.<locals>.is_first_timea  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ÚUserWarningr1  r2  )r4  r3  Úmessager   r   r   r1  Ì  s   ÿør1  c                   C   s   dt jd< d S )NFr/  )r1  r2  r   r   r   r   Ú!_reset_warn_typed_storage_removalß  ó   r9  Úmodulec                 C   s,   |   dd¡d }|dtj ¡ dfv r|S dS )NÚ.r   éÿÿÿÿr4   r5   r™   )Úrsplitrn   r×   rØ   )r;  Z	last_partr   r   r   Ú_get_device_from_moduleâ  s   r?  c                	       s²  e Zd ZU dZejed< edd„ ƒZede	e
 fdd„ƒZdd	„ Zd
d
d
ddœ‡ fdd„
Zd
d
d
ddœdd„Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zd»dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd¼d%ed&e	e fd'd(„Zd)d*„ Zd+d,„ Zd½de	e
 d&edeee
f fd-d.„Zd½defd/d0„Z d½defd1d2„Z!d3d4„ Z"d5d6„ Z#de$fd7d8„Z%d9d:„ Z&d;d<„ Z'd=d>„ Z(d?d@„ Z)dAdB„ Z*dCdD„ Z+‡ fdEdF„Z,dGdH„ Z-dIdJ„ Z.dKdL„ Z/d¾dNee
ej0f fdOdP„Z1d¾dNee
ej0f fdQdR„Z2dSdT„ Z3dUdV„ Z4d
dWœdXdY„Z5edZd[„ ƒZ6ed\d]„ ƒZ0d^d_„ Z7d`da„ Z8dbdc„ Z9ddde„ Z:dfdg„ Z;dhdi„ Z<djdk„ Z=dldm„ Z>dndo„ Z?dpdq„ Z@eAdrds„ ƒZBdtdu„ ZCeAdvdw„ ƒZDeAd
d
dxœdydz„ƒZEd{d|„ ZFd}d~„ ZGdd€„ ZHd�d‚„ ZIdƒd„„ ZJd…d†„ Z$d‡dˆ„ ZKd‰dŠ„ ZLd‹dŒ„ ZMd�dŽ„ Zd�d�„ ZNd‘d’„ ZOd“d”„ ZPd•d–„ ZQd—d˜„ ZRd™dš„ ZSd›dœ„ ZTeAd�dž„ ƒZUeAdŸd „ ƒZVd¡d¢„ ZWd£d¤„ ZXd¥d¦„ ZYd§d¨„ ZZd©dª„ Z[d«d¬„ Z\eAd­d®„ ƒZ]d¯d°„ Z^d±d²„ Z_eAd
dWœd³d´„ƒZ`dµd¶„ Zad·d¸„ Zbd¹dº„ Zc‡  ZdS )¿ÚTypedStorageFr1   c                 C   s   | j S r   )r1   r"   r   r   r   Ú_dtypeî  s   zTypedStorage._dtyper!   c                 C   r7   rÿ   )r"  rX   r"   r   r   r   rX   ò  r   zTypedStorage.filenamec                 C   s    t ƒ  |  td|  ¡ ƒ|¡ | S )Nr   )r1  Ú_setitemÚsliceÚ_size)r   Úvaluer   r   r   Úfill_ø  s   zTypedStorage.fill_N)Úwrap_storager1   r   Ú	_internalc                   sb  |st ƒ  | tjjkrtdƒ‚| tkrtƒ  | ¡S | › d�}|d ur(t|d ƒ‚|d ur2t|d ƒ‚|d u rqt|ƒdkrBt|d ƒ‚t|ƒdkrdt	|d ƒsdt
|d tjjƒsdt|dt|d ƒ› � ƒ‚t|| jt| jƒd	d
œŽS t|ƒdkr}t|d ƒ‚t
|tjƒsŽt|dt|ƒ› � ƒ‚t| jƒ}|jj|kr§t|d|› d|jj› � ƒ‚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)r1   r   rH  ú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 ©rG  r1   rH  )r1  rn   r§   Ú_LegacyStorageÚRuntimeErrorr@  r�   Ú__new__rp   r+  rŸ   ÚcollectionsÚabcÚSequencer    r2   rA  r?  ræ   r›   r   r1   )r>   rG  r1   r   rH  r   Úarg_error_msgÚ
cls_devicer�   r   r   rP  ý  s„   ÿÿÿÿÿÿÿ*ÿÿüÿÿÿÿ
ÿÿÿüzTypedStorage.__new__)r   r1   rG  rH  c                G   s°  |st ƒ  d}|d urUt|ƒdkrt|d ƒ‚|d u r!t|d ƒ‚t|tjƒs2t|dt|ƒ› � ƒ‚|d ur<t|d ƒ‚|| _t|tjƒsPt|dt|ƒ› � ƒ‚|| _	d S |d u r]t 
¡ n|| _t |d u rhd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|d�| _	d S t|ƒdkrÒt|d ƒr°tjt|d ƒ|  ¡  |d�| _	d S t|d tjjƒrÅt|d | j|ƒ| _	d S t|dt|d ƒ› � ƒ‚t|d ƒ‚)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   rK  z#
Argument 'dtype' must be specifiedz+
Argument 'dtype' must be torch.dtype, not zG
Argument 'device' should not be specified when 'wrap_storage' is givenrL  r™   r4   ú/Cannot create CUDA storage with quantized dtyper“   r   rJ  rI  )r1  rp   rO  rŸ   rn   r1   r    r2   r›   r"  Úget_default_dtyper   r  r  r  r  r  r+  r´   rß   rQ  rR  rS  r&  )r   r   r1   rG  rH  r   rT  r   r   r   r   E  sv   ÿÿÿÿÿÿÿÿÿÿÿ

$ÿÿÿÿzTypedStorage.__init__c                 C   ó   t ƒ  | jjjdkS rü   ©r1  r"  r   r2   r"   r   r   r   rV   ‰  ó   zTypedStorage.is_cudac                 C   rX  rþ   rY  r"   r   r   r   rW   Ž  rZ  zTypedStorage.is_hpuc                 C   s   t ƒ  | jS )z2Return the internal :class:`torch.UntypedStorage`.)r1  r"  r"   r   r   r   rÜ   “  s   zTypedStorage.untypedc                 C   s<   t |ƒtjks	J ‚t | ƒtkrt|| jdd�S t | ƒ|d�S )NTrM  ©rG  )r2   rn   r›   r@  r1   )r   rÑ   r   r   r   Ú_new_wrapped_storage˜  s   ýz!TypedStorage._new_wrapped_storagec                 C   ó   t ƒ  |  ¡ S r   ©r1  rD  r"   r   r   r   r#   £  ó   zTypedStorage.__len__c                 C   sÌ   |d u r|r
|   ¡ S dS t|ƒtkr tdt| ƒ› dt|ƒ› �ƒ‚|rG||   ¡ ks/||   ¡  k r;td|› d|  ¡ › �ƒ‚|dkrA|S ||   ¡  S ||   ¡ ksT||   ¡  k r`td|› d|  ¡ › �ƒ‚||   ¡  S )Nr   úcan't index a ú with zindex z" out of range for storage of size )rD  r2   r´   r    Ú
IndexErrorr/   )r   r%   Zis_stopr   r   r   Ú_maybe_wrap_index§  s*   ÿÿÿzTypedStorage._maybe_wrap_indexc                 C   s   t ƒ  |  ||¡S r   )r1  rB  )r   r%   rE  r   r   r   r'   À  s   zTypedStorage.__setitem__c              
   C   sî   t |ttfƒstdt| ƒ› dt|ƒ› �ƒ‚t |¡r#tdt|ƒ› �ƒ‚| jtjtj	tj
tjtjfv rct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d�}| t| j|dd�¡ ntjg | j| jjd� | ¡}|||< d S )Nr`  ra  z cannot set item with value type rž   TrM  )rŸ   r´   rC  rO  r2   rn   Ú
is_storager1   r  r  r  r  r  r¢   r!  r¸   r¡   r"  r   r£   r@  )r   r%   rE  r$  Z	tmp_dtyper%  r   r   r   rB  Ä  s(   
û

ýzTypedStorage._setitemc                 C   ó   t ƒ  |  |¡S r   )r1  Ú_getitemr$   r   r   r   r&   Ü  ó   
zTypedStorage.__getitem__c              
   C   s  | 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 rZt	j
t	jt	jt	jt	jt	jt	jt	jt	jt	ji}t| j || j dd� |¡S |  |¡}dd	lm} |ƒ � t	jg | j| j jd
� | ¡}||  ¡ W  d   ƒ S 1 s‡w   Y  d S )Nra   rù   z7slices are only supported in UntypedStorage.__getitem__r`  ra  TrM  r   )Úunset_fake_temporarilyrž   )r"  r   r2   rú   rŸ   rC  rO  r´   r1   rn   r  r  r  r  r  r¢   r!  r¸   r@  rf  rc  Ztorch._subclasses.fake_tensorrh  r¡   r£   Úitem)r   r%   r$  Zidx_wrappedrh  r%  r   r   r   rf  à  s4   

ûýý

$þzTypedStorage._getitemr(   r)   c                 C   s6   t ƒ  t|tƒr| j |j|¡ | S | j ||¡ | S r   )r1  rŸ   r@  r"  r+   r*   r   r   r   r+     s   
ÿzTypedStorage.copy_c                 C   r]  r   )r1  Ú_nbytesr"   r   r   r   r-   	  r_  zTypedStorage.nbytesc                 C   ó
   | j  ¡ S r   )r"  r-   r"   r   r   r   rj    ó   
zTypedStorage._nbytesc                 C   sR   t ƒ  |d u r"|  ¡ }|d ur|jd |j S d | jt| ƒjg¡S | j ||¡S )Nr<  )r1  Ú_get_legacy_storage_classræ   rå   rq   r2   r"  )r   r1   r)   Zlegacy_classr   r   r   r2     s   zTypedStorage.typec                 K   óL   t ƒ  | jtjtjtjtjtjfv rtdƒ‚| j	j
||fi |¤Ž}|  |¡S )NrV  )r1  r1   rn   r  r  r  r  r  rO  r"  r4   r\  )r   r   r)   r   Zcuda_storager   r   r   r4     ó
   
zTypedStorage.cudac                 K   rn  )Nz.Cannot create HPU storage with quantized dtype)r1  r1   rn   r  r  r  r  r  rO  r"  r5   r\  )r   r   r)   r   Zhpu_storager   r   r   r5   %  ro  zTypedStorage.hpuc                 C   r]  r   )r1  rß   r"   r   r   r   r6   ,  r_  zTypedStorage.element_sizec                 C   s   t j | j¡S r   )rn   rÞ   rß   r1   r"   r   r   r   rß   1  r:  zTypedStorage._element_sizec                 C   ó   t ƒ  | j ¡ S r   )r1  r"  r9   r"   r   r   r   r9   4  rg  zTypedStorage.get_devicec              	      sv   t ƒ  dt ˆ ¡› dˆ j› dˆ j› dtˆ ƒ› d�	}ˆ jjdkr#d| S dd	 ‡ fd
d„tˆ  	¡ ƒD ƒ¡ }|d | S )Nr^   z(dtype=z	, device=r_   r`   ra   rb   rc   rd   c                 3   re   r   rf   rh   r"   r   r   rk   @  rl   z'TypedStorage.__str__.<locals>.<genexpr>rm   )
r1  rn   ro   r1   r   rp   r2   rq   rr   r/   rs   r   r"   r   rt   8  s   ÿÿÿ$zTypedStorage.__str__c                 C   ó   t ƒ  t| ƒS r   )r1  rg   r"   r   r   r   rv   C  r_  zTypedStorage.__repr__c                    s$   t ƒ  t‡ fdd„tˆ  ¡ ƒD ƒƒS )Nc                 3   rw   r   r   rh   r"   r   r   rk   I  rx   z(TypedStorage.__iter__.<locals>.<genexpr>)r1  ry   rr   r/   r"   r   r"   r   rz   G  s   zTypedStorage.__iter__c                 C   s   t ƒ  |  t | j¡¡S r   )r1  r\  Úcopyr"  r"   r   r   r   r|   K  ó   zTypedStorage.__copy__c                 C   re  r   )r1  Ú	_deepcopy©r   r~   r   r   r   r€   O  rg  zTypedStorage.__deepcopy__c                 C   s   |   t | j|¡¡S r   )r\  rr  Údeepcopyr"  ru  r   r   r   rt  T  s   zTypedStorage._deepcopyc                    s   t ƒ  tƒ  ¡ |  ¡  S r   )r1  r�   rŽ   r-   r"   r�   r   r   rŽ   W  rs  zTypedStorage.__sizeof__c                 C   ó   t ƒ  |  | j ¡ ¡S )r’   )r1  r\  r"  r{   r"   r   r   r   r{   [  ó   zTypedStorage.clonec                 C   rq  r”   )r1  r•   r"   r   r   r   r–   `  ó   zTypedStorage.tolistc                 C   rw  )r˜   )r1  r\  r"  r™   r"   r   r   r   r™   e  rx  zTypedStorage.cpur4   r   c                 C   s   t ƒ  | j |¡S )zèDetermine 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.
        )r1  r"  rÎ   rÏ   r   r   r   rÎ   j  s   	zTypedStorage.is_pinnedc                 C   s   t ƒ  |  | jj|d�¡S )zïCopy 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“   )r1  r\  r"  rÐ   rÏ   r   r   r   rÐ   v  s   	zTypedStorage.pin_memoryc                 C   r]  )rÒ   )r1  Ú_share_memory_r"   r   r   r   rÙ   ‚  ry  zTypedStorage.share_memory_c                 C   ó   | j  ¡  | S r   )r"  rÙ   r"   r   r   r   rz  ˆ  ó   
zTypedStorage._share_memory_r“   c                C   s>   |du rd}t  |¡}t jj||  ¡  |d�}t|| jdd�S )rÚ   Nr™   r“   TrM  )rn   r   r›   rÛ   rß   r@  r1   )r   r/   r   rÑ   r   r   r   rÛ   Œ  s   
ýzTypedStorage._new_sharedc                 C   r7   r   )r"  r   r"   r   r   r   r   —  r—   zTypedStorage._cdatac                 C   s   t ƒ  | jjS r   )r1  r"  r   r"   r   r   r   r   ›  ry  zTypedStorage.devicec                 C   r]  r   r^  r"   r   r   r   r/      r_  zTypedStorage.sizec                 C   s   | j  ¡ |  ¡  S r   )r"  r-   rß   r"   r   r   r   rD  ¥  s   zTypedStorage._sizec                 C   r]  r   )r1  Ú_pickle_storage_typer"   r   r   r   Úpickle_storage_typeª  r_  z TypedStorage.pickle_storage_typec              
   C   s<   zt ƒ | j W S  ty } z
td| j› d�ƒ|‚d }~ww )Nzdtype z is not recognized)r  r1   ÚKeyError)r   Úer   r   r   r}  ¯  s   €ÿz!TypedStorage._pickle_storage_typec                 C   r�   r‚   rƒ   r‰   r   r   r   r‹   µ  rŒ   zTypedStorage.__reduce__c                 C   r]  r   )r1  Ú	_data_ptrr"   r   r   r   r:   º  r_  zTypedStorage.data_ptrc                 C   rk  r   )r"  r:   r"   r   r   r   r�  ¿  rl  zTypedStorage._data_ptrc                 C   rp  r   )r1  r"  r;   r"   r   r   r   r;   Â  rg  zTypedStorage.resizablec                 C   s   t ƒ  |  |¡ d S r   )r1  Ú_resize_rL   r   r   r   rM   Æ  s   zTypedStorage.resize_c                 C   s   | j  ||  ¡  ¡ d S r   )r"  rM   rß   rL   r   r   r   r‚  Ë  s   zTypedStorage._resize_c                 O   ó   t j|i |¤ŽS r   )r›   rU   rC   r   r   r   rU   Î  ó   zTypedStorage._free_weak_refc                 O   ó   | j j|i |¤ŽS r   )r"  rN   r   r   r   r   rN   Ò  r‘   zTypedStorage._weak_refc                 O   s   t ƒ  | j|i |¤ŽS r   )r1  Ú_from_bufferrC   r   r   r   rD   Õ  rx  zTypedStorage.from_bufferrž   c                O   sº   | t kr2|d u rt ¡ n|}t |d u rdn|¡}|jdkr&td|j› �ƒ‚tjj|d|i|¤Ž}n$|d us<t|ƒdkr@tdƒ‚|d urHtdƒ‚| j	}tjj|d|i|¤Ž}t ||dd�S )	Nr™   z3TypedStorage.from_buffer: Not available for device r1   é   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_bufferTrM  )
r@  rn   rW  r   r2   rO  r›   rD   rp   rA  )r>   r1   r   r   r   rÑ   r   r   r   r†  Ú  s*   
ÿÿýzTypedStorage._from_bufferc                 C   s^   t |tjƒstdt|ƒ› �ƒ‚tjg | j| jd� | ¡ |¡ 	¡ }| 
¡ |  
¡ kr-| ¡ }|S r�   )rŸ   rn   r1   r    r2   r¡   r   r£   r¤   r¥   r:   r{   r¦   r   r   r   r¨   õ  s   $zTypedStorage._toc                 C   ó   t ƒ  |  tj¡S rª   )r1  r¨   rn   r«   r"   r   r   r   r«   ý  ó   zTypedStorage.doublec                 C   rˆ  r­   )r1  r¨   rn   r®   r"   r   r   r   r®     r‰  zTypedStorage.floatc                 C   rˆ  r¯   )r1  r¨   rn   r°   r"   r   r   r   r°     r‰  zTypedStorage.halfc                 C   rˆ  r±   )r1  r¨   rn   r²   r"   r   r   r   r²     r‰  zTypedStorage.longc                 C   rˆ  r³   )r1  r¨   rn   r´   r"   r   r   r   r´     r‰  zTypedStorage.intc                 C   rˆ  rµ   )r1  r¨   rn   r¶   r"   r   r   r   r¶     r‰  zTypedStorage.shortc                 C   rˆ  r·   )r1  r¨   rn   r¸   r"   r   r   r   r¹     r‰  zTypedStorage.charc                 C   rˆ  rº   )r1  r¨   rn   r¢   r"   r   r   r   r»      r‰  zTypedStorage.bytec                 C   rˆ  r¼   )r1  r¨   rn   r½   r"   r   r   r   r½   %  r‰  zTypedStorage.boolc                 C   rˆ  r¾   )r1  r¨   rn   r¿   r"   r   r   r   r¿   *  r‰  zTypedStorage.bfloat16c                 C   rˆ  rÀ   )r1  r¨   rn   rÁ   r"   r   r   r   rÂ   /  r‰  zTypedStorage.complex_doublec                 C   rˆ  rÃ   )r1  r¨   rn   rÄ   r"   r   r   r   rÅ   4  r‰  zTypedStorage.complex_floatc                 C   rˆ  rÆ   )r1  r¨   rn   rÇ   r"   r   r   r   rÇ   9  r‰  zTypedStorage.float8_e5m2c                 C   rˆ  rÈ   )r1  r¨   rn   rÉ   r"   r   r   r   rÉ   >  r‰  zTypedStorage.float8_e4m3fnc                 C   rˆ  rÊ   )r1  r¨   rn   rË   r"   r   r   r   rË   C  r‰  zTypedStorage.float8_e5m2fnuzc                 C   rˆ  rÌ   )r1  r¨   rn   rÍ   r"   r   r   r   rÍ   H  r‰  zTypedStorage.float8_e4m3fnuzc                 C   s@   t ƒ  | tkrtdƒ‚t |||tj | j¡ ¡}| |d�}|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[  )	r1  r@  rO  r›   rZ   rn   rÞ   rß   r1   )r>   rX   rY   r/   rÑ   r§   r   r   r   rZ   M  s   ý
zTypedStorage.from_filec                 O   rƒ  r   )r›   r[   rC   r   r   r   r[   k  r„  zTypedStorage._expiredc                 O   r…  r   )r"  rK   r   r   r   r   rK   o  r‘   zTypedStorage._write_filec                 O   r…  r   )r"  rO   r   r   r   r   rO   r  r‘   zTypedStorage._set_from_filec                 O   r…  r   )r"  rP   r   r   r   r   rP   u  r‘   zTypedStorage._set_cdatac                 O   r…  r   )r"  rQ   r   r   r   r   rQ   x  r‘   zTypedStorage._share_cuda_c                 C   r]  r   )r1  Ú
_is_sharedr"   r   r   r   rR   {  r_  zTypedStorage.is_sharedc                 C   rk  r   )r"  rR   r"   r   r   r   rŠ  €  rl  zTypedStorage._is_sharedc                 O   ó   t jj|i |¤ŽS r   )rn   r›   rS   rC   r   r   r   rS   ƒ  r  zTypedStorage._new_shared_cudac                 O   s*   | j j|i |¤Ž\}}}||||  ¡  fS r   )r"  r<   rß   )r   r   r   Zmanager_handleZstorage_handler/   r   r   r   r<   ‡  s   z!TypedStorage._share_filename_cpu_c                 C   r{  r   )r"  rJ   r"   r   r   r   rJ   ‹  r|  zTypedStorage._shared_decrefc                O   s   t jj|i |¤ŽS r   ©rn   r›   rH   )r>   r   r   r   r   r   r   Ú_release_ipc_counter�  r  z!TypedStorage._release_ipc_counterc                 O   r…  r   )r"  rT   r   r   r   r   rT   “  r‘   zTypedStorage._shared_increfc                 O   s&   | j j|i |¤Ž\}}|||  ¡  fS r   )r"  r=   rß   )r   r   r   Úfdr/   r   r   r   r=   –  s   zTypedStorage._share_fd_cpu_c                 C   sz   | j tƒ vrd S tƒ | j  }| jjdddtj ¡ fvrd S | jjdkr%tntt| jjƒ}zt||ƒW S  ty<   Y d S w )Nr™   r4   r5   )	r1   r  r   r2   rn   r×   rØ   ÚgetattrÚAttributeError)r   Zstorage_namer;  r   r   r   rm  š  s   ÿz&TypedStorage._get_legacy_storage_class)Fr   rã   rä   )erå   ræ   rç   r   rn   r1   rè   rë   rA  ré   rg   rX   rF  rP  r   rV   rW   rÜ   r\  r#   rc  r'   rB  r&   rf  r   r½   r+   r-   rj  r   r2   r4   r5   r6   rß   r´   r9   rt   rv   rz   r|   r€   rt  rŽ   r{   r–   r™   r   rÎ   rÐ   rÙ   rz  rÛ   r   r/   rD  r~  r}  r‹   r:   r�  r;   rM   r‚  rê   rU   rN   rD   r†  r¨   r«   r®   r°   r²   r¶   r¹   r»   r¿   rÂ   rÅ   rÇ   rÉ   rË   rÍ   rZ   r[   rK   rO   rP   rQ   rR   rŠ  rS   r<   rJ   r�  rT   r=   rm  rì   r   r   r�   r   r@  é  sÎ   
 

HD


!$






r@  c                   @   s    e Zd ZU ejed< dd„ ZdS )Ú_LegacyStorageMetar1   c                 C   s2   t |ƒtkrt| jƒ}||jj ko| j|jkS dS rã   )r2   r@  r?  ræ   r   r1   )r>   ÚinstancerU  r   r   r   Ú__instancecheck__±  s   
z$_LegacyStorageMeta.__instancecheck__N)rå   ræ   rç   rn   r1   rè   r“  r   r   r   r   r‘  ®  s   
 
r‘  c                   @   s0   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZdS )rN  c                 C   s    t j || ƒ  ¡  ¡}| |d�S )rÚ   r[  )rn   r›   rÛ   rß   )r>   r/   rÑ   r   r   r   rÛ   ¸  s   
z_LegacyStorage._new_sharedc                 O   r‹  r   rŒ  rC   r   r   r   r�  ¾  r  z#_LegacyStorage._release_ipc_counterc                 C   s(   |t j | j¡ }| t j |||¡d�S )Nr[  )rn   rÞ   rß   r1   r›   rG   )r>   rE   rF   r/   Z
bytes_sizer   r   r   Ú_new_shared_filenameÂ  s   z#_LegacyStorage._new_shared_filenameN)rå   ræ   rç   rê   rÛ   r�  r”  r   r   r   r   rN  ·  s    

rN  )Ú	metaclassr~  c              
   C   s8   zt ƒ |  W S  ty } z	td| › d�ƒ|‚d }~ww )Nzpickle storage type "z" is not recognized)r   r  )r~  r€  r   r   r   Ú#_get_dtype_from_pickle_storage_typeÇ  s   
ÿÿ€ÿr–  )rÝ   )<r„   rn   rÞ   r   r   r   Ztorch.typesr   Útypingr   r   r	   Z_Dictr
   ré   r   r   r   rr  rQ  rö   r   r5  rî   Únumpyr(  r'  ÚModuleNotFoundErrorÚLockrí   r   r´   rï   rè   r   r   rø   r×   ÚStorageBaser›   r‡   r2   r4   r5   r  r   r&  r+  r,  r-  r.  r1  r9  rg   r?  r@  Ú__doc__r‘  rN  r–  r   r   r   r   Ú<module>   sj   
 $ÿ  "?


     
F

	