
    hS                    j   S r SSKJr  SSKrSSKrSSKrSSKJr  Sr	S"S jr
 " S S\R                  5      r " S S	\5      r " S
 S\R                  5      r " S S\5      r " S S\R                   5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S S\R                  5      r " S  S!\R                  5      rg)#zConvolution modules.    )annotationsN)ConvConv2	LightConvDWConvDWConvTranspose2dConvTransposeFocus	GhostConvChannelAttentionSpatialAttentionCBAMConcatRepConvIndexc                    US:  a:  [        U [        5      (       a
  X S-
  -  S-   OU  Vs/ s H  o2US-
  -  S-   PM     snn Uc/  [        U [        5      (       a  U S-  OU  Vs/ s H  o3S-  PM	     snnU$ s  snf s  snf )zPad to 'same' shape outputs.      )
isinstanceint)kpdxs       U/home/james-whalen/.local/lib/python3.13/site-packages/ultralytics/nn/modules/conv.pyautopadr      s}    1u)!S11AQK!OQR7SQRAQUaQR7Sy C((AFq.Aq!Avq.AH 8T.As   A5"A:c                  ^   ^  \ rS rSrSr\R                  " 5       rSU 4S jjrS r	S r
SrU =r$ )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).
c	                T  > [         T	U ]  5         [        R                  " XX4[	        X5U5      XgSS9U l        [        R                  " U5      U l        USL a  U R                  U l        g[        U[        R                  5      (       a  Xl        g[        R                  " 5       U l        g)a2  
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   r.   	__class__s
            r   r%   Conv.__init__4   sw     	IIbaGA!,<QY^_	..$'*d{4##z#ryy?Y?Y_a_j_j_l    c                `    U R                  U R                  U R                  U5      5      5      $ z
Apply convolution, batch normalization and activation to input tensor.

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

Returns:
    (torch.Tensor): Output tensor.
r.   r*   r(   r0   r   s     r   forwardConv.forwardG   $     xx		!-..r7   c                B    U R                  U R                  U5      5      $ )z
Apply convolution and activation without batch normalization.

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

Returns:
    (torch.Tensor): Output tensor.
r.   r(   r;   s     r   forward_fuseConv.forward_fuseS        xx		!%%r7   r:   )r   r   Nr   r   T__name__
__module____qualname____firstlineno____doc__r&   SiLUr+   r%   r<   rA   __static_attributes____classcell__r5   s   @r   r   r   '   s*     '')Km&
/
& 
&r7   r   c                  B   ^  \ rS rSrSrSU 4S jjrS rS rS rSr	U =r
$ )	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.
c	                v   > [         T	U ]  XX4XVXxS9  [        R                  " XSU[	        SXW5      XgSS9U l        g)a3  
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.
r4   r   r.   r   Fr    N)r$   r%   r&   r'   r   cv2r/   s
            r   r%   Conv2.__init__k   s=     	q<99RQ71a+;AX]^r7   c                    U R                  U R                  U R                  U5      U R                  U5      -   5      5      $ r9   )r.   r*   r(   rR   r;   s     r   r<   Conv2.forward|   s1     xx		!txx{ :;<<r7   c                `    U R                  U R                  U R                  U5      5      5      $ )z
Apply fused convolution, batch normalization and activation to input tensor.

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

Returns:
    (torch.Tensor): Output tensor.
r:   r;   s     r   rA   Conv2.forward_fuse   r>   r7   c                   [         R                  " U R                  R                  R                  5      nUR
                  SS  Vs/ s H  o"S-  PM	     nnU R                  R                  R                  R                  5       USS2SS2US   US   S-   2US   US   S-   24'   U R                  R                  =R                  U-  sl        U R                  S5        U R                  U l
        gs  snf )zFuse parallel convolutions.r   Nr   r   rR   )torch
zeros_liker(   weightdatashaperR   clone__delattr__rA   r<   )r0   wr   is       r   
fuse_convsConv2.fuse_convs   s    TYY--223WWQR[)[!V[)48HHOO4H4H4N4N4P!Q!qtax1!q
01		"((	 *s   C1)rR   r<   )   r   Nr   r   T)rE   rF   rG   rH   rI   r%   r<   rA   rb   rK   rL   rM   s   @r   r   r   `   s"    _"
=
/) )r7   r   c                  X   ^  \ rS rSrSrS\R                  " 5       4U 4S jjrS rSr	U =r
$ )r      z
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U ]  5         [        XSSS9U l        [	        X"X4S9U l        g)z
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r.   N)r$   r%   r   conv1r   conv2)r0   r1   r2   r   r.   r5   s        r   r%   LightConv.__init__   s.     	"!/
BA/
r7   c                B    U R                  U R                  U5      5      $ )z
Apply 2 convolutions to input tensor.

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

