
    ёia                    :   S SK Jr  S SKJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  S SKJr  SS	KJr  \(       a   S S
KJr  S SKJr  S SKJrJrJrJrJr  S SKJr  / r " S S\5      r " S S\5      r  " S S\5      r! " S S\ 5      r" " S S\5      r# " S S\ 5      r$g)    )annotations)TYPE_CHECKINGLiteralN)Layer)_update_padding_nd)Normal)convert_to_list   )
functional)Sequence)Tensor)ParamAttrLikeSize2Size3Size4Size6)_PaddingSizeModec                     ^  \ rS rSr% S\S'   S\S'              S	                             S
U 4S jjjrSS jrSS jrSrU =r	$ )_Conv3D,   r   weightbiasc                  >^  [         TT ]  5         USLd   S5       eUT l        UT l        UT l        UT l        UT l        UT l        UT l        U	T l	        UT l
        U
S:X  d   S5       eUS:X  d   S5       eUS;   d   S5       eS	1nX;  a  [        S
U SU S35      eUS	:H  nSn[        UUS5      T l        [        UUS5      T l        [        UUS5      T l        UT l        U
T l        [%        UUU5      u  T l        T l        / T R                  QT R
                  PT R                  PnU 4S jnT R+                  UT R                  U" 5       S9T l        T R+                  T R                  T R                  /SS9T l        g )NF(weight_attr should not be False in Conv.zeros,Currently, only support padding_mode='zeros'    Currently, only support groups=1Nigemm;The value of 'backend' in Conv3D should be None or 'igemm'.NDHWCdata_format must be one of , but got data_format=''   stridedilationkernel_sizec                    > [         R                  " TR                  5      TR                  -  n SU -  S-  n[	        SU5      $ Ng       @g      ?g        npprod_kernel_size_in_channelsr   filter_elem_numstdselfs     [/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/sparse/nn/layer/conv.py_get_default_param_initializer8_Conv3D.__init__.<locals>._get_default_param_initializerq   >     ggd&7&784;L;LLO(S0C#s##    shapeattrdefault_initializerTr<   r;   is_biassuper__init___param_attr
_bias_attr_groupsr0   _out_channels_data_format_subm_key_backend
ValueErrorr	   _stride	_dilationr/   _padding_padding_moder   _updated_padding_padding_algorithmcreate_parameterr   r   r4   in_channelsout_channelsr)   r'   paddingr(   groupssubmkeypadding_modeweight_attr	bias_attrdata_formatbackendvalid_formatchannel_lastdimsfilter_shaper6   	__class__s   `                   r5   rB   _Conv3D.__init__0   s   " 	%' 	
6	
' '#')'
	w& 	
:	
& {>>>{ 
 
 	I I	I 

  y*-l^;RS^R__`a  #g-&vtX>(4D+K}M)9K\4:
6t6



 
	$
 ++!! > @ , 

 ))););(<d * 
	r9   c                v   U R                   c  [        R                  R                  UU R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9
nU$ U R                   S:X  a  [        R                  R                  UU R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9
nU$ [        SU R                    S35      e)Nr   r'   rV   r(   rW   rX   rY   r]   r    zDThe value of 'backend' in Conv3D should be None or 'igemm', but got .)rJ   Fconv_conv3dr   r   rL   rP   rM   rE   rH   rI   rG   _conv3d_igemmrK   r4   xouts      r5   forward_Conv3D.forward      == &&..YY||--||ZZII -- ! C: 
# ]]g%&&&&YY||--||ZZII -- ' C  
 VW[WdWdVeefg r9   c                v   SnU R                   S/[        U R                   5      -  :w  a  US-  nU R                  S:w  a  US-  nU R                  S:w  a  US-  nU R                  S/[        U R                  5      -  :w  a  US-  nU R
                  S:w  a  US	-  nUS
-  nUR                  " S0 U R                  D6$ Nz;{_in_channels}, {_out_channels}, kernel_size={_kernel_size}r   z, stride={_stride}r   z, padding={_padding}r   z, padding_mode={_padding_mode}z, dilation={_dilation}z, groups={_groups}z, data_format={_data_format} rL   lenrN   rO   rM   rE   format__dict__r4   main_strs     r5   
extra_repr_Conv3D.extra_repr       P<<A3T\\!222,,H==A..H(88H>>aS3t~~#66600H<<1,,H22///r9   rJ   rD   rG   rM   rE   r0   r/   rI   rF   rN   rQ   rO   rC   rL   rH   rP   r   r   )r   r   r   r   FNr   NNr"   N)rT   intrU   r   r)   r   r'   r   rV   2_PaddingSizeMode | Size3 | Size6 | Sequence[Size2]r(   r   rW   
Literal[1]rX   boolrY   
str | NonerZ   Literal['zeros']r[   ParamAttrLike | Noner\   r   r]   Literal['NDHWC']r^   Literal['igemm'] | NonereturnNonerm   r   r   r   r   str
__name__
__module____qualname____firstlineno____annotations__rB   ro   r{   __static_attributes____classcell__rc   s   @r5   r   r   ,   s    N
L FG)0,0*.(/+/M
M
 M
 	M

 M
 DM
 M
 M
 M
 M
 'M
 *M
 (M
 &M
 )M
  
!M
 M
^B0 0r9   r   c                     ^  \ rS rSr% S\S'   S\S'              S	                             S
U 4S jjjrSS jrSS jrSrU =r	$ )_Conv2D   r   r   r   c                  >^  [         TT ]  5         USLd   S5       eUT l        UT l        UT l        UT l        UT l        UT l        UT l        U	T l	        UT l
        U
S:X  d   S5       eUS:X  d   S5       eUS;   d   S5       eS	1nX;  a  [        S
U SU S35      eUS	:H  nSn[        UUS5      T l        [        UUS5      T l        [        UUS5      T l        UT l        U
T l        [%        UUU5      u  T l        T l        / T R                  QT R
                  PT R                  PnU 4S jnT R+                  UT R                  U" 5       S9T l        T R+                  T R                  T R                  /SS9T l        g )NFr   r   r   r   r   r   r!   NHWCr#   r$   r%   r
   r'   r(   r)   c                    > [         R                  " TR                  5      TR                  -  n SU -  S-  n[	        SU5      $ r+   r,   r1   s     r5   r6   8_Conv2D.__init__.<locals>._get_default_param_initializer   r8   r9   r:   Tr>   r@   rS   s   `                   r5   rB   _Conv2D.__init__   s   " 	%' 	
6	
' '#')'
	w& 	
:	
& {>>>{ 
 
 	I I	I 

 x*-l^;RS^R__`a  #f,&vtX>(4D+K}M)9K\4:
6t6



 
	$
 ++!! > @ , 

 ))););(<d * 
	r9   c                v   U R                   c  [        R                  R                  UU R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9
nU$ U R                   S:X  a  [        R                  R                  UU R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9
nU$ [        SU R                    S35      e)Nrf   r    zDThe value of 'backend' in Conv2D should be None or 'igemm', but got rg   )rJ   rh   ri   _conv2dr   r   rL   rP   rM   rE   rH   rI   rG   _conv2d_igemmrK   rl   s      r5   ro   _Conv2D.forward  rq   r9   c                v   SnU R                   S/[        U R                   5      -  :w  a  US-  nU R                  S:w  a  US-  nU R                  S:w  a  US-  nU R                  S/[        U R                  5      -  :w  a  US-  nU R
                  S:w  a  US	-  nUS
-  nUR                  " S0 U R                  D6$ rs   ru   ry   s     r5   r{   _Conv2D.extra_repr$  r}   r9   r~   )r   r   r   r   FNr   NNr   N)rT   r   rU   r   r)   r   r'   r   rV   2_PaddingSizeMode | Size2 | Size4 | Sequence[Size2]r(   r   rW   r   rX   r   rY   r   rZ   r   r[   r   r\   r   r]   Literal['NHWC']r^   r   r   r   r   r   r   r   s   @r5   r   r      s    N
L FG)0,0*.'-+/M
M
 M
 	M

 M
 DM
 M
 M
 M
 M
 'M
 *M
 (M
 %M
 )M
  
!M
 M
^B0 0r9   r   c                  r   ^  \ rS rSrSr        S                       SU 4S jjjrSrU =r$ )Conv3Di4  a  
**Sparse Convolution3d Layer**
The Sparse convolution3d layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and
Output(Output) are multidimensional SparseCooTensors with a shape of
:math:`[N, D, H, W, C]` . Where N is batch size, C is the number of
channels, D is the depth of the feature, H is the height of the feature,
and W is the width of the feature. If bias attribution is provided,
bias is added to the output of the convolution.
For each input :math:`X`, the equation is:

..  math::

    Out = W \ast X + b

In the above equation:

* :math:`X`: Input value, a tensor with NDHWC format.
* :math:`W`: Filter value, a tensor with DHWCM format.
* :math:`\\ast`: Convolution operation.
* :math:`b`: Bias value, a 1-D tensor with shape [M].
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.

Parameters:
    in_channels(int): The number of input channels in the input image.
    out_channels(int): The number of output channels produced by the convolution.
    kernel_size(int|list|tuple): The size of the convolving kernel.
    stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must
        contain three integers, (stride_D, stride_H, stride_W). Otherwise, the
        stride_D = stride_H = stride_W = stride. The default value is 1.
    padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms.
        1. a string in ['valid', 'same'].
        2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding`
        3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...].
        4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form  [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions.
        5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
        The default value is 0.
    dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must
        contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the
        dilation_D = dilation_H = dilation_W = dilation. The default value is 1.
    groups(int, optional): The groups number of the Conv3D Layer. According to grouped
        convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
        the first half of the filters is only connected to the first half
        of the input channels, while the second half of the filters is only
        connected to the second half of the input channels. The default value is 1, currently, only support groups=1.
    padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Currently only support ``'zeros'``.
    weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
        of conv3d. If it is set to None or one attribute of ParamAttr, conv3d
        will create ParamAttr as param_attr. If it is set to None, the parameter
        is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
        :math:`(\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
    bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv3d.
        If it is set to False, no bias will be added to the output units.
        If it is set to None or one attribute of ParamAttr, conv3d
        will create ParamAttr as bias_attr. If the Initializer of the bias_attr
        is not set, the bias is initialized zero. The default value is None.
    data_format(str, optional): Data format that specifies the layout of input.
        It can be "NCDHW" or "NDHWC". Currently, only support "NCDHW".

Attribute:

    **weight** (Parameter): the learnable weights of filters of this layer.

    **bias** (Parameter): the learnable bias of this layer.

Shape:

    - x: :math:`(N, D_{in}, H_{in}, W_{in}, C_{in})`

    - weight: :math:`(K_{d}, K_{h}, K_{w}, C_{in}, C_{out})`

    - bias: :math:`(C_{out})`

    - output: :math:`(N, D_{out}, H_{out}, W_{out}, C_{out})`

    Where

    ..  math::

       D_{out}&= \frac{(D_{in} + 2 * paddings[0] - (dilations[0] * (kernel\_size[0] - 1) + 1))}{strides[0]} + 1

       H_{out}&= \frac{(H_{in} + 2 * paddings[1] - (dilations[1] * (kernel\_size[1] - 1) + 1))}{strides[1]} + 1

       W_{out}&= \frac{(W_{in} + 2 * paddings[2] - (dilations[2] * (kernel\_size[2] - 1) + 1))}{strides[2]} + 1

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> indices = [
        ...     [0, 0, 0, 0],
        ...     [0, 0, 0, 0],
        ...     [0, 0, 1, 2],
        ...     [1, 3, 2, 3],
        ... ]
        >>> values = [[1], [2], [3], [4]]
        >>> indices = paddle.to_tensor(indices, dtype='int32')
        >>> values = paddle.to_tensor(values, dtype='float32')
        >>> dense_shape = [1, 1, 3, 4, 1]
        >>> sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape, stop_gradient=True)
        >>> conv = paddle.sparse.nn.Conv3D(1, 1, (1, 3, 3))
        >>> y = conv(sparse_x)
        >>> print(y.shape)
        paddle.Size([1, 1, 1, 2, 1])
c                8   > [         TU ]  UUUUUUUSS UU	U
US9  g NF)
r'   rV   r(   rW   rX   rY   rZ   r[   r\   r]   rA   rB   r4   rT   rU   r)   r'   rV   r(   rW   rZ   r[   r\   r]   rc   s               r5   rB   Conv3D.__init__  >     	%## 	 	
r9   rt   )r   r   r   r   r   NNr"   )rT   r   rU   r   r)   r   r'   r   rV   r   r(   r   rW   r   rZ   r   r[   r   r\   r   r]   r   r   r   r   r   r   r   __doc__rB   r   r   r   s   @r5   r   r   4  s    jb FG)0,0*.(/

 
 	

 
 D
 
 
 '
 *
 (
 &
 

 
r9   r   c                  r   ^  \ rS rSrSr        S                       SU 4S jjjrSrU =r$ )Conv2Di  a  
**Sparse Convolution2d Layer**

The Sparse convolution2d layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and
Output(Output) are multidimensional SparseCooTensors with a shape of
:math:`[N, H, W, C]` . Where N is batch size, C is the number of
channels, H is the height of the feature,
and W is the width of the feature. If bias attribution is provided,
bias is added to the output of the convolution.
For each input :math:`X`, the equation is:

..  math::

    Out = W \ast X + b

In the above equation:

* :math:`X`: Input value, a tensor with NHWC format.
* :math:`W`: Filter value, a tensor with HWCM format.
* :math:`\\ast`: Convolution operation.
* :math:`b`: Bias value, a 1-D tensor with shape [M].
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.

Parameters:
    in_channels(int): The number of input channels in the input image.
    out_channels(int): The number of output channels produced by the convolution.
    kernel_size(int|list|tuple): The size of the convolving kernel.
    stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must
        contain three integers, (stride_H, stride_W). Otherwise, the
        stride_H = stride_W = stride. The default value is 1.
    padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms.

        1. a string in ['valid', 'same'].
        2. an int, which means each spatial dimension(height, width) is zero padded by size of `padding`
        3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...].
        4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form  [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions.
        5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...].

        Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
        The default value is 0.
    dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must
        contain three integers, (dilation_H, dilation_W). Otherwise, the
        dilation_H = dilation_W = dilation. The default value is 1.
    groups(int, optional): The groups number of the Conv2D Layer. According to grouped
        convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
        the first half of the filters is only connected to the first half
        of the input channels, while the second half of the filters is only
        connected to the second half of the input channels. The default value is 1, currently, only support groups=1.
    padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Currently only support ``'zeros'``.
    weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
        of conv2d. If it is set to None or one attribute of ParamAttr, conv2d
        will create ParamAttr as param_attr. If it is set to None, the parameter
        is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
        :math:`(\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
    bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv2d.
        If it is set to False, no bias will be added to the output units.
        If it is set to None or one attribute of ParamAttr, conv2d
        will create ParamAttr as bias_attr. If the Initializer of the bias_attr
        is not set, the bias is initialized zero. The default value is None.
    data_format(str, optional): Data format that specifies the layout of input.
        It can be "NCHW" or "NHWC". Currently, only support "NHWC".

Attribute:
    **weight** (Parameter): the learnable weights of filters of this layer.

    **bias** (Parameter): the learnable bias of this layer.

Shape:
    - x: :math:`(N, H_{in}, W_{in}, C_{in})`

    - weight: :math:`(K_{h}, K_{w}, C_{in}, C_{out})`

    - bias: :math:`(C_{out})`

    - output: :math:`(N, H_{out}, W_{out}, C_{out})`

    Where

    ..  math::

       H_{out}&= \frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (kernel\_size[0] - 1) + 1))}{strides[0]} + 1

       W_{out}&= \frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (kernel\_size[1] - 1) + 1))}{strides[1]} + 1

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> indices = [[0, 0, 0, 0], [0, 0, 1, 2], [1, 3, 2, 3]]
        >>> values = [[1], [2], [3], [4]]
        >>> indices = paddle.to_tensor(indices, dtype='int32')
        >>> values = paddle.to_tensor(values, dtype='float32')
        >>> dense_shape = [1, 3, 4, 1]
        >>> sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape, stop_gradient=True)
        >>> conv = paddle.sparse.nn.Conv2D(1, 1, (3, 3))
        >>> y = conv(sparse_x)
        >>> print(y.shape)
        paddle.Size([1, 1, 2, 1])
c                8   > [         TU ]  UUUUUUUSS UU	U
US9  g r   r   r   s               r5   rB   Conv2D.__init__(  r   r9   rt   )r   r   r   r   r   NNr   )rT   r   rU   r   r)   r   r'   r   rV   r   r(   r   rW   r   rZ   r   r[   r   r\   r   r]   r   r   r   r   r   s   @r5   r   r     s    eX FG)0,0*.'-

 
 	

 
 D
 
 
 '
 *
 (
 %
 

 
r9   r   c                  ~   ^  \ rS rSrSr          S                           SU 4S jjjrSrU =r$ )
SubmConv3DiG  a1  
**Submanifold Sparse Convolution3d Layer**
The submanifold sparse convolution3d layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and
Output(Output) are multidimensional SparseCooTensors with a shape of
:math:`[N, D, H, W, C]` . Where N is batch size, C is the number of
channels, D is the depth of the feature, H is the height of the feature,
and W is the width of the feature. If bias attribution is provided,
bias is added to the output of the convolution.
For each input :math:`X`, the equation is:

..  math::

    Out = W \ast X + b

In the above equation:

* :math:`X`: Input value, a tensor with NDHWC format.
* :math:`W`: Filter value, a tensor with DHWCM format.
* :math:`\\ast`: Submanifold Convolution operation, refer to the paper: https://arxiv.org/abs/1706.01307.
* :math:`b`: Bias value, a 1-D tensor with shape [M].
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.

Parameters:
    in_channels(int): The number of input channels in the input image.
    out_channels(int): The number of output channels produced by the convolution.
    kernel_size(int|list|tuple): The size of the convolving kernel.
    stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must
        contain three integers, (stride_D, stride_H, stride_W). Otherwise, the
        stride_D = stride_H = stride_W = stride. The default value is 1.
    padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms.
        1. a string in ['valid', 'same'].
        2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding`
        3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...].
        4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form  [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions.
        5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
        The default value is 0.
    dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must
        contain three integers, (dilation_D, dilation_H, dilation_W). Otherwise, the
        dilation_D = dilation_H = dilation_W = dilation. The default value is 1.
    groups(int, optional): The groups number of the Conv3D Layer. According to grouped
        convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
        the first half of the filters is only connected to the first half
        of the input channels, while the second half of the filters is only
        connected to the second half of the input channels. The default value is 1.
    padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Currently only support ``'zeros'``.
    key(str, optional): the key is used to save or use the same rulebook,
        the definition and role of rulebook refers to
        https://pdfs.semanticscholar.org/5125/a16039cabc6320c908a4764f32596e018ad3.pdf. The
        default value is None.
    weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
        of conv3d. If it is set to None or one attribute of ParamAttr, conv3d
        will create ParamAttr as param_attr. If it is set to None, the parameter
        is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
        :math:`(\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
    bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv3d.
        If it is set to False, no bias will be added to the output units.
        If it is set to None or one attribute of ParamAttr, conv3d
        will create ParamAttr as bias_attr. If the Initializer of the bias_attr
        is not set, the bias is initialized zero. The default value is None.
    data_format(str, optional): Data format that specifies the layout of input.
        It can be "NCDHW" or "NDHWC". Currently, only support "NCDHW".

Attribute:

    **weight** (Parameter): the learnable weights of filters of this layer.

    **bias** (Parameter): the learnable bias of this layer.

Shape:

    - x: :math:`(N, D_{in}, H_{in}, W_{in}, C_{in})`

    - weight: :math:`(K_{d}, K_{h}, K_{w}, C_{in}, C_{out})`

    - bias: :math:`(C_{out})`

    - output: :math:`(N, D_{out}, H_{out}, W_{out}, C_{out})`

    Where

    ..  math::

       D_{out}&= \frac{(D_{in} + 2 * paddings[0] - (dilations[0] * (kernel\_size[0] - 1) + 1))}{strides[0]} + 1

       H_{out}&= \frac{(H_{in} + 2 * paddings[1] - (dilations[1] * (kernel\_size[1] - 1) + 1))}{strides[1]} + 1

       W_{out}&= \frac{(W_{in} + 2 * paddings[2] - (dilations[2] * (kernel\_size[2] - 1) + 1))}{strides[2]} + 1

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> indices = [
        ...     [0, 0, 0, 0],
        ...     [0, 0, 0, 0],
        ...     [0, 0, 1, 2],
        ...     [1, 3, 2, 3],
        ... ]
        >>> values = [[1], [2], [3], [4]]
        >>> dense_shape = [1, 1, 3, 4, 1]
        >>> indices = paddle.to_tensor(indices, dtype='int32')
        >>> values = paddle.to_tensor(values, dtype='float32')
        >>> sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape, stop_gradient=True)
        >>> subm_conv = paddle.sparse.nn.SubmConv3D(1, 1, (1, 3, 3))
        >>> y = subm_conv(sparse_x)
        >>> print(y.shape)
        paddle.Size([1, 1, 3, 4, 1])
c                :   > [         TU ]  UUUUUUUSU	UU
UUUS9  g NT)r'   rV   r(   rW   rX   rY   rZ   r[   r\   r]   r^   r   r4   rT   rU   r)   r'   rV   r(   rW   rZ   rY   r[   r\   r]   r^   rc   s                 r5   rB   SubmConv3D.__init__  A      	%## 	 	
r9   rt   )
r   r   r   r   r   NNNr"   N)rT   r   rU   r   r)   r   r'   r   rV   r   r(   r   rW   r   rZ   r   rY   r   r[   r   r\   r   r]   r   r^   r   r   r   r   r   s   @r5   r   r   G  s    nj FG)0,0*.(/+/

 
 	

 
 D
 
 
 '
 
 *
 (
 &
 )
 

 
r9   r   c                  ~   ^  \ rS rSrSr          S                           SU 4S jjjrSrU =r$ )
SubmConv2Di  a  
**Submanifold Sparse Convolution2d Layer**

The submanifold sparse convolution2d layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and
Output(Output) are multidimensional SparseCooTensors with a shape of
:math:`[N, H, W, C]` . Where N is batch size, C is the number of
channels, H is the height of the feature,
and W is the width of the feature. If bias attribution is provided,
bias is added to the output of the convolution.
For each input :math:`X`, the equation is:

..  math::

    Out = W \ast X + b

In the above equation:

* :math:`X`: Input value, a tensor with NDHWC format.
* :math:`W`: Filter value, a tensor with DHWCM format.
* :math:`\\ast`: Submanifold Convolution operation, refer to the paper: https://arxiv.org/abs/1706.01307.
* :math:`b`: Bias value, a 1-D tensor with shape [M].
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.

Parameters:
    in_channels(int): The number of input channels in the input image.
    out_channels(int): The number of output channels produced by the convolution.
    kernel_size(int|list|tuple): The size of the convolving kernel.
    stride(int|list|tuple, optional): The stride size. If stride is a list/tuple, it must
        contain two integers, (stride_H, stride_W). Otherwise, the
        stride_H = stride_W = stride. The default value is 1.
    padding(int|str|tuple|list, optional): The padding size. Padding couple be in one of the following forms.

        1. a string in ['valid', 'same'].
        2. an int, which means each spatial dimension(depth, height, width) is zero padded by size of `padding`
        3. a list[int] or tuple[int] whose length is the number of spatial dimensions, which contains the amount of padding on each side for each spatial dimension. It has the form [pad_d1, pad_d2, ...].
        4. a list[int] or tuple[int] whose length is 2 * number of spatial dimensions. It has the form  [pad_before, pad_after, pad_before, pad_after, ...] for all spatial dimensions.
        5. a list or tuple of pairs of ints. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...].

        Note that, the batch dimension and channel dimension are also included. Each pair of integers correspond to the amount of padding for a dimension of the input. Padding in batch dimension and channel dimension should be [0, 0] or (0, 0).
        The default value is 0.
    dilation(int|list|tuple, optional): The dilation size. If dilation is a list/tuple, it must
        contain two integers, (dilation_H, dilation_W). Otherwise, the
        dilation_H = dilation_W = dilation. The default value is 1.
    groups(int, optional): The groups number of the Conv2D Layer. According to grouped
        convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
        the first half of the filters is only connected to the first half
        of the input channels, while the second half of the filters is only
        connected to the second half of the input channels. The default value is 1.
    padding_mode(str, optional): ``'zeros'``, ``'reflect'``, ``'replicate'`` or ``'circular'``. Currently only support ``'zeros'``.
    key(str, optional): the key is used to save or use the same rulebook,
        the definition and role of rulebook refers to
        https://pdfs.semanticscholar.org/5125/a16039cabc6320c908a4764f32596e018ad3.pdf. The
        default value is None.
    weight_attr(ParamAttr, optional): The parameter attribute for learnable parameters/weights
        of conv2d. If it is set to None or one attribute of ParamAttr, conv2d
        will create ParamAttr as param_attr. If it is set to None, the parameter
        is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
        :math:`(\frac{2.0 }{filter\_elem\_num})^{0.5}`. The default value is None.
    bias_attr(ParamAttr|bool, optional): The parameter attribute for the bias of conv2d.
        If it is set to False, no bias will be added to the output units.
        If it is set to None or one attribute of ParamAttr, conv2d
        will create ParamAttr as bias_attr. If the Initializer of the bias_attr
        is not set, the bias is initialized zero. The default value is None.
    data_format(str, optional): Data format that specifies the layout of input.
        It can be "NCHW" or "NHWC". Currently, only support "NHWC".

