a
    7Sicx                     @   s^  d dl Z d dlZddlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZ d dlZd dlZd dlmZ zd dlZdZW n ey   dZY n0 e	dd	d
ZG dd deZG dd dejjeZdd Zee_ee_edddd Zedddd Zdd Z dd Z!G dd dZ"ej#e"j_#ej#e"j_#G dd deZ$G dd de"e$d Z%e&d!d"d#Z'dS )$    N   )_type_cuda)Storage)AnyTypeVarTypeUnioncast)	lru_cacheT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
edd	d
Zdd ZdeeedddZedddZedddZdeeedddZdedddZe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eedd)d*Zeddd+edd,d-Zeedd.d/Z eedd0d1Z!edd2d3Z"d4d5 Z#ed6d7d8Z$edd9d:Z%edd;d<Z&d=d> Z'd?d@ Z(dAdB Z)eddCdDZ*eeddEdFZ+dGdH Z,edIdJ Z-e.dKdL Z/dMdN Z0dOdP Z1dQdR Z2dSdT Z3dUdV Z4dWdX Z5 fdYdZZ6d[d\ Z7d]d^ Z8d_d` Z9dadb Z:dcdd Z;dedf Z<dgdh Z=didj Z>dkdl Zdmdn Z?dodp Z@dqdr ZAdsdt Zdudv ZBdwdx ZCdydz ZDd{d| ZEd}d~ ZFeddddZGdd ZH  ZIS )_StorageBase_cdataF	is_sparseis_sparse_csrdevicec                 O   s   d S N selfargskwargsr   r   I/var/www/html/django/DPS/env/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__N)sourcenon_blockingr   c                 C   s   d S r   r   r   r"   r#   r   r   r   copy_   r   z_StorageBase.copy_c                 C   s   d S r   r   r   r   r   r   nbytes   r   z_StorageBase.nbytesc                 C   s   |   S r   )r&   r   r   r   r   size   s    z_StorageBase.sizedtyper#   r   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   r   r#   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   data_ptr$   r   z_StorageBase.data_ptrc                 O   s   d S r   r   r   r   r   r   _share_filename_cpu_'   r   z!_StorageBase._share_filename_cpu_c                 O   s   d S r   r   r   r   r   r   _share_fd_cpu_(   r   z_StorageBase._share_fd_cpu_)clsr'   r   c                 C   s   d S r   r   r1   r'   r   r   r   _new_using_filename_cpu)   s    z$_StorageBase._new_using_filename_cpuc                 C   s   d S r   r   r2   r   r   r   _new_using_fd_cpu+   s    z_StorageBase._new_using_fd_cpuc                 O   s   d S r   r   r1   r   r   r   r   r   from_buffer-   s    z_StorageBase.from_buffer)r   r)   c                C   s   d S r   r   )r1   managerobjr'   r   r)   r   r   r   _new_shared_filename_cpu/   s    z%_StorageBase._new_shared_filename_cpuc                 O   s   d S r   r   r5   r   r   r   _release_ipc_counter_cuda1   s    z&_StorageBase._release_ipc_counter_cudac                 O   s   d S r   r   r5   r   r   r   _new_with_weak_ptr3   s    z_StorageBase._new_with_weak_ptrc                 C   s   d S r   r   r   r   r   r   _shared_decref5   r   z_StorageBase._shared_decrefc                 O   s   d S r   r   r   r   r   r   _write_file6   r   z_StorageBase._write_file)r'   c                 C   s   d S r   r   r   r'   r   r   r   resize_7   r   z_StorageBase.resize_c                 O   s   d S r   r   r   r   r   r   	_weak_ref8   r   z_StorageBase._weak_refc                 C   s   d S r   r   r   r   r   r   	is_pinned9   r   z_StorageBase.is_pinnedc                 O   s   d S r   r   r   r   r   r   _set_from_file:   r   z_StorageBase._set_from_filec                 O   s   d S r   r   r   r   r   r   
_set_cdata;   r   z_StorageBase._set_cdatac                 O   s   d S r   r   r   r   r   r   _share_cuda_<   r   z_StorageBase._share_cuda_c                 C   s   d S r   r   r   r   r   r   	is_shared=   r   z_StorageBase.is_sharedc                 O   s   d S r   r   r5   r   r   r   _new_shared_cuda>   s    z_StorageBase._new_shared_cudac                 O   s   d S r   r   r   r   r   r   _shared_incref@   r   z_StorageBase._shared_increfc                 O   s   d S r   r   r5   r   r   r   _free_weak_refA   s    z_StorageBase._free_weak_refc                 C   s   d S r   r   r   r   r   r   is_cudaC   s    z_StorageBase.is_cudac                    sL   dd  fddt  D  }|dt  d j dt  d S )	N 
 c                 3   s   | ]}t  | V  qd S r   str.0ir   r   r   	<genexpr>G   r   z'_StorageBase.__str__.<locals>.<genexpr>
