
    [Th                     Z    S SK Jr   S rS rS rS rS rS rS rS	 r	S
 r
S rS rS rg)    )OrderedDictc                 D    U R                  5       (       a  [        S5      eg )NzzNYI: Named tensors don't support serialization. Please drop names via `tensor = tensor.rename(None)` before serialization.)	has_namesRuntimeError)tensors    T/var/www/auris/envauris/lib/python3.13/site-packages/torch/_namedtensor_internals.pycheck_serializing_named_tensorr	      s)    M
 	
     c                     [        [        U R                  5       VVs/ s H  u  pUc  UOUU4PM     snn5      $ s  snnf )zgReturns a map of { dim: dim_name } where dim is a name if the dim is named
and the dim index otherwise.)r   	enumeratenames)r   idxnames      r   build_dim_mapr      s>     @I&,,@WX@W93#4	.@WX Xs   ;
c                 
   [        U [        5      (       a  U R                  5       n [        U S5      (       d,  [        U [        5      (       d  [        S[        U 5       35      e[        U 5      S:X  a  [        S5      e[        U 6 $ )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      sz    *k**%%'
:z**:j%3P3PPQUV`QaPbc
 	
 :!>??
r
   c                     U (       a  gg)Nrename_rename )inplaces    r   namer_api_namer!   (   s    r
   c                 ,    U [         :H  =(       d    U S:H  $ )Nz...)Ellipsis)items    r   is_ellipsisr%   /   s    8,tu},r
   c                     [        U 5       VVs/ s H  u  p#[        U5      (       d  M  UPM     nnn[        U5      S:  a  [        U SU  S35      e[        U5      S:X  a  US   $ g s  snnf )N   z1: More than one Ellipsis ('...') found in names (z-). This function supports up to one Ellipsis.   r   )r   r%   r   r   )r   fn_nameir   ellipsis_indicess        r   single_ellipsis_indexr,   3   s|    )25)9O)9ga[=N)9O
!iHgBD
 	
 !"" Ps
   A'A'c                 "    X [        U5      U-
   $ )N)r   )numel_pre_globnumel_post_globr   s      r   expand_single_ellipsisr0   ?   s    #e*">??r
   c                 Z    [        U [        U5      U -
  S-
  U5      nUS U  U-   XS-   S  -   $ )Nr(   )r0   r   )ellipsis_idxr   tensor_namesglobbed_namess       r   replace_ellipsis_by_positionr5   C   sE    *c%j</!3\M ,-/%q8H8J2KKKr
   c                 :    [        X5      nUc  U $ [        X0U5      $ )zP
Expands ... inside `names` to be equal to a list of names from `tensor_names`.
)r,   r5   )r   r3   r)   r2   s       r   resolve_ellipsisr7   J   s&     )8L'\JJr
   c           	          [        U5      S:X  a  US   c  U R                  S U5      $ U R                  [        XR                  [	        U5      5      U5      $ )Nr(   r   )r   _update_namesr7   r   r!   )r   r   r    s      r   update_names_with_listr:   T   sQ    
5zQ58+##D'22nW.EF r
   c                 (   [        U 5      nUR                  5        HK  nX   nXCR                  5       ;   a  XSU'   M   [        [        U5       SU SU SU R                   SU S3
5      e   U R                  [        UR                  5       5      U5      $ )Nz: Tried to rename dim 'z	' to dim z in Tensor[z] but dim 'z' does not exist)r   keysr   r!   r   r9   r   values)r   
rename_mapr    dim_mapold_dimnew_dims         r   update_names_with_mappingrB   ^   s    F#G??$%lln$&G!'*++B7)9);v||nKyHXZ  % gnn&6 7AAr
   c           	          [        U5      S:  n[        U5      nU(       a6  U(       a/  [        [        U5       S[        U5       S[        U5       S35      eU(       d  U(       d  [	        XU5      $ U(       a  [	        XU5      $ [        XU5      $ )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:   rB   )r   r   r>   r    r   has_rename_pairss         r   update_namesrF   l   s    F E
QIJ'%g&' (>>LW>U=V W''5g'>&? @
 	
 -%fW==%fW==$VAAr
   N)collectionsr   r	   r   r   r!   r%   r,   r0   r5   r7   r:   rB   rF   r   r
   r   <module>rH      sN    #
	-	@LKB3Br
   