
    /jbR                    F   d Z ddlmZ ddlZddlZddlZddlmZ dZ	d#dZ
 G d dej                  Z G d	 d
e          Z G d dej                  Z G d de          Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d d ej                  Z G d! d"ej                  ZdS )$zConvolution modules.    )annotationsN)CBAMChannelAttentionConcatConvConv2ConvTransposeDWConvDWConvTranspose2dFocus	GhostConvIndex	LightConvRepConvSpatialAttention   c                    dk    r.t          | t                    r| dz
  z  dz   nfd| D             } |&t          | t                    r| dz  nd | D             }|S )zPad to 'same' shape outputs.r   c                &    g | ]}|d z
  z  d z   S r    ).0xds     `/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/nn/modules/conv.py
<listcomp>zautopad.<locals>.<listcomp>!   s%    7S7S7SAQUa7S7S7S    N   c                    g | ]}|d z  S r   r   r   r   s     r   r   zautopad.<locals>.<listcomp>#   s    .A.A.A!qAv.A.A.Ar   )
isinstanceint)kpr   s     `r   autopadr%      s{    1uu)!S11SAQK!OO7S7S7S7SQR7S7S7Sy C((AAFF.A.Aq.A.A.AHr   c                  N     e Zd ZdZ ej                    Zd fd	Zd Zd Z	 xZ
S )	r   a:  Standard convolution module with batch normalization and activation.

    Attributes:
        conv (nn.Conv2d): Convolutional layer.
        bn (nn.BatchNorm2d): Batch normalization layer.
        act (nn.Module): Activation function layer.
        default_act (nn.Module): Default activation function (SiLU).
    r   NTc	                X   t                                                       t          j        ||||t	          |||          ||d          | _        t          j        |          | _        |du r| j        n.t          |t          j
                  r|nt          j                    | _        dS )a  Initialize Conv layer with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p (int, optional): Padding.
            g (int): Groups.
            d (int): Dilation.
            act (bool | nn.Module): Activation function.
        FgroupsdilationbiasTN)super__init__nnConv2dr%   convBatchNorm2dbndefault_actr!   ModuleIdentityact
selfc1c2r#   sr$   gr   r6   	__class__s
            r   r-   zConv.__init__3   s     	Ib"aGAq!,<,<QQRY^___	.$$'*d{{4##z#ry?Y?Y8l_a_j_l_lr   c                x    |                      |                     |                     |                              S zApply convolution, batch normalization and activation to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        r6   r2   r0   r8   r   s     r   forwardzConv.forwardE   ,     xx		!--...r   c                R    |                      |                     |                    S )zApply convolution and activation without batch normalization.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        r6   r0   rA   s     r   forward_fusezConv.forward_fuseP         xx		!%%%r   )r   r   Nr   r   T__name__
__module____qualname____doc__r.   SiLUr3   r-   rB   rF   __classcell__r=   s   @r   r   r   '   sz          "'))Km m m m m m$	/ 	/ 	/	& 	& 	& 	& 	& 	& 	&r   r   c                  6     e Zd ZdZd
 fd	Zd Zd Zd	 Z xZS )r   a"  Simplified RepConv module with Conv fusing.

    Attributes:
        conv (nn.Conv2d): Main 3x3 convolutional layer.
        cv2 (nn.Conv2d): Additional 1x1 convolutional layer.
        bn (nn.BatchNorm2d): Batch normalization layer.
        act (nn.Module): Activation function layer.
       r   NTc	                    t                                          ||||||||           t          j        ||d|t	          d||          ||d          | _        dS )a  Initialize Conv2 layer with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p (int, optional): Padding.
            g (int): Groups.
            d (int): Dilation.
            act (bool | nn.Module): Activation function.
        r<   r   r6   r   Fr(   N)r,   r-   r.   r/   r%   cv2r7   s
            r   r-   zConv2.__init__f   sb     	RAqA<<<9RQ71a+;+;APQX]^^^r   c                    |                      |                     |                     |          |                     |          z                       S r?   )r6   r2   r0   rT   rA   s     r   rB   zConv2.forwardv   s;     xx		!txx{{ :;;<<<r   c                x    |                      |                     |                     |                              S )zApply fused convolution, batch normalization and activation to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        r@   rA   s     r   rF   zConv2.forward_fuse   rC   r   c                   t          j        | j        j        j                  }d |j        dd         D             }| j        j        j                                        |dddd|d         |d         dz   |d         |d         dz   f<   | j        j        xj        |z  c_        |                     d           | j	        | _
        dS )zFuse parallel convolutions.c                    g | ]}|d z  S r   r   r    s     r   r   z$Conv2.fuse_convs.<locals>.<listcomp>   s    )))Q!V)))r   r   Nr   r   rT   )torch