[z(device=
) of size ])joinranger'   torchtypenamer   lenr   Zdata_strr   r   r   __str__F   s    $z_StorageBase.__str__c                 C   s   t | S r   rL   r   r   r   r   __repr__L   s    z_StorageBase.__repr__c                    s   t t fddt  S )Nc                    s    |  S r   r   rP   r   r   r   <lambda>P   r   z'_StorageBase.__iter__.<locals>.<lambda>itermaprV   r'   r   r   r   r   __iter__O   s    z_StorageBase.__iter__c                 C   s   |   S r   )cloner   r   r   r   __copy__R   s    z_StorageBase.__copy__c                 C   s6   | di }| j|v r || j S |  }||| j< |S )NrW   )
setdefaultr   rc   )r   memonew_storager   r   r   __deepcopy__U   s    


z_StorageBase.__deepcopy__c                 C   s&   t  }tj| |dd t| ffS NF)Z_use_new_zipfile_serializationioBytesIOrW   save_load_from_bytesgetvaluer   br   r   r   
__reduce__]   s    z_StorageBase.__reduce__c                    s   t t|  |   S r   )superr   
__sizeof__r'   r   	__class__r   r   rt   b   s    z_StorageBase.__sizeof__c                 C   s   t | |  | jd| S )Returns a copy of this storager   )r*   r&   r   r%   r   r   r   r   rc   e   s    z_StorageBase.clonec                 C   s   t | S z6Returns a list containing the elements of this storagelistr   r   r   r   tolisti   s    z_StorageBase.tolistc                 C   s*   | j jdkr"t|  | dS | S dS )AReturns a CPU copy of this storage if it's not already on the CPUcpuFN)r   r*   rW   _UntypedStorager'   r%   r   r   r   r   r~   m   s    z_StorageBase.cpuc                 C   sd   t |tjstdt| tjg tj| jdt	t
| | }| |  kr`| }|S Nz*Argument 'dtype' must be torch.dtype, not r)   r   )
isinstancerW   r)   	TypeErrorr*   tensoruint8r   set_r
   r   tostorager.   rc   r   r)   r   r   r   r   _tot   s    *z_StorageBase._toc                 C   s   |  tjS z!Casts this storage to double typer   rW   doubler   r   r   r   r   |   s    z_StorageBase.doublec                 C   s   |  tjS z Casts this storage to float typer   rW   floatr   r   r   r   r      s    z_StorageBase.floatc                 C   s   |  tjS zCasts this storage to half typer   rW   halfr   r   r   r   r      s    z_StorageBase.halfc                 C   s   |  tjS zCasts this storage to long typer   rW   longr   r   r   r   r      s    z_StorageBase.longc                 C   s   |  tjS zCasts this storage to int typer   rW   intr   r   r   r   r      s    z_StorageBase.intc                 C   s   |  tjS z Casts this storage to short typer   rW   shortr   r   r   r   r      s    z_StorageBase.shortc                 C   s   |  tjS zCasts this storage to char typer   rW   int8r   r   r   r   char   s    z_StorageBase.charc                 C   s   |  tjS zCasts this storage to byte typer   rW   r   r   r   r   r   byte   s    z_StorageBase.bytec                 C   s   |  tjS zCasts this storage to bool typer   rW   boolr   r   r   r   r      s    z_StorageBase.boolc                 C   s   |  tjS z#Casts this storage to bfloat16 typer   rW   bfloat16r   r   r   r   r      s    z_StorageBase.bfloat16c                 C   s   |  tjS z)Casts this storage to complex double typer   rW   cdoubler   r   r   r   complex_double   s    z_StorageBase.complex_doublec                 C   s   |  tjS z(Casts this storage to complex float typer   rW   cfloatr   r   r   r   complex_float   s    z_StorageBase.complex_floatc                 C   sH   | j rtd|   dddl}|j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)	rI   r   r*   Z
torch.cudar+   ZmemoryZ_host_allocatorr'   r%   )r   rW   r   r   r   r   
pin_memory   s
    z_StorageBase.pin_memoryc                 C   s4   ddl m} | jrn| dkr(|   n|   | S )  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.multiprocessingr   rI   r/   r0   )r   r   r   r   r   share_memory_   s    	

z_StorageBase.share_memory_r~   rx   c                C   sN   ddl m} t|}|jdkr,| ||dS | dkr@| |S | |S dS )>Creates a new storage in shared memory with the same data typer   r   r+   rx   r   N)r   r   rW   r   r*   r3   r4   )r1   r'   r   r   r   r   r   _new_shared   s    



z_StorageBase._new_sharedc                 C   s   | S r   r   r   r   r   r   _untyped   s    z_StorageBase._untyped)N)NF)NF)J__name__
__module____qualname__r   __annotations__r   r   r   rW   r   r   r   r   r!   r   r%   r&   r'   rM   r*   r+   r,   r-   r.   r/   r0   classmethodr   r3   r4   r6   r9   r:   r;   r<   r=   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   propertyrI   r[   r\   rb   rd   rh   rr   rt   rc   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   ru   r   r      s   



r   c                   @   s   e Zd Zedd ZdS )r   c                 C   s   | j jdkS Nr+   r   r*   r   r   r   r   rI      s    z_UntypedStorage.is_cudaN)r   r   r   r   rI   r   r   r   r   r      s   r   c                 C   s   t t| S r   )rW   loadrk   rl   )rq   r   r   r   rn      s    rn   )maxsizec                "   C   sj   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iS )NDoubleStorageFloatStorageHalfStorageLongStorage
IntStorageShortStorageCharStorageByteStorageBoolStorageBFloat16StorageComplexDoubleStorageComplexFloatStorageQInt8StorageQInt32StorageQUInt8StorageQUInt4x2StorageQUInt2x4Storage)rW   r   r   r   r   r   int16r   r   r   r   r   r   qint8qint32quint8quint4x2quint2x4r   r   r   r   _dtype_to_storage_type_map   s$    r   c                  C   s   dd t   D } | S )Nc                 S   s   i | ]\}}||qS r   r   )rO   key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   sz   |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}|
  S )Nr   )rW   r   r   r   r   r   r   int32r   r   r   r   )sequencer)   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 d S r   )	HAS_NUMPYr   r   npinteger)xr   r   r   _isint  s    r   c                       s  e Zd ZU dZejed< dd Zdddd fdd
Zdddd	d
dZ	e
dd Zdd Zdd Zdd ZdddZdd Zdd ZdeedddZdd Zdeeeeef dd d!Zded"d#d$Zd%d& Zed"d'd(Zd)d* Zd+d, Zd-d. Zd/d0 Z d1d2 Z! fd3d4Z"d5d6 Z#d7d8 Z$d9d: Z%d;d< Z&d=d> Z'dd?d@dAZ(e
dBdC Z)e
dDdE Z*dFdG Z+dHdI Z,dJdK Z-dLdM Z.dNdO Z/e0dPdQ Z1dRdS Z2e0dddTdUdVZ3dWdX Z4dYdZ Z5d[d\ Z6d]d^ Z7d_d` Z8dadb Zdcdd Z9dedf Z:dgdh Z;didj Zdkdl Z<dmdn Z=dodp Z>e0dqdr Z?e0dsdt Z@dudv ZAdwdx ZBdydz ZCd{d| ZDd}d~ ZEdd ZFe0dd ZGdd ZHdd ZIe0dd?ddZJdd ZKdd ZLdd ZM  ZNS )_TypedStorageFr)   c                 C   s   || dt | < | S )Nr   rY   )r   valuer   r   r   fill_'  s    z_TypedStorage.fill_N)wrap_storager)   r   c                   sv  | t jjkrtd| tkr(t | S |  d}|d urFt|d |d urZt|d |d u rt|dkrzt|d t|dkrt|d st	|d t
jjst|dt|d   t|| jt| jt ju rd	nd
dS t|dk rt|d t	|t js"t|dt|  | jdkr2d	nd
}|jj|kr`t|d| d|jj  t||| jdS 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: r+   r~   r   B
No positional arguments should be given when using 'wrap_storage':
Argument 'wrap_storage' must be _UntypedStorage, but got 
torch.cudaz"
Device of 'wrap_storage' must be z
, but got r   r)   )rW   r   _LegacyStorageRuntimeErrorr   rs   __new__rY   r   r   collectionsabcSequencer   r*   r)   evalr   r+   r   r   )r1   r   r)   r   r   arg_error_msg
cls_deviceru   r   r   r   +  s|    *z_TypedStorage.__new__)r   r)   r   c                G   s  d}|d urt |dkr$t|d |d u r8t|d t|tjsZt|dt|  |d urnt|d || _t|tjst|dt|  || _n
|d u rt	 n|| _t
|d u rdn|}| jtjtjtjtjtjfv r|jd	krtd
t |dkrtj|d| _nt |dkrt|d rXtjt|d |   |d| _nDt|d tjjrt|d | j|| _nt|dt|d   nt|d d S )Na3  _TypedStorage.__init__ received an invalid combination of arguments. Expected one of:
 * (*, torch.device device, torch.dtype dtype)
 * (int size, *, torch.device device, torch.dtype dtype)
 * (Sequence data, *, torch.device device, torch.dtype dtype)
 * (*, _UntypedStorage wrap_storage, torch.dtype dtype)r   r   z#
Argument 'dtype' must be specifiedz+
Argument 'dtype' must be torch.dtype, not zG
Argument 'device' should not be specified when 'wrap_storage' is givenr   r~   r+   /Cannot create CUDA storage with quantized dtyperx   r   r   r   )rY   r   r   rW   r)   r   r*   r   _storageget_default_dtyper   r   r   r   r   r   r   r   r,   r   r   r   r   )r   r   r)   r   r   r  r   r   r   r   n  sr    

"z_TypedStorage.__init__c                 C   s   | j jdkS r   r   r   r   r   r   rI     s    z_TypedStorage.is_cudac                 C   s   | j S r   )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S t | |dS d S )Nr   r   )r*   rW   r   r   r)   )r   untyped_storager   r   r   _new_wrapped_storage  s    z"_TypedStorage._new_wrapped_storagec                 C   s   | j  |   S r   )r  r&   r,   r   r   r   r   r     s    z_TypedStorage.__len__c                 C   s   |d u r|r|   S dS nt|tkrBtdt|  dt| |r||   ks`||    k rxtd| d|    |dkr|S ||    S n>||   ks||    k rtd| d|    ||    S d S )Nr   can't index a  with zindex z" out of range for storage of size )r'   r*   r   r   
IndexError)r   r    Zis_stopr   r   r   _maybe_wrap_index  s*    z_TypedStorage._maybe_wrap_indexc              
   C   s   t |ttf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}|| j }tjg || jdt| j|d}ntjg | j| jd| }|||< d S )Nr	  r
  r   r   )r   r   slicer   r*   r)   rW   r   r   r   r   r   r   r   r   r   r   r   r   r  )r   r    r   r   Z	tmp_dtyper   r   r   r   __setitem__  s     

