
    קg                     \    d dl mZ 	 d Zd Zd Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd ZdS )    )OrderedDictc                 L    |                                  rt          d          d S )NzzNYI: Named tensors don't support serialization. Please drop names via `tensor = tensor.rename(None)` before serialization.)	has_namesRuntimeErrortensors    X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/_namedtensor_internals.pycheck_serializing_named_tensorr
      s8     
M
 
 	

 
    c                 X    t          d t          | j                  D                       S )zkReturns a map of { dim: dim_name } where dim is a name if the dim is named
    and the dim index otherwise.c                 $    g | ]\  }}||n||fS N ).0idxnames      r	   
<listcomp>z!build_dim_map.<locals>.<listcomp>   s)    XXX93##4	.XXXr   )r   	enumeratenamesr   s    r	   build_dim_mapr      s1     XX	&,@W@WXXX  r   c                 2   t          | t                    r|                                 } t          | d          s4t          | t                    st          dt          |                      t          |           dk    rt          d          t          |  S )N__iter__zBExpected namedshape to be OrderedDict or iterable of tuples, got: r   z!Expected namedshape to non-empty.)	
isinstancer   itemshasattrtupler   typelenzip)
namedshapes    r	   unzip_namedshaper!      s    *k** (%%''
:z** 
:j%3P3P 
cQUV`QaQacc
 
 	
 :!>???
r   c                     | rdS dS )Nrename_renamer   )inplaces    r	   namer_api_namer&   (   s     yxr   c                 $    | t           k    p| dk    S )Nz...)Ellipsis)items    r	   is_ellipsisr*   /   s    8,tu},r   c                     d t          |           D             }t          |          dk    rt          | d|  d          t          |          dk    r|d         S d S )Nc                 6    g | ]\  }}t          |          |S r   )r*   )r   ir   s      r	   r   z)single_ellipsis_index.<locals>.<listcomp>4   s)    OOOga[=N=NOOOOr      z1: More than one Ellipsis ('...') found in names (z-). This function supports up to one Ellipsis.   r   )r   r   r   )r   fn_nameellipsis_indicess      r	   single_ellipsis_indexr2   3   s    OO5)9)9OOO
!! D DD D D
 
 	
 !!""4r   c                 6    || t          |          |z
           S r   )r   )numel_pre_globnumel_post_globr   s      r	   expand_single_ellipsisr6   ?   s    #e**">>??r   c                     t          | t          |          | z
  dz
  |          }|d |          |z   || dz   d          z   S )Nr/   )r6   r   )ellipsis_idxr   tensor_namesglobbed_namess       r	   replace_ellipsis_by_positionr;   C   sS    *c%jj</!3\ M ,-/%q8H8J8J2KKKr   c                 L    t          | |          }|| S t          || |          S )zX
    Expands ... inside `names` to be equal to a list of names from `tensor_names`.
    )r2   r;   )r   r9   r0   r8   s       r	   resolve_ellipsisr=   J   s0     )88L'e\JJJr   c           	          t          |          dk    r|d         |                     d |          S |                     t          || j        t	          |                    |          S )Nr/   r   )r   _update_namesr=   r   r&   )r   r   r%   s      r	   update_names_with_listr@   T   sc    
5zzQ58+##D'222nW.E.EFF  r   c                 ^   t          |           }|                                D ]U}||         }||                                v r|||<   &t          t          |           d| d| d| j         d| d
          |                     t          |                                          |          S )Nz: Tried to rename dim 'z	' to dim z in Tensor[z] but dim 'z' does not exist)r   keysr   r&   r   r?   r   values)r   
rename_mapr%   dim_mapold_dimnew_dims         r	   update_names_with_mappingrH   ^   s    F##G??$$  W%gllnn$$&GG!'** Z Z7 Z ZZ Z'-|Z Z@GZ Z Z   gnn&6&6 7 7AAAr   c           	      >   t          |          dk    }t          |          }|rA|r?t          t          |           dt          |           dt          |           d          |s|st	          | ||          S |rt	          | ||          S t          | ||          S )a  There are two usages:

    tensor.rename(*names) returns a view on tensor with named dims `names`.
    `names` must be of length `tensor.dim()`; otherwise, if '...' is in `names`,
    then it is expanded greedily to be equal to the corresponding names from
    `tensor.names`.

    For example,
    ```
    >>> # xdoctest: +SKIP
    >>> x = torch.empty(2, 3, 5, 7, names=('N', 'C', 'H', 'W'))
    >>> x.rename('...', 'height', 'width').names
    ('N', 'C', 'height', 'width')

    >>> # xdoctest: +SKIP
    >>> x.rename('batch', '...', 'width').names
    ('batch', 'C', 'H', 'width')

    ```

    tensor.rename(**rename_map) returns a view on tensor that has rename dims
        as specified in the mapping `rename_map`.

    For example,
    ```
    >>> # xdoctest: +SKIP
    >>> x = torch.empty(2, 3, 5, 7, names=('N', 'C', 'H', 'W'))
    >>> x.rename(W='width', H='height').names
    ('N', 'C', 'height', 'width')

    ```

    Finally, tensor.rename has an in-place version called tensor.rename_.
    r   zW: This function takes either positional args or keyword args, but not both. Use tensor.z!(*names) to name dims and tensor.z(**rename_map) to rename dims.)r   boolr   r&   r@   rH   )r   r   rD   r%   r   has_rename_pairss         r	   update_namesrL   l   s    F E

QIJ'' 
% 
g&&  >LW>U>U '5g'>'>  
 
 	
  >- >%feW=== >%feW===$VZAAAr   N)collectionsr   r
   r   r!   r&   r*   r2   r6   r;   r=   r@   rH   rL   r   r   r	   <module>rN      s    # # # # # #
 
 
  	 	 	  - - -	 	 	@ @ @L L LK K K  B B B3B 3B 3B 3B 3Br   