zeros_liker0   weightdatashaperT   clone__delattr__rF   rB   )r8   wis      r   
fuse_convszConv2.fuse_convs   s    TY-233))QWQRR[)))48HO4H4N4N4P4P!!!QQQ!qtax1!q
01	"(r   )rQ   r   Nr   r   T)	rI   rJ   rK   rL   r-   rB   rF   rb   rN   rO   s   @r   r   r   \   sz         _ _ _ _ _ _ 	= 	= 	=	/ 	/ 	/) ) ) ) ) ) )r   r   c                  H     e Zd ZdZd ej                    f fd	Zd Z xZS )r   a   Light convolution module with 1x1 and depthwise convolutions.

    This implementation is based on the PaddleDetection HGNetV2 backbone.

    Attributes:
        conv1 (Conv): 1x1 convolution layer.
        conv2 (DWConv): Depthwise convolution layer.
    r   c                    t                                                       t          ||dd          | _        t	          ||||          | _        dS )a  Initialize LightConv layer with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size for depthwise convolution.
            act (nn.Module): Activation function.
        r   Fr6   N)r,   r-   r   conv1r
   conv2)r8   r9   r:   r#   r6   r=   s        r   r-   zLightConv.__init__   sO     	"b!///
BA3///


r   c                R    |                      |                     |                    S )zApply 2 convolutions to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        )rg   rf   rA   s     r   rB   zLightConv.forward   s      zz$**Q--(((r   )	rI   rJ   rK   rL   r.   ReLUr-   rB   rN   rO   s   @r   r   r      se          "#		 0 0 0 0 0 0	) 	) 	) 	) 	) 	) 	)r   r   c                  $     e Zd ZdZd fd	Z xZS )r
   zDepth-wise convolution module.r   Tc           
     ~    t                                          ||||t          j        ||          ||           dS )aH  Initialize depth-wise convolution with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            d (int): Dilation.
            act (bool | nn.Module): Activation function.
        rS   Nr,   r-   mathgcd)r8   r9   r:   r#   r;   r   r6   r=   s          r   r-   zDWConv.__init__   s>     	RA"b)9)9QCHHHHHr   r   r   r   TrI   rJ   rK   rL   r-   rN   rO   s   @r   r
   r
      sM        ((I I I I I I I I I Ir   r
   c                  $     e Zd ZdZd fd	Z xZS )r   z(Depth-wise transpose convolution module.r   r   c                ~    t                                          ||||||t          j        ||                     dS )a?  Initialize depth-wise transpose convolution with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p1 (int): Padding.
            p2 (int): Output padding.
        )r)   Nrl   )r8   r9   r:   r#   r;   p1p2r=   s          r   r-   zDWConvTranspose2d.__init__   s>     	RAr2dhr26F6FGGGGGr   )r   r   r   r   rp   rO   s   @r   r   r      sM        22H H H H H H H H H Hr   r   c                  N     e Zd ZdZ ej                    Zd fd	Zd Zd Z	 xZ