z_TypedStorage.__setitem__c              
   C   s   t |trtdn&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| S | |}tjg | j| jd| }||  S )Nz8slices are only supported in _UntypedStorage.__getitem__r	  r
  r   r   )r   r  r   r   r*   r)   rW   r   r   r   r   r   r   r   r   r   r  r  r   r   r   item)r   r    r   Zidx_wrappedr   r   r   r   r!     s(    



z_TypedStorage.__getitem__)r"   r#   c                 C   s   | j | | | S r   )r  r%   r   r$   r   r   r   r%   
  s    z_TypedStorage.copy_c                 C   s
   | j  S r   )r  r&   r   r   r   r   r&     s    z_TypedStorage.nbytesr(   c                 C   sP   |d u r>|   }|d ur(|jd |j S d| jt| jgS | j||S d S )N.)_get_legacy_storage_classr   r   rU   r*   r  )r   r)   r#   Zlegacy_classr   r   r   r*     s    z_TypedStorage.typer   c                 K   sF   | j tjtjtjtjtjfv r&td| jj	||fi |}| 
|S )Nr  )r)   rW   r   r   r   r   r   r   r  r+   r  )r   r   r#   r   Zcuda_storager   r   r   r+     s    z_TypedStorage.cudac                 C   s   t j| jS r   )rW   _utils_element_sizer)   r   r   r   r   r,   #  s    z_TypedStorage.element_sizec                 C   s
   | j  S r   )r  r-   r   r   r   r   r-   &  s    z_TypedStorage.get_devicec              
      sT   dd  fddt  D  }|dt  d j d j dt  d		 S )
