a
    –¥»a‚  ã                   @   sh   d dl Z d dlZddlmZmZ d dlmZmZmZ eddd�Z	G dd„ de
ƒZd	d
„ Zee_ee_dS )é    Né   )Ú_typeÚ_cuda)ÚAnyÚTypeVarÚTypeÚTÚ_StorageBase)Úboundc                       sÂ  e Zd ZU eed< dZeed< dZeed< dd„ Ze	dœdd	„Z
d
d„ Zeedœdd„Ze	dœdd„ZdVeeedœdd„ZdWedœdd„Ze	dœdd„Ze	dœdd„Zdd„ Zdd„ Zeee e	edœd d!„ƒZeee e	edœd"d#„ƒZd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Z‡ fd0d1„Z d2d3„ Z!d4d5„ Z"d6d7„ Z#d8d9„ Z$d:d;„ Z%d<d=„ Z&d>d?„ Z'd@dA„ Z	dBdC„ Z(dDdE„ Z)dFdG„ Z*dHdI„ ZdJdK„ Z+dLdM„ Z,dNdO„ Z-dPdQ„ Z.dRdS„ Z/edTdU„ ƒZ0‡  Z1S )Xr	   Ú_cdataFÚis_cudaÚ	is_sparsec                 O   s   d S ©N© )ÚselfÚargsÚkwargsr   r   úG/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/storage.pyÚ__init__   ó    z_StorageBase.__init__)Úreturnc                 C   s   d S r   r   ©r   r   r   r   Ú__len__   r   z_StorageBase.__len__c                 C   s   d S r   r   )r   Úidxr   r   r   Ú__getitem__   r   z_StorageBase.__getitem__)Úsourcer   c                 C   s   d S r   r   )r   r   r   r   r   Úcopy_   r   z_StorageBase.copy_c                 C   s   d S r   r   r   r   r   r   Úsize   r   z_StorageBase.sizeN)ÚdtypeÚnon_blockingr   c                 C   s   d S r   r   )r   r   r   r   r   r   Útype   r   z_StorageBase.typec                 K   s   d S r   r   )r   Údevicer   r   r   r   r   Úcuda   r   z_StorageBase.cudac                 C   s   d S r   r   r   r   r   r   Úelement_size   r   z_StorageBase.element_sizec                 C   s   d S r   r   r   r   r   r   Ú
get_device   r   z_StorageBase.get_devicec                 C   s   d S r   r   r   r   r   r   Ú_share_filename_   r   z_StorageBase._share_filename_c                 C   s   d S r   r   r   r   r   r   Ú
_share_fd_   r   z_StorageBase._share_fd_)Úclsr   r   c                 C   s   d S r   r   ©r'   r   r   r   r   Ú_new_using_filename   s    z _StorageBase._new_using_filenamec                 C   s   d S r   r   r(   r   r   r   Ú_new_using_fd   s    z_StorageBase._new_using_fdc                    sD   dd  ‡ fdd„ttˆ ƒƒD ƒ¡ }|dt ˆ ¡› dtˆ ƒ› d� S )Nú z
 c                 3   s   | ]}t ˆ | ƒV  qd S r   ©Ústr)Ú.0Úir   r   r   Ú	<genexpr>    r   z'_StorageBase.__str__.<locals>.<genexpr>z
[z	 of size ú])ÚjoinÚrangeÚlenÚtorchÚtypename)r   Úcontentr   r   r   Ú__str__   s    $z_StorageBase.__str__c                 C   s   t | ƒS r   r,   r   r   r   r   Ú__repr__#   s    z_StorageBase.__repr__c                    s   t t‡ fdd„tˆ  ¡ ƒƒƒS )Nc                    s   ˆ |  S r   r   )r/   r   r   r   Ú<lambda>'   r   z'_StorageBase.__iter__.<locals>.<lambda>)ÚiterÚmapr3   r   r   r   r   r   Ú__iter__&   s    z_StorageBase.__iter__c                 C   s   |   ¡ S r   )Úcloner   r   r   r   Ú__copy__)   s    z_StorageBase.__copy__c                 C   s6   |  di ¡}| j|v r || j S |  ¡ }||| j< |S )Nr5   )Ú
setdefaultr   r>   )r   ÚmemoZnew_storager   r   r   Ú__deepcopy__,   s    