S )	r	   an  Convolution transpose module with optional batch normalization and activation.

    Attributes:
        conv_transpose (nn.ConvTranspose2d): Transposed convolution layer.
        bn (nn.BatchNorm2d | nn.Identity): Batch normalization layer.
        act (nn.Module): Activation function layer.
        default_act (nn.Module): Default activation function (SiLU).
    r   r   Tc                b   t                                                       t          j        ||||||           | _        |rt          j        |          nt          j                    | _        |du r| j        n.t          |t          j
                  r|nt          j                    | _        dS )at  Initialize ConvTranspose layer with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p (int): Padding.
            bn (bool): Use batch normalization.
            act (bool | nn.Module): Activation function.
        r+   TN)r,   r-   r.   ConvTranspose2dconv_transposer1   r5   r2   r3   r!   r4   r6   )	r8   r9   r:   r#   r;   r$   r2   r6   r=   s	           r   r-   zConvTranspose.__init__   s     	 0RAq2vNNN(*=".$$$'*d{{4##z#ry?Y?Y8l_a_j_l_lr   c                x    |                      |                     |                     |                              S )zApply transposed convolution, batch normalization and activation to input.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        )r6   r2   ry   rA   s     r   rB   zConvTranspose.forward   s0     xx 3 3A 6 677888r   c                R    |                      |                     |                    S )zApply convolution transpose and activation to input.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        )r6   ry   rA   s     r   rF   zConvTranspose.forward_fuse  s$     xx++A..///r   )r   r   r   TTrH   rO   s   @r   r	   r	      sz          "'))Km m m m m m"	9 	9 	9	0 	0 	0 	0 	0 	0 	0r   r	   c                  *     e Zd ZdZd fd	Zd Z xZS )r   zFocus module for concentrating feature information.

    Slices input tensor into 4 parts and concatenates them in the channel dimension.

    Attributes:
        conv (Conv): Convolution layer.
    r   NTc           	         t                                                       t          |dz  ||||||          | _        dS )ad  Initialize Focus module with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p (int, optional): Padding.
            g (int): Groups.
            act (bool | nn.Module): Activation function.
           re   N)r,   r-   r   r0   )	r8   r9   r:   r#   r;   r$   r<   r6   r=   s	           r   r-   zFocus.__init__  sA     	aQ1aS999			r   c                    |                      t          j        |dddddddf         |dddddddf         |dddddddf         |dddddddf         fd                    S )a  Apply Focus operation and convolution to input tensor.

        Input shape is (B, C, H, W) and output shape is (B, c2, H/2, W/2).

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        .Nr   r   )r0   rY   catrA   s     r   rB   zFocus.forward(  s     yyAc33Q3!m$4aQTT33Q36G3PSPSRSPSUVUYXYUY>IZ\]^acdcgfgcgijimlmim^m\n#oqrsstttr   )r   r   Nr   TrI   rJ   rK   rL   r-   rB   rN   rO   s   @r   r   r     s]         : : : : : : u u u u u u ur   r   c                  *     e Zd ZdZd fd	Zd Z xZS )r   a&  Ghost Convolution module.

    Generates more features with fewer parameters by using cheap operations.

    Attributes:
        cv1 (Conv): Primary convolution.
        cv2 (Conv): Cheap operation convolution.

    References:
        https://github.com/huawei-noah/Efficient-AI-Backbones
    r   Tc           	         t                                                       |dz  }t          ||||d||          | _        t          ||ddd||          | _        dS )aH  Initialize Ghost Convolution module with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            g (int): Groups.
            act (bool | nn.Module): Activation function.
        r   Nre      r   )r,   r-   r   cv1rT   )	r8   r9   r:   r#   r;   r<   r6   c_r=   s	           r   r-   zGhostConv.__init__D  sd     	1WB1dA3777B1dBC888r   c                    |                      |          }t          j        ||                     |          fd          S )zApply Ghost Convolution to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor with concatenated features.
        r   )r   rY   r   rT   )r8   r   ys      r   rB   zGhostConv.forwardT  s4     HHQKKy!TXXa[[)1---r   ro   r   rO   s   @r   r   r   7  sV        
 
9 9 9 9 9 9 
. 
. 
. 
. 
. 
. 
.r   r   c                  v     e Zd ZdZ ej                    Zd fd	Zd Zd Z	d	 Z
ed
             Zd Zd Z xZS )r   a  RepConv module with training and deploy modes.

    This module is used in RT-DETR and can fuse convolutions during inference for efficiency.

    Attributes:
        conv1 (Conv): 3x3 convolution.
        conv2 (Conv): 1x1 convolution.
        bn (nn.BatchNorm2d, optional): Batch normalization for identity branch.
        act (nn.Module): Activation function.
        default_act (nn.Module): Default activation function (SiLU).

    References:
        https://github.com/DingXiaoH/RepVGG/blob/main/repvgg.py
    rQ   r   TFc           	        t                                                       |dk    r|dk    sJ || _        || _        || _        |du r| j        n.t          |t          j                  r|nt          j	                    | _
        |	r!||k    r|dk    rt          j        |          nd| _        t          ||||||d          | _        t          ||d|||dz  z
  |d          | _        dS )	a  Initialize RepConv module with given parameters.

        Args:
            c1 (int): Number of input channels.
            c2 (int): Number of output channels.
            k (int): Kernel size.
            s (int): Stride.
            p (int): Padding.
            g (int): Groups.
            d (int): Dilation.
            act (bool | nn.Module): Activation function.
            bn (bool): Use batch normalization for identity branch.
            deploy (bool): Deploy mode for inference.
        rQ   r   T)num_featuresNF)r$   r<   r6   r   )r,   r-   r<   r9   r:   r3   r!   r.   r4   r5   r6   r1   r2   r   rf   rg   )r8   r9   r:   r#   r;   r$   r<   r   r6   r2   deployr=   s              r   r-   zRepConv.__init__s  s     	Avv!q&&& '*d{{4##z#ry?Y?Y8l_a_j_l_l57YB"HHa".b1111UY"b!Q!qe<<<