Attribute:
    **weight** (Parameter): the learnable weights of filters of this layer.

    **bias** (Parameter): the learnable bias of this layer.

Shape:
    - x: :math:`(N, H_{in}, W_{in}, C_{in})`

    - weight: :math:`(K_{h}, K_{w}, C_{in}, C_{out})`

    - bias: :math:`(C_{out})`

    - output: :math:`(N, H_{out}, W_{out}, C_{out})`

    Where

    ..  math::

       H_{out}&= \frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (kernel\_size[0] - 1) + 1))}{strides[0]} + 1

       W_{out}&= \frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (kernel\_size[1] - 1) + 1))}{strides[1]} + 1

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> indices = [[0, 0, 0, 0], [0, 0, 1, 2], [1, 3, 2, 3]]
        >>> values = [[1], [2], [3], [4]]
        >>> dense_shape = [1, 3, 4, 1]
        >>> indices = paddle.to_tensor(indices, dtype='int32')
        >>> values = paddle.to_tensor(values, dtype='float32')
        >>> sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape, stop_gradient=True)
        >>> subm_conv = paddle.sparse.nn.SubmConv2D(1, 1, (3, 3))
        >>> y = subm_conv(sparse_x)
        >>> print(y.shape)
        paddle.Size([1, 3, 4, 1])
c                :   > [         TU ]  UUUUUUUSU	UU
UUUS9  g r   r   r   s                 r5   rB   SubmConv2D.__init__F  r   r9   rt   )
r   r   r   r   r   NNNr   N)rT   r   rU   r   r)   r   r'   r   rV   r   r(   r   rW   r   rZ   r   rY   r   r[   r   r\   r   r]   r   r^   r   r   r   r   r   s   @r5   r   r     s    i` FG)0,0*.'-+/

 
 	

 
 D
 
 
 '
 
 *
 (
 %
 )
 

 
r9   r   )%
__future__r   typingr   r   numpyr-   	paddle.nnr   paddle.nn.functional.convr   paddle.nn.initializerr   paddle.utilsr	    r   rh   collections.abcr   paddler   paddle._typingr   r   r   r   r   paddle.nn.functional.commonr   __all__r   r   r   r   r   r   rt   r9   r5   <module>r      s    # )   8 ( ( (  =
A0e A0HA0e A0HI
W I
XD
W D
NP
 P
fK
 K
r9   