
    ^j,                     l    d dl Z d dlmZ  G d dej                        Z G d dej                        Zy)    Nc                   j     e Zd ZU dZej
                  j                  e   ed<   ddef fdZ	d Z
 xZS )SpaceToDepthzRearrange spatial dimensions into channel dimension.

    Divides spatial dimensions by block_size and multiplies channels by block_size^2.
    Used in TResNet as an efficient stem operation.

    Args:
        block_size: Spatial reduction factor.
    bs
block_sizec                 >    t         |           |dk(  sJ || _        y )N   super__init__r   selfr   	__class__s     e/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/layers/space_to_depth.pyr   zSpaceToDepth.__init__   s!    Q    c                    |j                         \  }}}}|j                  |||| j                  z  | j                  || j                  z  | j                        }|j                  dddddd      j	                         }|j                  ||| j                  z  | j                  z  || j                  z  || j                  z        }|S )Nr               r   sizeviewr   permute
contiguousr   xNCHWs         r   forwardzSpaceToDepth.forward   s    VVX
1aFF1adggtwwTWWdggFIIaAq!Q'224FF1a$''kDGG+Q$''\1<Hr   )r   )__name__
__module____qualname____doc__torchjitFinalint__annotations__r   r!   __classcell__r   s   @r   r   r      s.     			3 
r   r   c                   (     e Zd ZdZ fdZd Z xZS )DepthToSpacezRearrange channel dimension into spatial dimensions.

    Inverse of SpaceToDepth. Divides channels by block_size^2 and multiplies
    spatial dimensions by block_size.

    Args:
        block_size: Spatial expansion factor.
    c                 0    t         |           || _        y )Nr	   r   s     r   r   zDepthToSpace.__init__'   s    r   c                 h   |j                         \  }}}}|j                  || j                  | j                  || j                  dz  z  ||      }|j                  dddddd      j	                         }|j                  ||| j                  dz  z  || j                  z  || j                  z        }|S )Nr   r   r   r   r   r   r   r   s         r   r!   zDepthToSpace.forward+   s    VVX
1aFF1dggtwwdggl(;QBIIaAq!Q'224FF1aDGGqL)1tww;DGGDr   )r"   r#   r$   r%   r   r!   r+   r,   s   @r   r.   r.      s    r   r.   )r&   torch.nnnnModuler   r.    r   r   <module>r5      s+     299 0299 r   