"b!Q1qAv:!GGG


r   c                R    |                      |                     |                    S )zForward pass for deploy mode.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        rE   rA   s     r   rF   zRepConv.forward_fuse  rG   r   c                    | j         dn|                      |          }|                     |                     |          |                     |          z   |z             S )zForward pass for training mode.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Output tensor.
        Nr   )r2   r6   rf   rg   )r8   r   id_outs      r   rB   zRepConv.forward  sM     go4771::xx

1

15>???r   c                    |                      | j                  \  }}|                      | j                  \  }}|                      | j                  \  }}||                     |          z   |z   ||z   |z   fS )zCalculate equivalent kernel and bias by fusing convolutions.

        Returns:
            (torch.Tensor): Equivalent kernel
            (torch.Tensor): Equivalent bias
        )_fuse_bn_tensorrf   rg   r2   _pad_1x1_to_3x3_tensor)r8   	kernel3x3bias3x3	kernel1x1bias1x1kernelidbiasids          r   get_equivalent_kernel_biasz"RepConv.get_equivalent_kernel_bias  s     "11$*==	7!11$*==	7//88&466yAAAHLgX_N_bhNhhhr   c                X    | dS t           j        j                            | g d          S )zPad a 1x1 kernel to 3x3 size.

        Args:
            kernel1x1 (torch.Tensor): 1x1 convolution kernel.

        Returns:
            (torch.Tensor): Padded 3x3 kernel.
        Nr   )r   r   r   r   )rY   r.   
functionalpad)r   s    r   r   zRepConv._pad_1x1_to_3x3_tensor  s.     18&**9lllCCCr   c                   |dS t          |t                    rI|j        j        }|j        j        }|j        j        }|j        j        }|j        j        }|j        j        }nt          |t          j
                  rt          | d          s| j        | j        z  }t          j        | j        |ddft          j                  }	t#          | j                  D ]}