NrJ   rK   c                 3   s   | ]}t  | V  qd S r   rL   rN   r   r   r   rQ   *  r   z(_TypedStorage.__str__.<locals>.<genexpr>rR   z(dtype=z	, device=rS   rT   )rU   rV   r'   rW   rX   r)   r   rY   rZ   r   r   r   r[   )  s    $z_TypedStorage.__str__c                 C   s   t | S r   rL   r   r   r   r   r\   /  s    z_TypedStorage.__repr__c                    s   t t fddt  S )Nc                    s    |  S r   r   r]   r   r   r   r^   3  r   z(_TypedStorage.__iter__.<locals>.<lambda>r_   r   r   r   r   rb   2  s    z_TypedStorage.__iter__c                 C   s   |  t| jS r   )r  copyr  r   r   r   r   rd   5  s    z_TypedStorage.__copy__c                 C   s   |  t| j|S r   )r  r  deepcopyr  )r   rf   r   r   r   rh   8  s    z_TypedStorage.__deepcopy__c                    s   t t|  |   S r   )rs   r   rt   r&   r   ru   r   r   rt   ;  s    z_TypedStorage.__sizeof__c                 C   s   |  | j S )rw   )r  r  rc   r   r   r   r   rc   >  s    z_TypedStorage.clonec                 C   s   t | S ry   rz   r   r   r   r   r|   B  s    z_TypedStorage.tolistc                 C   s   |  | j S )r}   )r  r  r~   r   r   r   r   r~   F  s    z_TypedStorage.cpuc                 C   s   |  | j S )zBCoppies the  storage to pinned memory, if it's not already pinned.)r  r  r   r   r   r   r   r   J  s    z_TypedStorage.pin_memoryc                 C   s   | j   | S )r   )r  r   r   r   r   r   r   N  s    	
z_TypedStorage.share_memory_rx   c                C   s<   |du rd}t |}t jj||   |d}t|| jdS )r   Nr~   rx   r   )rW   r   r   r   r,   r   r)   )r   r'   r   r  r   r   r   r   Z  s    
z_TypedStorage._new_sharedc                 C   s   | j jS r   )r  r   r   r   r   r   r   d  s    z_TypedStorage._cdatac                 C   s   | j jS r   )r  r   r   r   r   r   r   h  s    z_TypedStorage.devicec                 C   s   t | S r   r   r   r   r   r   r'   l  s    z_TypedStorage.sizec                 C   s8   zt  | j W S  ty2   td| j dY n0 d S )Nzdtype z is not recognized)r   r)   KeyErrorr   r   r   r   pickle_storage_typeo  s    z!_TypedStorage.pickle_storage_typec                 C   s&   t  }tj| |dd t| ffS ri   rj   rp   r   r   r   rr   u  s    z_TypedStorage.__reduce__c                 C   s
   | j  S r   )r  r.   r   r   r   r   r.   z  s    z_TypedStorage.data_ptrc                 C   s   | j ||    d S r   )r  r?   r,   r>   r   r   r   r?   }  s    z_TypedStorage.resize_c                 O   s   t j|i |S r   )r   rH   r5   r   r   r   rH     s    z_TypedStorage._free_weak_refc                 O   s   | j j|i |S r   )r  r@   r   r   r   r   r@     s    z_TypedStorage._weak_refr   c                O   s   | t krd|d u rt n|}t|d u r,dn|}|jdkrLtd|j tjj|d|i|}nH|d usxt|dkrtd|d urtd| j	}tjj|d|i|}t ||dS )Nr~   z4_TypedStorage.from_buffer: Not available for device r)      zgfrom_buffer: 'dtype' can only be specified in _UntypedStorage.from_buffer and _TypedStorage.from_bufferzhfrom_buffer: 'device' can only be specified in _UntypedStorage.from_buffer and _TypedStorage.from_bufferr   )