z_StorageBase.__deepcopy__c                 C   s&   t  ¡ }tj| |dd� t| ¡ ffS )NF)Z_use_new_zipfile_serialization)ÚioÚBytesIOr5   ÚsaveÚ_load_from_bytesÚgetvalue)r   Úbr   r   r   Ú
__reduce__4   s    z_StorageBase.__reduce__c                    s   t t| ƒ ¡ |  ¡ |  ¡   S r   )Úsuperr	   Ú
__sizeof__r#   r   r   ©Ú	__class__r   r   rK   9   s    z_StorageBase.__sizeof__c                 C   sX   | j r|  ¡ nd}tj |¡�& t| ƒ|  ¡ ƒ | ¡W  d  ƒ S 1 sJ0    Y  dS )zReturns a copy of this storageéÿÿÿÿN)r   r$   r5   r"   r!   r    r   r   )r   r!   r   r   r   r>   <   s    z_StorageBase.clonec                 C   s   t | ƒS )z6Returns a list containing the elements of this storage)Úlistr   r   r   r   ÚtolistB   s    z_StorageBase.tolistc                 C   s   |   tt| jjƒ¡S )zAReturns a CPU copy of this storage if it's not already on the CPU)r    Úgetattrr5   rM   Ú__name__r   r   r   r   ÚcpuF   s    z_StorageBase.cpuc                 C   s   |   t | ƒjd ¡S )z!Casts this storage to double typez.DoubleStorage©r    Ú
__module__r   r   r   r   ÚdoubleJ   s    z_StorageBase.doublec                 C   s   |   t | ƒjd ¡S )z Casts this storage to float typez.FloatStoragerT   r   r   r   r   ÚfloatN   s    z_StorageBase.floatc                 C   s   |   t | ƒjd ¡S )zCasts this storage to half typez.HalfStoragerT   r   r   r   r   ÚhalfR   s    z_StorageBase.halfc                 C   s   |   t | ƒjd ¡S )zCasts this storage to long typez.LongStoragerT   r   r   r   r   ÚlongV   s    z_StorageBase.longc                 C   s   |   t | ƒjd ¡S )zCasts this storage to int typez.IntStoragerT   r   r   r   r   ÚintZ   s    z_StorageBase.intc                 C   s   |   t | ƒjd ¡S )z Casts this storage to short typez.ShortStoragerT   r   r   r   r   Úshort^   s    z_StorageBase.shortc                 C   s   |   t | ƒjd ¡S )zCasts this storage to char typez.CharStoragerT   r   r   r   r   Úcharb   s    z_StorageBase.charc                 C   s   |   t | ƒjd ¡S )zCasts this storage to byte typez.ByteStoragerT   r   r   r   r   Úbytef   s    z_StorageBase.bytec                 C   s   |   t | ƒjd ¡S )zCasts this storage to bool typez.BoolStoragerT   r   r   r   r   Úboolj   s    z_StorageBase.boolc                 C   s   |   t | ƒjd ¡S )z#Casts this storage to bfloat16 typez.BFloat16StoragerT   r   r   r   r   Úbfloat16n   s    z_StorageBase.bfloat16c                 C   s   |   t | ƒjd ¡S )z)Casts this storage to complex double typez.ComplexDoubleStoragerT   r   r   r   r   Úcomplex_doubler   s    z_StorageBase.complex_doublec                 C   s   |   t | ƒjd ¡S )z(Casts this storage to complex float typez.ComplexFloatStoragerT   r   r   r   r   Úcomplex_floatv   s    z_StorageBase.complex_floatc                 C   sF   | j rtd|  ¡ › d�ƒ‚ddl}|j ¡ }t| ƒ|  ¡ |d� | ¡S )z@Copies the storage to pinned memory, if it's not already pinned.zcannot pin 'z' only CPU memory can be pinnedr   N)Ú	allocator)r   Ú	TypeErrorr    Z
torch.cudar"   Z_host_allocatorr   r   )r   r5   rb   r   r   r   Ú
pin_memoryz   s
    
z_StorageBase.pin_memoryc                 C   s4   ddl m} | jrn|ƒ dkr(|  ¡  n|  ¡  | 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.

        Returns: self
        r   ©Úget_sharing_strategyÚfile_system)Útorch.multiprocessingrf   r   r%   r&   )r   rf   r   r   r   Úshare_memory_‚   s    	

z_StorageBase.share_memory_c                 C   s<   ddl m} | jr| |ƒS |ƒ dkr.|  |¡S |  |¡S dS )z>Creates a new storage in shared memory with the same data typer   re   rg   N)rh   rf   r   r)   r*   )r'   r   rf   r   r   r   Ú_new_shared”   s    

z_StorageBase._new_shared)NF)NF)2rR   rU   Ú__qualname__r   Ú__annotations__r   r^   r   r   rZ   r   r   r   r   r   r-   r    r"   r#   r$   r%   r&   Úclassmethodr   r)   r*   r8   r9   r=   r?   rB   rI   rK   r>   rP   rS   rV   rW   rX   rY   r[   r\   r]   r_   r`   ra   rd   ri   rj   Ú__classcell__r   r   rL   r   r	      sX   
c                 C   s   t  t | ¡¡S r   )r5   ÚloadrC   rD   )rH   r   r   r   rF       s    rF   )rC   r5   Ú_utilsr   r   Útypingr   r   r   r   Úobjectr	   rF   r    r"   r   r   r   r   Ú<module>   s    