d|	|
|
|z  ddf<   t%          j        |	                              |j        j                  | _        | j        }|j        }|j        }|j        }|j        }|j        }||z                                   }||z                      dddd          }||z  |||z  |z  z
  fS )zFuse batch normalization with convolution weights.

        Args:
            branch (Conv | nn.BatchNorm2d | None): Branch to fuse.

        Returns:
            kernel (torch.Tensor): Fused kernel.
            bias (torch.Tensor): Fused bias.
        N)r   r   	id_tensorrQ   )dtyper   )r!   r   r0   r[   r2   running_meanrunning_varr+   epsr.   r1   hasattrr9   r<   npzerosfloat32rangerY   
from_numpytodevicer   sqrtreshape)r8   branchkernelr   r   gammabetar   	input_dimkernel_valuera   stdts                r   r   zRepConv._fuse_bn_tensor  s    >4fd## 	['F!91L )/KI$E9>D)-CC// 	4-- Y Gtv-	!x)Q(B"*UUUtw = =A;<LA	M1a!788!&!1,!?!?!B!B6=CW!X!X^F!.L ,KME;D*CS &&((S[!!"aA..z4,"6"<<<<r   c           
     b   t          | d          rdS |                                 \  }}t          j        | j        j        j        | j        j        j        | j        j        j        | j        j        j	        | j        j        j
        | j        j        j        | j        j        j        d                              d          | _        || j        j        _        || j        j        _        |                                 D ]}|                                 |                     d           |                     d           t          | d          r|                     d           t          | d	          r|                     d	           t          | d
          r|                     d
           dS dS )zLFuse convolutions for inference by creating a single equivalent convolution.r0   NT)in_channelsout_channelskernel_sizestridepaddingr*   r)   r+   Frf   rg   nmr2   r   )r   r   r.   r/   rf   r0   r   r   r   r   r   r*   r)   requires_grad_r[   r\   r+   
parametersdetach_r_   )r8   r   r+   paras       r   rb   zRepConv.fuse_convs  s   4   	F6688I
35
3:?)JO+Z_-:?)	
 	
 	
 .

 		 !'	"	OO%% 	 	DLLNNNN!!!!!!4 	#T"""4 	#T"""4%% 	*[)))))	* 	*r   )rQ   r   r   r   r   TFF)rI   rJ   rK   rL   r.   rM   r3   r-   rF   rB   r   staticmethodr   r   rb   rN   rO   s   @r   r   r   a  s          "'))KH H H H H H4	& 	& 	&
@ 
@ 
@
i 
i 
i D D \D"= "= "=H* * * * * * *r   r   c                  ,     e Zd ZdZd
 fdZdd	Z xZS )r   a  Channel-attention module for feature recalibration.

    Applies attention weights to channels based on global average pooling.

    Attributes:
        pool (nn.AdaptiveAvgPool2d): Global average pooling.
        fc (nn.Conv2d): Fully connected layer implemented as 1x1 convolution.
        act (nn.Sigmoid): Sigmoid activation for attention weights.

    References:
        https://github.com/open-mmlab/mmdetection/tree/v3.0.0rc1/configs/rtmdet
    channelsr"   returnNonec                    t                                                       t          j        d          | _        t          j        ||dddd          | _        t          j                    | _        dS )zrInitialize Channel-attention module.

        Args:
            channels (int): Number of input channels.
        r   r   Trw   N)	r,   r-   r.   AdaptiveAvgPool2dpoolr/   fcSigmoidr6   )r8   r   r=   s     r   r-   zChannelAttention.__init__  s\     	(++	)Hh1adCCC:<<r   r   torch.Tensorc                ~    ||                      |                     |                     |                              z  S )zApply channel attention to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Channel-attended output tensor.
        )r6   r   r   rA   s     r   rB   zChannelAttention.forward  s1     488DGGDIIaLL112222r   )r   r"   r   r   )r   r   r   r   r   rO   s   @r   r   r      s[         	  	  	  	  	  	 	3 	3 	3 	3 	3 	3 	3 	3r   r   c                  *     e Zd ZdZd fd	Zd Z xZS )r   a!  Spatial-attention module for feature recalibration.

    Applies attention weights to spatial dimensions based on channel statistics.

    Attributes:
        cv1 (nn.Conv2d): Convolution layer for spatial attention.
        act (nn.Sigmoid): Sigmoid activation for attention weights.
       c                    t                                                       |dv s
J d            |dk    rdnd}t          j        dd||d          | _        t          j                    | _        d	S )
zInitialize Spatial-attention module.

        Args:
            kernel_size (int): Size of the convolutional kernel (3 or 7).
        >   rQ   r   zkernel size must be 3 or 7r   rQ   r   r   F)r   r+   N)r,   r-   r.   r/   r   r   r6   )r8   r   r   r=   s      r   r-   zSpatialAttention.__init__/  su     	f$$$&B$$$"a''!!Q9Q;eLLL:<<r   c                    ||                      |                     t          j        t          j        |dd          t          j        |dd          d         gd                              z  S )zApply spatial attention to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Spatial-attended output tensor.
        r   T)keepdimr   )r6   r   rY   r   meanmaxrA   s     r   rB   zSpatialAttention.forward;  sf     488DHHUY