r   rW   r  r   r*   r   r   r6   rY   r)   )r1   r)   r   r   r   r  r   r   r   r6     s"    
z_TypedStorage.from_bufferc                 C   s^   t |tjstdt| tjg | j| jd| |	 }|
 | 
 krZ| }|S r   )r   rW   r)   r   r*   r   r   r   r   r   r.   rc   r   r   r   r   r     s    $z_TypedStorage._toc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.doublec                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.floatc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.halfc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.longc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.intc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.shortc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.charc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.bytec                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.boolc                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.bfloat16c                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.complex_doublec                 C   s   |  tjS r   r   r   r   r   r   r     s    z_TypedStorage.complex_floatc                 C   sB   | t krtdt| jj|||tj| j	 }| |d}|S )a  
        from_file(filename, shared=False, size=0) -> Storage

        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
            size (int): number of elements in the storage
        z/from_file can only be called on derived classesr  )
r   r   r   r   r   	from_filerW   r  r  r)   )r1   filenameZsharedr'   r  r   r   r   r   r    s    
z_TypedStorage.from_filec                 O   s   t | jjj|i |S r   )r   r   r   _expiredr5   r   r   r   r    s    z_TypedStorage._expiredc                 C   s
   | j  S r   )r  rA   r   r   r   r   rA     s    z_TypedStorage.is_pinnedc                 O   s   | j j|i |S r   )r  r=   r   r   r   r   r=     s    z_TypedStorage._write_filec                 O   s   | j j|i |S r   )r  rB   r   r   r   r   rB     s    z_TypedStorage._set_from_filec                 O   s   | j j|i |S r   )r  rC   r   r   r   r   rC      s    z_TypedStorage._set_cdatac                 O   s   | j j|i |S r   )r  rD   r   r   r   r   rD     s    z_TypedStorage._share_cuda_c                 C   s
   | j  S r   )r  rE   r   r   r   r   rE     s    z_TypedStorage.is_sharedc                 O   s   t jj|i |S r   )rW   r   rF   r5   r   r   r   rF   	  s    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   s   | j   | S r   )r  r<   r   r   r   r   r<     s    
