
    N j>                        S SK Jr  S SKJrJr  \(       a  S SKJr  SSKJr  S SK	r	 " S S5      r
SS	 jr S         SS
 jjrg)    )annotations)TYPE_CHECKINGUnion)Sequence   DimNc                  j    \ rS rSr% S\S'   SSS jjrSS jrSS jrSS jrSS	 jr	SS
 jr
SS jrSrg)DimEntry   zUnion[Dim, int]dataNc                    SSK Jn  [        U5      [        L a  US:  a  [	        SU 35      eO-Uc  SnO'[        X5      (       d  [	        S[        U5       35      eXl        g )Nr   r   r   zExpected negative int, got zExpected Dim, got ) r	   typeintAssertionError
isinstancer   )selfr   r	   s      i/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/functorch/dim/_dim_entry.py__init__DimEntry.__init__   sa    :qy$'B4&%IJJ \Dd(($'9$t*%FGG	    c                :   [        U[        5      (       d  gU R                  5       (       a.  UR                  5       (       a  U R                  UR                  :H  $ U R                  5       (       d-  UR                  5       (       d  U R                  UR                  L $ g)NF)r   r   is_positionalr   )r   others     r   __eq__DimEntry.__eq__!   sy    %** E$7$7$9$999

**##%%e.A.A.C.C99

** r   c                d    [        U R                  5      [        L =(       a    U R                  S:  $ )Nr   )r   r   r   r   s    r   r   DimEntry.is_positional0   s"    DII#%7$))a-7r   c                d    SSK Jn  [        U R                  U5      (       a  gU R                  S:H  $ )Nr   r   Fr   )r   r	   r   r   )r   r	   s     r   is_noneDimEntry.is_none3   s)    dii%% 99>!r   c                    [        U R                  [        5      (       d!  [        S[	        U R                  5       35      eU R                  $ )NzExpected int, got )r   r   r   r   r   r   s    r   positionDimEntry.position>   s9    $))S)) #5d499o5F!GHHyyr   c                n    [        U R                  [        5      (       a  [        S5      eU R                  $ )NzExpected Dim, got int)r   r   r   r   r   s    r   dimDimEntry.dimC   s)    dii%% !899yyr   c                ,    [        U R                  5      $ N)reprr   r   s    r   __repr__DimEntry.__repr__H   s    DIIr   )r   r+   )r   zUnion[Dim, int, None]returnNone)r   objectr/   bool)r/   r2   )r/   r   )r/   r	   )r/   str)__name__
__module____qualname____firstlineno____annotations__r   r   r   r"   r%   r(   r-   __static_attributes__ r   r   r   r      s+    
8	"

r   r   c                T    SnU  H  nUR                  5       (       d  M  US-  nM!     U$ )Nr   r   )r   )levelsrls      r   ndim_of_levelsr?   L   s.    	A??FA  Hr   c                R   X:X  a  U $ U R                  5       nU R                  5       nU(       d#  [        U5      [        U5      :  a  [        S5      e/ n/ nU H;  n UR	                  U5      n	UR                  XI   5        UR                  XY   5        M=     U R                  XgU R                  5       5      $ ! [         ae    UR                  5       (       a  UR                  S5        O)UR                  UR                  5       R                   5        UR                  S5         M  f = f)a"  
Reshape a tensor to match target levels using as_strided.

Args:
    tensor: Input tensor to reshape
    from_levels: Current levels of the tensor
    to_levels: Target levels to match
    drop_levels: If True, missing dimensions are assumed to have stride 0

Returns:
    Reshaped tensor
z,Cannot expand dimensions without drop_levelsr   r   )sizestridelenr   indexappend
ValueErrorr   r(   
as_stridedstorage_offset)
tensorfrom_levels	to_levelsdrop_levelssizesstrides	new_sizesnew_strideslevelidxs
             r   _match_levelsrS   T   s   $ KKMEmmoG{c)n, !OPPIK	-##E*C UZ(w|,  YV5J5J5LMM  	"""$$  #  !1!12q!	"s   B77A+D&%D&)r<   zSequence[DimEntry]r/   r   )F)
rI   torch.TensorrJ   list[DimEntry]rK   rU   rL   r2   r/   rT   )
__future__r   typingr   r   collections.abcr   r   r	   torchr   r?   rS   r:   r   r   <module>rZ      sg    " ' ( 
9 9x 	.N.N.N .N 	.N
 .Nr   