1a0N0N0NPUPYZ[]^hlPmPmPmnoPp/qst%u%uvvwwwwr   r   r   rO   s   @r   r   r   %  s]         
  
  
  
  
  
 	x 	x 	x 	x 	x 	x 	xr   r   c                  *     e Zd ZdZd fd	Zd Z xZS )r   a(  Convolutional Block Attention Module.

    Combines channel and spatial attention mechanisms for comprehensive feature refinement.

    Attributes:
        channel_attention (ChannelAttention): Channel attention module.
        spatial_attention (SpatialAttention): Spatial attention module.
    r   c                    t                                                       t          |          | _        t	          |          | _        dS )zInitialize CBAM with given parameters.

        Args:
            c1 (int): Number of input channels.
            kernel_size (int): Size of the convolutional kernel for spatial attention.
        N)r,   r-   r   channel_attentionr   spatial_attention)r8   r9   r   r=   s      r   r-   zCBAM.__init__Q  sA     	!1"!5!5!1+!>!>r   c                R    |                      |                     |                    S )zApply channel and spatial attention sequentially to input tensor.

        Args:
            x (torch.Tensor): Input tensor.

        Returns:
            (torch.Tensor): Attended output tensor.
        )r   r   rA   s     r   rB   zCBAM.forward\  s&     %%d&<&<Q&?&?@@@r   r   r   rO   s   @r   r   r   G  s]         	? 	? 	? 	? 	? 	?	A 	A 	A 	A 	A 	A 	Ar   r   c                  ,     e Zd ZdZd fd	ZddZ xZS )	r   zConcatenate a list of tensors along specified dimension.

    Attributes:
        d (int): Dimension along which to concatenate tensors.
    r   c                V    t                                                       || _        dS )z|Initialize Concat module.

        Args:
            dimension (int): Dimension along which to concatenate tensors.
        N)r,   r-   r   )r8   	dimensionr=   s     r   r-   zConcat.__init__o  s&     	r   r   list[torch.Tensor]c                6    t          j        || j                  S )zConcatenate input tensors along specified dimension.

        Args:
            x (list[torch.Tensor]): List of input tensors.

        Returns:
            (torch.Tensor): Concatenated tensor.
        )rY   r   r   rA   s     r   rB   zConcat.forwardx  s     yDF###r   r   r   r   r   rO   s   @r   r   r   h  s[              	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$r   r   c                  ,     e Zd ZdZd fd	ZddZ xZS )	r   zoReturns a particular index of the input.

    Attributes:
        index (int): Index to select from input.
    r   c                V    t                                                       || _        dS )zeInitialize Index module.

        Args:
            index (int): Index to select from input.
        N)r,   r-   index)r8   r   r=   s     r   r-   zIndex.__init__  s&     	


r   r   r   c                    || j                  S )zSelect and return a particular index from input.

        Args:
            x (list[torch.Tensor]): List of input tensors.

        Returns:
            (torch.Tensor): Selected tensor.
        )r   rA   s     r   rB   zIndex.forward  s     }r   )r   r   r   rO   s   @r   r   r     s[              	 	 	 	 	 	 	 	r   r   )Nr   )rL   
__future__r   rm   numpyr   rY   torch.nnr.   __all__r%   r4   r   r   r   r
   rx   r   r	   r   r   r   r   r   r   r   r   r   r   r   <module>r      s     " " " " " "            $   2& 2& 2& 2& 2&29 2& 2& 2&j7) 7) 7) 7) 7)D 7) 7) 7)t )  )  )  )  )	  )  )  )FI I I I IT I I I"H H H H H* H H H"10 10 10 10 10BI 10 10 10h$u $u $u $u $uBI $u $u $uP'. '. '. '. '.	 '. '. '.T\* \* \* \* \*bi \* \* \*~"3 "3 "3 "3 "3ry "3 "3 "3Jx x x x xry x x xDA A A A A29 A A AB$ $ $ $ $RY $ $ $8    BI     r   