z_TypedStorage._shared_decrefc                O   s   t jj|i |S r   rW   r   r:   )r1   r   r   r   r   r   r   _release_ipc_counter  s    z"_TypedStorage._release_ipc_counterc                 O   s   | j j|i |S r   )r  rG   r   r   r   r   rG     s    z_TypedStorage._shared_increfc                 O   s&   | j j|i |\}}|||   fS r   )r  r0   r,   )r   r   r   fdr'   r   r   r   r0     s    z_TypedStorage._share_fd_cpu_c                 C   sh   | j t vrd S t | j  }| jjdvr,d S | jjdkr<dnd}zt|| W S  tyb   Y d S 0 d S )N)r~   r+   r~   ztorch.ztorch.cuda.)r)   r   r   r*   r   AttributeError)r   Zstorage_namemoduler   r   r   r     s    z'_TypedStorage._get_legacy_storage_class)F)N)NF)NF)Or   r   r   r   rW   r)   r   r   r   r   r   rI   r   r  r   r  r  r!   r   r   r%   r&   rM   r	   r*   r+   r,   r   r-   r[   r\   rb   rd   rh   rt   rc   r|   r~   r   r   r   r   r   r'   r  rr   r.   r?   r   rH   r@   r6   r   r   r   r   r   r   r   r   r   r   r   r  r  rA   r=   rB   rC   rD   rE   rF   r/   r<   r  rG   r0   r  r   r   r   ru   r   r   "  s   

CC








r   c                   @   s    e Zd ZU ejed< dd ZdS )_LegacyStorageMetar)   c                 C   s:   t |tkr6| jdkrdnd}||jj ko4| j|jkS dS )Nr   r+   r~   F)r*   r   r   r   r)   )r1   instancer  r   r   r   __instancecheck__6  s    z$_LegacyStorageMeta.__instancecheck__N)r   r   r   rW   r)   r   r#  r   r   r   r   r!  3  s   

r!  c                   @   s0   e Zd Zedd Zedd Zedd ZdS )r   c                 C   s    t j||    }| |dS )r   r  )rW   r   r   r,   )r1   r'   r  r   r   r   r   =  s    z_LegacyStorage._new_sharedc                 O   s   t jj|i |S r   r  r5   r   r   r   r  C  s    z#_LegacyStorage._release_ipc_counterc                 C   s(   |t j| j }| t j|||dS )Nr  )rW   r  r  r)   r   r9   )r1   r7   r8   r'   
bytes_sizer   r   r   _new_shared_filenameG  s    z#_LegacyStorage._new_shared_filenameN)r   r   r   r   r   r  r%  r   r   r   r   r   <  s   

r   )	metaclassr  c                 C   s4   zt  |  W S  ty.   td|  dY n0 d S )Nzpickle storage type "z" is not recognized)r   r  r'  r   r   r   #_get_dtype_from_pickle_storage_typeL  s    
r(  )(rk   rW   r  r   r   Ztorch.typesr   typingr   r   r   r	   r
   r  r   	functoolsr   numpyr   r   ModuleNotFoundErrorr   objectr   _CStorageBaser   rn   r*   r+   r   r   r   r   r   __doc__r!  r   rM   r(  r   r   r   r   <module>   sF   
 F

    

	