Returns:
    (torch.Tensor): Output tensor.
)rj   ri   r;   s     r   r<   LightConv.forward   s     zz$**Q-((r7   )ri   rj   )rE   rF   rG   rH   rI   r&   ReLUr%   r<   rK   rL   rM   s   @r   r   r      s$     "#	 0
) 
)r7   r   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r      zDepth-wise convolution module.c           
     N   > [         TU ]  XX4[        R                  " X5      XVS9  g)a	  
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.
rQ   Nr$   r%   mathgcd)r0   r1   r2   r   r3   r   r.   r5   s          r   r%   DWConv.__init__   s$     	")9QHr7    r   r   r   TrE   rF   rG   rH   rI   r%   rK   rL   rM   s   @r   r   r      s    (I Ir7   r   c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r      z(Depth-wise transpose convolution module.c                N   > [         TU ]  XX4XV[        R                  " X5      S9  g)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!   Nrr   )r0   r1   r2   r   r3   p1p2r5   s          r   r%   DWConvTranspose2d.__init__   s$     	rdhhr6FGr7   rv   )r   r   r   r   rx   rM   s   @r   r   r      s    2H Hr7   r   c                  ^   ^  \ rS rSrSr\R                  " 5       rSU 4S jjrS r	S r
SrU =r$ )r	      aW  
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).
c           	     ~  > [         TU ]  5         [        R                  " XX4XV(       + S9U l        U(       a  [        R
                  " U5      O[        R                  " 5       U l        USL a  U R                  U l        g[        U[        R                  5      (       a  Xpl        g[        R                  " 5       U l        g)a-  
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_transposer)   r-   r*   r+   r   r,   r.   )	r0   r1   r2   r   r3   r   r*   r.   r5   s	           r   r%   ConvTranspose.__init__   sz     	 00qvN(*"..$'*d{4##z#ryy?Y?Y_a_j_j_lr7   c                `    U R                  U R                  U R                  U5      5      5      $ )z
Apply transposed convolution, batch normalization and activation to input.

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

Returns:
    (torch.Tensor): Output tensor.
r.   r*   r   r;   s     r   r<   ConvTranspose.forward  s'     xx 3 3A 6788r7   c                B    U R                  U R                  U5      5      $ )z
Apply activation and convolution transpose operation to input.

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

Returns:
    (torch.Tensor): Output tensor.
)r.   r   r;   s     r   rA   ConvTranspose.forward_fuse  s     xx++A.//r7   r   )r   r   r   TTrD   rM   s   @r   r	   r	      s*     '')Km$
9
0 
0r7   r	   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r
   i   z
Focus module for concentrating feature information.

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

Attributes:
    conv (Conv): Convolution layer.
c           
     J   > [         TU ]  5         [        US-  X#XEXgS9U l        g)a  
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.
   rh   N)r$   r%   r   r(   )	r0   r1   r2   r   r3   r   r4   r.   r5   s	           r   r%   Focus.__init__*  s&     	aa9	r7   c                    U R                  [        R                  " USSSS2SSS24   USSSS2SSS24   USSSS2SSS24   USSSS2SSS24   4S5      5      $ )z
Apply Focus operation and convolution to input tensor.

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

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

Returns:
    (torch.Tensor): Output tensor.
.Nr   r   )r(   rY   catr;   s     r   r<   Focus.forward;  s     yyAc3Q3!m$4aQTT3Q36G3PSRSPSUVUYXYUY>IZ\]^acdcgfgcgijimlmim^m\n#oqrsttr7   )r(   )r   r   Nr   T	rE   rF   rG   rH   rI   r%   r<   rK   rL   rM   s   @r   r
   r
      s    :"u ur7   r
   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   iK  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
c           
     r   > [         TU ]  5         US-  n[        XX4SXVS9U l        [        XwSSSXvS9U l        g)a	  
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   Nrh      r   )r$   r%   r   cv1rR   )	r0   r1   r2   r   r3   r4   r.   c_r5   s	           r   r%   GhostConv.__init__Y  s?     	1WdA71dB8r7   c                r    U R                  U5      n[        R                  " X R                  U5      4S5      $ )z
Apply Ghost Convolution to input tensor.

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

Returns:
    (torch.Tensor): Output tensor with concatenated features.
r   )r   rY   r   rR   )r0   r   ys      r   r<   GhostConv.forwardj  s-     HHQKyy!XXa[)1--r7   )r   rR   rw   r   rM   s   @r   r   r   K  s    9". .r7   r   c                     ^  \ rS rSrSr\R                  " 5       rSU 4S jjrS r	S r
S r\S 5       rS rS	 rS
rU =r$ )r   ix  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
c           
       > [         TU ]  5         US:X  a  US:X  d   eX`l        Xl        X l        USL a  U R
                  O5[        U[        R                  5      (       a  UO[        R                  " 5       U l
        U	(       a  X!:X  a  US:X  a  [        R                  " US9OSU l        [        XX4XVSS9U l        [        XSXEUS-  -
  USS9U l        g)	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.
rd   r   T)num_featuresNF)r   r4   r.   r   )r$   r%   r4   r1   r2   r+   r   r&   r,   r-   r.   r)   r*   r   ri   rj   )r0   r1   r2   r   r3   r   r4   r   r.   r*   deployr5   s              r   r%   RepConv.__init__  s      	Av!q&  '*d{4##z#ryy?Y?Y_a_j_j_l57BHa"..b1UY"!!e<
"!QqAv:!G
r7   c                B    U R                  U R                  U5      5      $ )zw
Forward pass for deploy mode.

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

Returns:
    (torch.Tensor): Output tensor.
r@   r;   s     r   rA   RepConv.forward_fuse  rC   r7   c                    U R                   c  SOU R                  U5      nU R                  U R                  U5      U R                  U5      -   U-   5      $ )zy
Forward pass for training mode.

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

Returns:
    (torch.Tensor): Output tensor.
r   )r*   r.   ri   rj   )r0   r   id_outs      r   r<   RepConv.forward  sD     ggo4771:xx

1

15>??r7   c                    U R                  U R                  5      u  pU R                  U R                  5      u  p4U R                  U R                  5      u  pVXR	                  U5      -   U-   X$-   U-   4$ )z
Calculate equivalent kernel and bias by fusing convolutions.

Returns:
    (torch.Tensor): Equivalent kernel
    (torch.Tensor): Equivalent bias
)_fuse_bn_tensorri   rj   r*   _pad_1x1_to_3x3_tensor)r0   	kernel3x3bias3x3	kernel1x1bias1x1kernelidbiasids          r   get_equivalent_kernel_bias"RepConv.get_equivalent_kernel_bias  sp     "11$**=	!11$**=	//866yAAHLgN_bhNhhhr7   c                b    U c  g[         R                  R                  R                  U / SQ5      $ )z
Pad a 1x1 kernel to 3x3 size.

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

Returns:
    (torch.Tensor): Padded 3x3 kernel.
r   )r   r   r   r   )rY   r&   
functionalpad)r   s    r   r   RepConv._pad_1x1_to_3x3_tensor  s*     88&&**9lCCr7   c                   Uc  g[        U[        5      (       a  UR                  R                  nUR                  R
                  nUR                  R                  nUR                  R                  nUR                  R                  nUR                  R                  nGO'[        U[        R                  5      (       Ga  [        U S5      (       d  U R                  U R                  -  n[        R                  " U R                  USS4[        R                   S9n	[#        U R                  5       H  n
SXX-  SS4'   M     [$        R&                  " U	5      R)                  UR                  R*                  5      U l        U R,                  nUR
                  nUR                  nUR                  nUR                  nUR                  nWW-   R/                  5       nWU-  R1                  SSSS5      nWU-  WWU-  U-  -
  4$ )z
Fuse 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.
)r   r   	id_tensorrd   )dtyper   )r   r   r(   r[   r*   running_meanrunning_varr#   epsr&   r)   hasattrr1   r4   npzerosfloat32rangerY   
from_numpytodevicer   sqrtreshape)r0   branchkernelr   r   gammabetar   	input_dimkernel_valuera   stdts                r   r   RepConv._fuse_bn_tensor  s    >fd##[[''F!9911L ))//KII$$E99>>D))--C//4-- GGtvv-	!xx)Q(B"**UtwwA;<LAM1a!78 (!&!1!1,!?!B!B6==CWCW!X^^F!..L ,,KMME;;D**CS &&(S[!!"aA.z4,"6"<<<<r7   c                   [        U S5      (       a  gU R                  5       u  p[        R                  " U R                  R
                  R                  U R                  R
                  R                  U R                  R
                  R                  U R                  R
                  R                  U R                  R
                  R                  U R                  R
                  R                  U R                  R
                  R                  SS9R                  S5      U l        XR
                  R                  l        X R
                  R                   l        U R#                  5        H  nUR%                  5         M     U R'                  S5        U R'                  S5        [        U S5      (       a  U R'                  S5        [        U S	5      (       a  U R'                  S	5        [        U S
5      (       a  U R'                  S
5        gg)zLFuse convolutions for inference by creating a single equivalent convolution.r(   NT)in_channelsout_channelskernel_sizestridepaddingr"   r!   r#   Fri   rj   nmr*   r   )r   r   r&   r'   ri   r(   r   r   r   r   r   r"   r!   requires_grad_r[   r\   r#   
parametersdetach_r_   )r0   r   r#   paras       r   rb   RepConv.fuse_convs  sg   4  668II

3355

33::??))JJOO++ZZ__--::??))	
 .
 		 !'		"		OO%DLLN &!!4T"4T"4%%[) &r7   )	r.   r*   r1   r2   r(   ri   rj   r4   r   )rd   r   r   r   r   TFF)rE   rF   rG   rH   rI   r&   rJ   r+   r%   rA   r<   r   staticmethodr   r   rb   rK   rL   rM   s   @r   r   r   x  sR      '')KH6
&@i D D#=J* *r7   r   c                  :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r   i  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
c           	        > [         TU ]  5         [        R                  " S5      U l        [        R
                  " XSSSSS9U l        [        R                  " 5       U l        g)z[
Initialize Channel-attention module.

Args:
    channels (int): Number of input channels.
r   r   Tr   N)	r$   r%   r&   AdaptiveAvgPool2dpoolr'   fcSigmoidr.   )r0   channelsr5   s     r   r%   ChannelAttention.__init__-  sG     	((+	))H1adC::<r7   c                d    XR                  U R                  U R                  U5      5      5      -  $ )z
Apply channel attention to input tensor.

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

Returns:
    (torch.Tensor): Channel-attended output tensor.
r.   r   r   r;   s     r   r<   ChannelAttention.forward9  s'     88DGGDIIaL1222r7   r   )r   r   returnNone)r   torch.Tensorr   r   r   rM   s   @r   r   r     s    
 
3 
3r7   r   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   iF  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U ]  5         US;   d   S5       eUS:X  a  SOSn[        R                  " SSXSS9U l        [        R
                  " 5       U l        g	)
zo
Initialize Spatial-attention module.

Args:
    kernel_size (int): Size of the convolutional kernel (3 or 7).
>   rd      zkernel size must be 3 or 7r   rd   r   r   F)r   r#   N)r$   r%   r&   r'   r   r   r.   )r0   r   r   r5   s      r   r%   SpatialAttention.__init__Q  sU     	f$B&BB$"a'!Q99Q;eL::<r7   c                    XR                  U R                  [        R                  " [        R                  " USSS9[        R
                  " USSS9S   /S5      5      5      -  $ )z
Apply spatial attention to input tensor.

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

Returns:
    (torch.Tensor): Spatial-attended output tensor.
r   T)keepdimr   )r.   r   rY   r   meanmaxr;   s     r   r<   SpatialAttention.forward^  sV     88DHHUYY

1a0NPUPYPYZ[]^hlPmnoPp/qst%uvwwwr7   )r.   r   r   r   rM   s   @r   r   r   F  s     
x 
xr7   r   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   ik  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.
c                b   > [         TU ]  5         [        U5      U l        [	        U5      U l        g)z
Initialize 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)r0   r1   r   r5   s      r   r%   CBAM.__init__v  s*     	!1"!5!1+!>r7   c                B    U R                  U R                  U5      5      $ )z
Apply channel and spatial attention sequentially to input tensor.

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

Returns:
    (torch.Tensor): Attended output tensor.
)r   r   r;   s     r   r<   CBAM.forward  s      %%d&<&<Q&?@@r7   )r   r   r   r   rM   s   @r   r   r   k  s    
?
A 
Ar7   r   c                  :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r   i  z
Concatenate a list of tensors along specified dimension.

Attributes:
    d (int): Dimension along which to concatenate tensors.
c                .   > [         TU ]  5         Xl        g)ze
Initialize Concat module.

Args:
    dimension (int): Dimension along which to concatenate tensors.
N)r$   r%   r   )r0   	dimensionr5   s     r   r%   Concat.__init__  s     	r7   c                B    [         R                  " XR                  5      $ )z
Concatenate input tensors along specified dimension.

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

Returns:
    (torch.Tensor): Concatenated tensor.
)rY   r   r   r;   s     r   r<   Concat.forward  s     yyFF##r7   )r   )r   r   zlist[torch.Tensor]r   rM   s   @r   r   r     s    
$ 
$r7   r   c                  :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r   i  zd
Returns a particular index of the input.

Attributes:
    index (int): Index to select from input.
c                .   > [         TU ]  5         Xl        g)zN
Initialize Index module.

Args:
    index (int): Index to select from input.
N)r$   r%   index)r0   r  r5   s     r   r%   Index.__init__  s     	
r7   c                    XR                      $ )z
Select and return a particular index from input.

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

Returns:
    (torch.Tensor): Selected tensor.
r  r;   s     r   r<   Index.forward  s     }r7   r  )r   r  r   rM   s   @r   r   r     s    
 
r7   r   )Nr   )rI   
__future__r   rs   numpyr   rY   torch.nnr&   __all__r   r,   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   rv   r7   r   <module>r     s    "    $6&299 6&r;)D ;)|#)		 #)LIT I$H** H$50BII 50p'uBII 'uV*.		 *.Zc*bii c*L%3ryy %3P"xryy "xJ!A299 !AH$RYY $>BII r7   