
    ёil                      S SK Jr  S SKJr  S SKrS SKJrJr  S SK	J
r
JrJr  S SKJrJrJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJrJrJr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&J'r'J(r(J)r)  SSK*J+r+  / r,S r-S r.\/\044S jr1S2S jr2S r3S r4S r5S3S jr6S r7     S4               S5S jjr8       S6                   S7S jjr9       S8                 S9S jjr:     S:               S;S jjr;S  r<     S<                 S=S! jjr=     S>                 S?S" jjr>     S@                 SAS# jjr?      SB                 SCS$ jjr@      SD                 SES% jjrA\" SS&/5       SF       SGS' jj5       rB\" SS&/5        SH         SIS( jj5       rC\" SS&/5        SJ         SKS) jj5       rD\" SS&/SS*/5        SL         SMS+ jj5       rE\" SS&/SS*/5        SL         SNS, jj5       rF\" SS&/SS*/5        SL         SOS- jj5       rG    SP             SQS. jjrH    SP             SQS/ jjrI\     SR                 SSS0 jj5       rJ\     ST                 SUS1 jj5       rKg)V    )annotations)TYPE_CHECKINGN)_C_opsin_dynamic_mode)Variablein_dygraph_modein_dynamic_or_pir_mode)lp_pool_function_decoratorparam_one_aliasparam_two_alias   )
check_typecheck_variable_and_dtype)LayerHelper)squeeze	unsqueeze)_contain_var_convert_to_tensor_list_is_symmetric_paddingconvert_to_list)Sequence)Tensor)DataLayout1DDataLayout2DDataLayout3DSize1Size2Size3Size4Size6   )_PaddingSizeModec                .    [        U [        [        45      $ N)
isinstancelisttuple)inputs    \/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/functional/pooling.py_is_list_or_tupler*   A   s    edE]++    c           
         [        U R                  5      U:w  a0  [        SU S[        U R                  5       S[        U 5       35      eg )NzExcepted Input X is z-D tensor, but received z-D )lenshape
ValueErrortype)x	dimensions     r)   _check_inputr3   E   sL    
177|y "9+-Ec!''l^SVW[\]W^V_`
 	
 !r+   c           
     `    [        X5      (       d  [        SU SU S[        U 5       S35      eg )Nz	Excepted z
 type for z but received type: . )r%   r/   r0   )r1   x_nametypess      r)   _check_instancer8   L   s<    awj0DT!WIRP
 	
  r+   c                0    SS jnU  H  nU" XA5        M     g )Nc           	     l    [        U [        5      (       a  Ub  X:  a  [        SU SU SU  S35      eg g g )NzExcepted the input z to be greater than z but received x: r5   )r%   intr/   )r1   r6   	min_limits      r)   _check_value-_check_value_limitation.<locals>._check_valueT   sN    a)"7AM%fX-A)L]^_]``bc  =J"7r+   MbP? )r1   r6   r<   r=   eles        r)   _check_value_limitationrC   S   s     S! r+   c                    U(       a-  [        U S   5      SS/:H  =(       a    [        U S   5      SS/:H  $ [        U S   5      SS/:H  =(       a    [        U S   5      SS/:H  $ )Nr   r!   )r&   )paddingchannel_lasts     r)   "_zero_padding_in_batch_and_channelrH   ^   sc    GAJAq6)Id72;.?Aq6.IIGAJAq6)Hd71:.>1a&.HHr+   c                l    U(       a  U SS OU SS  nU VVs/ s H  o3  H  oDPM     M     nnnU$ s  snnf )Nr!   rE      rA   )rF   rG   padding_	pad_a_dimelems        r)   %_exclude_padding_in_batch_and_channelrN   e   s>     ,wq}'!"+H&.Eh949hHEO Fs   0c                    US:X  a  U S;  a  [        SU  35      eU S:X  a  S$ S$ US:X  a  U S;  a  [        S	U  35      eU S
:X  a  S$ S$ US:X  a  U S;  a  [        SU  35      eU S:X  a  S$ S$ g )Nr!   )NCLNLCzHAttr(data_format) should be 'NCL' or 'NLC'. Received Attr(data_format): rQ   TFrJ   NCHWNHWCJAttr(data_format) should be 'NCHW' or 'NHWC'. Received Attr(data_format): rT   r   NCDHWNDHWCLAttr(data_format) should be 'NCDHW' or 'NDHWC'. Received Attr(data_format): rX   )r/   )data_formatnum_dimss     r)   _channel_lastr\   k   s    1}n,&&1]4 
 '%/4:U:1}..&&1]4 
 '&04;e;1}00&&1]4 
 ''14<u< r+   c                &   [        U [        5      (       aR  U R                  5       n U S;  a  [        SU  S35      eU S:X  a  USLa  [        S5      eSnS/U-  n X4$ SnS/U-  n  X4$ [	        U 5      (       Ga	  [        U 5      S	U-   :X  aZ  [	        U S   5      (       aG  [        X5      (       d  [        S
U  S35      eSn[        X5      n [        X5      (       a  U SS S	2   n X4$ [        U 5      S	U-  :X  aE  [        U S   [        5      (       a-  Sn[        U S	U-  S5      n [        X5      (       a  U SS S	2   n X4$ [        U 5      U:X  a)  [        U S   [        5      (       a  Sn[        XS5      n X4$ [        SU  35      eSn[        XS5      n X4$ )N)SAMEVALIDzUnknown padding: 'z$'. It can only be 'SAME' or 'VALID'.r_   FzWWhen Attr(padding) is "VALID", Attr(ceil_mode) must be False. Received ceil_mode: True.r   r^   rJ   zNon-zero padding(z6) in the batch or channel dimensions is not supported.EXPLICITrF   zInvalid padding: )r%   strupperr/   r*   r-   rH   rN   r   r;   r   )rF   r[   rG   	ceil_modepadding_algorithms        r)   _update_padding_ndre      s    '3--/++$WI-QR  g% 0 
 !(cHnGH %%E !'cHnGB %%A 
7	#	# w<1x<',=gaj,I,I5gLL 'y 1( (  !+;G %W77!!$Q$-" %% \Q\)jS.I.I *%gq8|YGG$W77!!$Q$- %% \X%*WQZ*E*E *%gCG %% 0	:;; '!'Y?%%r+   c                x    [        U 5      S:X  a  SS/U Qn U $ [        U 5      S:X  a  S/U Qn U $ [        SU  35      e)NrJ   r   r!   zBThe size of padding's dimension should be 1 or 2. But got padding=)r-   r/   )rF   s    r)   _expand_low_nd_paddingrg      s_    
7|qa"'" N 
W	-w-
 N PQXPYZ
 	
r+   r1   c                    Sn[        5       (       d  [        U S/ SQS5        [        U S5        [        U S/5      n [	        USS5      nS/UQnUc  UnO[	        USS	5      nS/UQn[        USS
S9  [        USS
S9  [        SS5      n[        USXS9u  p9[        U5      n[        5       (       a-  [        R                  " U UUUUUUSSSU	5      n
[        U
S/5      $ Sn[        U40 [        5       D6nUR                  SS9nUR!                  U5      nUR#                  USU 0SU0SUSUUU	SUUUS.
S9  [        US/5      $ )a	  
This API implements average pooling 1d operation,
See more details in :ref:`api_paddle_nn_AvgPool1d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
                      shape [N, C, L]. where `N` is batch size, `C` is the number of channels,
                      `L` is the length of the feature. The data type is float16, float32 or float64.
    kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
        it must contain an integer.
    stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
        it must contain an integer.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
        4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    exclusive (bool): Whether to exclude padding points in average pooling
                      mode, default is `True`.
    ceil_mode (bool): ${ceil_mode_comment}Whether to use the ceil function to calculate output height and width.
        If it is set to False, the floor function will be used. The default value is False.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.
Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn as nn

        >>> data = paddle.uniform([1, 3, 32], paddle.float32)
        >>> AvgPool1D = nn.AvgPool1D(kernel_size=2, stride=2, padding=0)
        >>> pool_out = AvgPool1D(data)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
rS   r1   float16float32float64
avg_pool1dr   rJ   r!   kernel_sizepool_strider@   r<   striderP   rG   rc   avgFpool2dinput_param_nameXOutT
pooling_typeksizeglobal_poolingstridespaddingsrd   	use_cudnnrc   	exclusiverZ   r0   inputsoutputsattrs)r   r   r3   r   r   rC   r\   re   rg   r	   r   rt   r   r   localsinput_dtype"create_variable_for_type_inference	append_op)r1   rn   rq   rF   r   rc   namerZ   rG   rd   outputop_typehelperdtypepool_outs                  r)   rm   rm      s   d K s5|	
 A!aSA!+q-@K#{#K~ M:fK$GFH= *L!3"G
 %W-G
 vs## W11""C"8<<UC8H% %$"'!#%6!&&*	 	 	
$ x!%%r+   c	                P   [        USS5      nUc  UnO[        USS5      n[        USSS9  [        USSS9  [        US5      n	[        USXS9u  p:[	        5       (       aA  [
        R                  " U UUUUUUS	S
S
U
5      nUc  U$ [        US5        XS   US   -  -  U-  $ Sn[        U40 [        5       D6n[        U S/ SQS5        UR                  SS9nUR                  U5      nUR                  USU 0SU0S	US
UUU
SUUUS.
S9  Uc  U$ [        US5        XS   US   -  -  U-  $ )a  
This API implements average pooling 2d operation.
See more details in :ref:`api_paddle_nn_AvgPool2d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
                      shape [N, C, H, W]. The format of input tensor is `"NCHW"` or
                      `"NHWC"`, 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. The data type if float32 or float64.
    kernel_size (int|list|tuple): The pool kernel size. If it is a tuple or list,
        it must contain two integers, (kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be a square of an int.
    stride (int|list|tuple): The stride size. If it is a tuple or list,
        it must contain two integers, (stride_Height, stride_Width).
        Otherwise, the stride size will be a square of an int.

    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape
    exclusive (bool): Whether to exclude padding points in average pooling
                      mode, default is `true`.
    divisor_override (float): if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
    data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NHWC"`.
                    The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_height, input_width]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> # avg pool2d
        >>> x = paddle.uniform([1, 3, 32, 32], paddle.float32)
        >>> out = F.avg_pool2d(x, kernel_size=2, stride=2, padding=0)
        >>> print(out.shape)
        paddle.Size([1, 3, 16, 16])
rJ   	pool_sizero   rn   r@   rp   rq   rc   rs   Fdivisor_overrider   r!   rt   r1   rj   uint16rk   rl   
avg_pool2dru   rw   rx   Try   r   )r   rC   r\   re   r	   r   rt   r8   r   r   r   r   r   r   )r1   rn   rq   rF   rc   r   r   rZ   r   rG   rd   r   r   r   r   r   s                   r)   r   r   A  s   z "+q+>K~ M:K$GFH= a0L!3L"G 
 #M,.@A^k!n<=@PPPW11 s?	
 ""C"8<<UC8H% %$"'!#%6!&&*	 	 	
$ #O,.@AN[^;<?OOr+   c	                "   [        USS5      nUc  UnO[        USS5      n[        US5      n	[        USXS9u  p:[        USSS9  [        USSS9  [	        5       (       a!  [
        R                  " U UUUUUUS	S
S
U
5      nOiSn[        U40 [        5       D6n[        U S/ SQS5        UR                  SS9nUR                  U5      nSU0nUR                  USU 0US	US
UUU
SUUUS.
S9  Uc  U$ [        US5        UUS   US   -  US   -  -  U-  $ )a  
This API implements average pooling 3d operation.
See more details in :ref:`api_paddle_nn_AvgPool3d` .

Args:
    x (Tensor): The input tensor of pooling operator, which is a 5-D tensor with
                      shape [N, C, D, H, W], where `N` represents the batch size, `C` represents
                      the number of channels, `D`, `H` and `W` represent the depth, height and width of the feature respectively.
    kernel_size (int|list|tuple): The pool kernel size. If pool kernel size
        is a tuple or list, it must contain three integers,
        (kernel_size_Depth, kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be the cube of an int.
    stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
        it must contain three integers, [stride_Depth, stride_Height, stride_Width).
        Otherwise, the pool stride size will be a cube of an int.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 3, [pad_depth, pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode (bool): ${ceil_mode_comment}
    exclusive (bool): Whether to exclude padding points in average pooling
                      mode, default is True.
    divisor_override (int|float) if specified, it will be used as divisor, otherwise kernel_size will be used. Default None.
    data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`.
                    The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_depth, input_height, input_width]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> x = paddle.uniform([1, 3, 32, 32, 32], paddle.float32)
        >>> # avg pool3d
        >>> out = paddle.nn.functional.avg_pool3d(x, kernel_size=2, stride=2, padding=0)
        >>> print(out.shape)
        paddle.Size([1, 3, 16, 16, 16])
r   r   ro   rr   rn   r@   rp   rq   rs   Fpool3dr1   r   
avg_pool3dru   rx   rw   Try   r   r   r   r!   rJ   )r   r\   re   rC   r	   r   r   r   r   r   r   r   r   r8   )r1   rn   rq   rF   rc   r   r   rZ   r   rG   rd   r   r   r   r   r   s                   r)   r   r     s   t "+q+>K~ M: a0L!3"G K$GFH===
 W11 s?	
 ""C"8<<UC(#8 %$"'!#%6!&&*	 	 	
$ (*<=1~A.Q?A	
r+   return_maskc                @    Sn[        U S5        [        U S/5      n S/[        USS5      QnUc  UnOS/[        USS5      Qn[        USUS9u  p8[	        U5      n[        5       (       a  U(       aQ  [        R                  " XX#SSU5      n	U(       a   [        U	S	   S/5      [        U	S   S/5      4$ [        U	S	   S/5      $ [        R                  " U UUUUS
USSSU5      n	[        U	S/5      $ [        U SSS/S5        U(       a  SOSn
[        U
40 [        5       D6nUR                  SS9nUR                  U5      n	UR                  S5      nXS.nUR                  U
SU 0USUSUUUS
US
US.
S9  U(       a  [        U	S/5      [        US/5      4$ [        U	S/5      $ )a	  
This API implements max pooling 1d operation.
See more details in :ref:`api_paddle_nn_MaxPool1d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
                      shape [N, C, L], where `N` is batch size, `C` is the number of channels,
                      `L` is the length of the feature. The data type if float32 or float64.
    kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
        it must contain an integer.
    stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
        it must contain an integer.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An integer, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 1, which means the feature map is zero padded by the size of `padding[0]` on every sides.
        4. A list[int] or tuple(int) whose length is 2. It has the form [pad_before, pad_after].
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    return_mask (bool): Whether return the max indices along with the outputs. default is `False`.
    ceil_mode (bool): Whether to use the ceil function to calculate output height and width. False is the default.
        If it is set to False, the floor function will be used. Default False.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.
Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> data = paddle.uniform([1, 3, 32], paddle.float32)
        >>> pool_out = F.max_pool1d(data, kernel_size=2, stride=2, padding=0)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
        >>> pool_out, indices = F.max_pool1d(data, kernel_size=2, stride=2, padding=0, return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
        >>> print(indices.shape)
        paddle.Size([1, 3, 16])
rS   r   rJ   r!   r   ro   r   Fr   Tmaxr1   rk   rl   
max_pool1dmax_pool2d_with_indexrt   ru   int32rx   Maskrw   ry   r   )r3   r   r   re   rg   r	   r   r   r   rt   r   r   r   r   r   r   )r1   rn   rq   rF   r   rc   r   rZ   rd   r   r   r   r   maskr   s                  r)   r   r   @  s   j KA!aSAD{A{CDK~@ofa?@!3i"G
 %W-G33yH
  !qc*GHQK!,EF Xa[1#. }}!H 8aS)) 	!C)Y)?N-8)hW11""C"8<<UC88A"18 %$"'!#%6!&!*	 	 	
(  Xs#WTA3%78	
 A3'	
r+   c                   Ub%  [        U[        [        45      (       d
   SU 35       eU R                  n/ n[	        [        U5      5       H9  nUR                  U[        U5      * U-      S-
  X'   -  X   -   SX7   -  -
  5        M;     SnUc  U$ [        U5      (       an  [        5       (       d  Sn[        U5      nOQ[        U5       HB  u  p[        U
[        5      (       d  M  [        R                  " U
5      R                  5       XI'   MD     [        U5      [        U5      S-   :X  a  USS  n[        U5      [        U5      :w  a3  [        S[        U5       S[        U5      S-    S[        U5       S	35      eU(       dV  [	        [        U5      5       H>  nXg   X'   -
  nXg   X'   -   nXU   s=:  a  U:  a  M&  O  [        S
U SU SU SU S3	5      e   U$ )Nz6Required output_size is None|list|tuple, but received r!   rJ   FTz,output_size should be a sequence containing z or z# elements, but it has a length of ''zinvalid output_size "z" (dim z must be between z and ))r%   r&   r'   r.   ranger-   appendr   r   r   	enumerater   nparrayitemr/   )r1   rn   rq   rF   output_size
input_sizedefault_sizedhas_static_varivarmin_sizemax_sizes                r)   _unpool_output_sizer     s   *[4-"H"H 
@NH JL3{#$[))A-.2fi?n'*n	
 % N	k	"	"  !N1+>K#K0c8,,%'XXc]%7%7%9KN 1 ;3{+a//!!"o
;3{++:; S%5%9$::]^abm^n]oopr
 	
 s;'(A#2H#2H1~88 +K=sBST\S]]bckbllmn 	 ) r+   c                x    US;  a  [        SU S35      eSn[        U S/5      n [        US/5      nS/[        USS5      QnUc  UnOS/[        USS	5      Qn[        US5      u  pH[	        U5      nUb&  USS [        U[        5      (       a  S/OS
-   USS -   n[        XX4U5      n[        5       (       a&  [        R                  " XX#XFU5      n	[        U	S/5      $ Sn
[        U
40 [        5       D6nUR                  SS9nUR                  U5      nUR!                  U
XS.SU0SUUUUS.S9  [        US/5      $ )a
  
This API implements max unpooling 1d operation.
`max_unpool1d` accepts the output of `max_pool1d` as input,
including the indices of the maximum value and calculate the partial inverse.
All non-maximum values are set to zero.

- Input: :math:`(N, C, L_{in})`
- Output: :math:`(N, C, L_{out})`, where

.. math::
    L_{out} = (L_{in} - 1) * stride - 2 * padding + kernel\_size

or as given by :attr:`output_size` in the call operator.


Args:
    x (Tensor): The input tensor of unpooling operator which is a 3-D tensor with
                      shape [N, C, L]. The format of input tensor is `"NCL"`,
                      where `N` is batch size, `C` is the number of channels, `L` is
                      the length of the feature. The data type is float32, float64 or int64.
    indices (Tensor): The indices given out by maxpooling1d which is a 3-D tensor with
                      shape [N, C, L]. The format of input tensor is `"NCL"` ,
                      where `N` is batch size, `C` is the number of channels, `L` is
                      the length of the feature. The data type is int32 or int64.
    kernel_size (int|list|tuple): The unpool kernel size. If unpool kernel size is a tuple or list,
        it must contain an integer.
    stride (int|list|tuple): The unpool stride size. If unpool stride size is a tuple or list,
        it must contain an integer.
    padding (int | tuple): Padding that was added to the input.
    output_size(list|tuple, optional): The target output size. If output_size is not specified,
                       the actual output shape will be automatically calculated by (input_shape,
                       kernel_size, stride, padding).
    data_format (string): The data format of the input and output data.
                    The default is `"NCL"`. When it is `"NCL"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_length]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of unpooling result.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> data = paddle.rand(shape=[1, 3, 16])
        >>> pool_out, indices = F.max_pool1d(data, kernel_size=2, stride=2, padding=0, return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 8])
        >>> print(indices.shape)
        paddle.Size([1, 3, 8])
        >>> unpool_out = F.max_unpool1d(pool_out, indices, kernel_size=2, padding=0)
        >>> print(unpool_out.shape)
        paddle.Size([1, 3, 16])

)rP   z?Attr(data_format) should be 'NCL'. Received Attr(data_format): .rS   rJ   r!   r   Nro   )r!   unpoolr1   ru   rw   Indicesrx   r   unpooling_typer{   r}   r~   r   r   )r/   r   r   re   rg   r%   r&   r   r	   r   r   r   r   r   r   r   r   )r1   indicesrn   rq   rF   rZ   r   r   rd   r   r   r   r   
unpool_outs                 r)   max_unpool1dr     s   J '!""-a1
 	
 K!aSA!%GD{A{CDK~@ofa?@!3GQ!?G$W-GO d33s?!"o 	
 &	K W;
 vs##G-FH-F4E::5AJ
+
## &
	   :s##r+   c                @   U R                   S:w  a  [        SU R                   S35      eUR                   S:w  a  [        SUR                   S35      e[        USS5      nUc  UnO[        USS5      n[        USS5      nUS	;  a  [        S
U S35      e[	        XX4U5      n[        5       (       a  [        R                  " XX#XFU5      nU$ Sn	[        U	40 [        5       D6n
U
R                  SS9nU
R                  U5      nU
R                  U	XS.SU0SUUUUS.S9  U$ )a@  
This API implements max unpooling 2d operation.
See more details in :ref:`api_paddle_nn_MaxUnPool2D` .


Args:
    x (Tensor): The input tensor of unpooling operator which is a 4-D tensor with
                      shape [N, C, H, W]. The format of input tensor is `"NCHW"`,
                      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. The data type is float32, float64 or int64.
    indices (Tensor): The indices given out by maxpooling2d which is a 4-D tensor with
                      shape [N, C, H, W]. The format of input tensor is `"NCHW"` ,
                      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. The data type is int32 or int64.
    kernel_size (int|list|tuple): The unpool kernel size. If unpool kernel size is a tuple or list,
        it must contain an integer.
    stride (int|list|tuple): The unpool stride size. If unpool stride size is a tuple or list,
        it must contain an integer.
    padding (int | tuple): Padding that was added to the input.
    output_size(list|tuple, optional): The target output size. If output_size is not specified,
                       the actual output shape will be automatically calculated by (input_shape,
                       kernel_size, padding).
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.


    - Input: :math:`(N, C, H_{in}, W_{in})`
    - Output: :math:`(N, C, H_{out}, W_{out})`, where

      .. math::
        H_{out} = (H_{in} - 1) \times \text{stride[0]} - 2 \times \text{padding[0]} + \text{kernel\_size[0]}

      .. math::
        W_{out} = (W_{in} - 1) \times \text{stride[1]} - 2 \times \text{padding[1]} + \text{kernel\_size[1]}

      or as given by :attr:`output_size` in the call operator

    Returns:
        Tensor: The output tensor of unpooling result.

    Raises:
        ValueError: If the input is not a 4-D tensor.
        ValueError: If indices shape is not equal input shape.


    Examples:
        .. code-block:: pycon

            >>> import paddle
            >>> import paddle.nn.functional as F

            >>> data = paddle.rand(shape=[1, 1, 6, 6])
            >>> pool_out, indices = F.max_pool2d(
            ...     data,
            ...     kernel_size=2,
            ...     stride=2,
            ...     padding=0,
            ...     return_mask=True,
            ... )
            >>> print(pool_out.shape)
            paddle.Size([1, 1, 3, 3])
            >>> print(indices.shape)
            paddle.Size([1, 1, 3, 3])
            >>> unpool_out = F.max_unpool2d(pool_out, indices, kernel_size=2, padding=0)
            >>> print(unpool_out.shape)
            paddle.Size([1, 1, 6, 6])

            >>> # specify a different output size than input size
            >>> unpool_out = F.max_unpool2d(
            ...     pool_out,
            ...     indices,
            ...     kernel_size=2,
            ...     padding=0,
            ...     output_size=[7, 7],
            ... )
            >>> print(unpool_out.shape)
            paddle.Size([1, 1, 7, 7])

   z4The x should have [N, C, H, W] format, but received r   z:The indices should have [N, C, H, W] format, but received rJ   r   ro   rF   )rS   z@Attr(data_format) should be 'NCHW'. Received Attr(data_format): r   r1   ru   r   rx   r   r   r   )ndimr/   r.   r   r   r	   r   r   r   r   r   r   r   r1   r   rn   rq   rF   rZ   r   r   r   r   r   r   r   s                r)   max_unpool2dr   i  sj   x 	vv{B177)1M
 	
 ||qHWXY
 	
 "+q+>K~ M:gq)4G("""-a1
 	

 &	K W;
 G-FH-F4E::5AJ
+
## &
	   r+   c                @   U R                   S:w  a  [        SU R                   S35      eUR                   S:w  a  [        SUR                   S35      e[        USS5      nUc  UnO[        USS5      n[        USS5      nUS	;  a  [        S
U S35      e[	        XX4U5      n[        5       (       a  [        R                  " XX#XFU5      nU$ Sn	[        U	40 [        5       D6n
U
R                  SS9nU
R                  U5      nU
R                  U	XS.SU0SUUUUS.S9  U$ )a  
This API implements max unpooling 3d operation.
`max_unpool3d` accepts the output of `max_pool3d` as input,
including the indices of the maximum value and calculate the partial inverse.
All non-maximum values are set to zero.

- Input: :math:`(N, C, D_{in}, H_{in}, W_{in})`
- Output: :math:`(N, C, D_{out}, H_{out}, W_{out})`, where

.. math::
    D_{out} = (D_{in} - 1) * stride[0] - 2 * padding[0] + kernel\_size[0]

.. math::
    H_{out} = (H_{in} - 1) * stride[1] - 2 * padding[1] + kernel\_size[1]

.. math::
    W_{out} = (W_{in} - 1) * stride[2] - 2 * padding[2] + kernel\_size[2]

or as given by :attr:`output_size` in the call operator


Args:
    x (Tensor): The input tensor of unpooling operator which is a 5-D tensor with
                      shape [N, C, D, H, W]. The format of input tensor is `"NCDHW"`,
                      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. The data type is float32, float64 or int64.
    indices (Tensor): The indices given out by maxpooling3d which is a 5-D tensor with
                      shape [N, C, D, H, W]. The format of input tensor is `"NCDHW"` ,
                      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. The data type is int32 or int64.
    kernel_size (int|list|tuple): The unpool kernel size. If unpool kernel size is a tuple or list,
        it must contain an integer.
    stride (int|list|tuple): The unpool stride size. If unpool stride size is a tuple or list,
        it must contain an integer.
    padding (int | tuple): Padding that was added to the input.
    output_size(list|tuple, optional): The target output size. If output_size is not specified,
                       the actual output shape will be automatically calculated by (input_shape,
                       kernel_size, stride, padding).
    data_format (string): The data format of the input and output data.
                    The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_depth, input_height, input_width]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of unpooling result.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> data = paddle.rand(shape=[1, 1, 4, 4, 6])
        >>> pool_out, indices = F.max_pool3d(data, kernel_size=2, stride=2, padding=0, return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([1, 1, 2, 2, 3])
        >>> print(indices.shape)
        paddle.Size([1, 1, 2, 2, 3])
        >>> unpool_out = F.max_unpool3d(pool_out, indices, kernel_size=2, padding=0)
        >>> print(unpool_out.shape)
        paddle.Size([1, 1, 4, 4, 6])

   z7The x should have [N, C, D, H, W] format, but received r   z=The indices should have [N, C, D, H, W] format, but received r   r   ro   rF   )rW   zAAttr(data_format) should be 'NCDHW'. Received Attr(data_format): unpool3dr1   ru   r   rx   r   r   r   )r   r/   r.   r   r   r	   r   r   r   r   r   r   r   r   s                r)   max_unpool3dr     sj   Z 	vv{EaggYaP
 	
 ||qKGMM?Z[\
 	
 "+q+>K~ M:gq)4G)#""-a1
 	

 &	K W;
 G-FH-F4E::5AJ
+
## &
	   r+   c                   [        USS5      nUc  UnO[        USS5      nUS;  a  [        SU S35      eUS:X  a  SOS	n[        USXS
9u  p9US:X  a  U(       a  [        S5      e[        5       (       aO  U(       a(  [        R
                  " XX#S	S	U5      n
U(       a  U
$ U
S   $ [        R                  " U UUUUSUSS	S	U	5      $ U(       a  SOSn[        U40 [        5       D6n[        U S/ SQS5        UR                  SS9nUR                  U5      nU(       a7  UR                  S5      nXS.nUR                  SSU 0USUS	UUU	SUSUS.
S9  X4$ SU0nUR                  SSU 0USUS	UUU	SUSUS.
S9  U$ )az  
This API implements max pooling 2d operation.
See more details in :ref:`api_paddle_nn_MaxPool2d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
                      shape [N, C, H, W]. The format of input tensor is `"NCHW"` or
                      `"NHWC"`, 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. The data type if float32 or float64.
    kernel_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
        it must contain two integers, (kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be a square of an int.
    stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
        it must contain two integers, (stride_Height, stride_Width).
        Otherwise, the pool stride size will be a square of an int.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode (bool): when True, will use `ceil` instead of `floor` to compute the output shape
    return_mask (bool): Whether to return the max indices along with the outputs. Default False, only support `"NCHW"` data format
    data_format (string): The data format of the input and output data. An optional string from: `"NCHW"`, `"NHWC"`.
                    The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_height, input_width]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.
Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> # max pool2d
        >>> x = paddle.uniform([1, 3, 32, 32], paddle.float32)
        >>> out = F.max_pool2d(x, kernel_size=2, stride=2, padding=0)
        >>> print(out.shape)
        paddle.Size([1, 3, 16, 16])
        >>> # for return_mask=True
        >>> out, max_indices = F.max_pool2d(x, kernel_size=2, stride=2, padding=0, return_mask=True)
        >>> print(out.shape)
        paddle.Size([1, 3, 16, 16])
        >>> print(max_indices.shape)
        paddle.Size([1, 3, 16, 16])
rJ   r   ro   rR   rU   r   rT   TF)r[   rG   rc   zSWhen setting return_mask to true, data_format must be set to NCHW in API:max_pool2dr   r   r   rt   r1   r   
max_pool2dru   r   r   rw   ry   r   rx   )r   r/   re   r	   r   r   rt   r   r   r   r   r   r   r1   rn   rq   rF   r   rc   rZ   r   rG   rd   r   r   r   r   r   r   r   s                    r)   r   r   z  s   ~ "+q+>K~ M:**""-a1
 	

 '&04eL!3!,"G fa
 	
 11yF )67fQi7==!  .9)hW11 s?	
 ""C"8<<UC<<WED&5G,Qx$)(&+% '):!%!*!%#.	  " ## h'GQx$)(&+% '):!%!*!%#.	  " Or+   c                ~   [        USS5      nUc  UnO[        USS5      n[        US5      n[        USXS9u  p9US:X  a  U(       a  [        S5      e[	        5       (       aO  U(       a(  [
        R                  " XX#SSU5      n
U(       a  U
$ U
S   $ [
        R                  " U UUUUS	US
SSU	5      $ U(       a  SOSn[        U40 [        5       D6n[        U S/ SQS5        UR                  SS9nUR                  U5      nUR                  S5      nXS.nUR                  USU 0US
USUUU	S	USUS.
S9  U(       a  X4$ U$ )a  
This API implements max pooling 3d operation.
See more details in :ref:`api_paddle_nn_MaxPool3D` .

Args:
    x (Tensor): The input tensor of pooling operator, which is a 5-D tensor with
                      shape [N, C, D, H, W]. The format of input tensor is `"NCDHW"` or `"NDHWC"`, where N represents batch size, C represents the number of channels, D, H and W represent the depth, height and width of the feature respectively.
    kernel_size (int|list|tuple): The pool kernel size. If the kernel size
        is a tuple or list, it must contain three integers,
        (kernel_size_Depth, kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be the cube of an int.
    stride (int|list|tuple): The pool stride size. If pool stride size is a tuple or list,
        it must contain three integers, [stride_Depth, stride_Height, stride_Width).
        Otherwise, the pool stride size will be a cube of an int.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 3, [pad_depth, pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 6. [pad_depth_front, pad_depth_back, pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode (bool): ${ceil_mode_comment}
    return_mask (bool): Whether to return the max indices along with the outputs. Default False. Only support "NDCHW" data_format.
    data_format (string): The data format of the input and output data. An optional string from: `"NCDHW"`, `"NDHWC"`.
                    The default is `"NCDHW"`. When it is `"NCDHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_depth, input_height, input_width]`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> # max pool3d
        >>> x = paddle.uniform([1, 3, 32, 32, 32])
        >>> output = F.max_pool3d(x, kernel_size=2, stride=2, padding=0)
        >>> print(output.shape)
        paddle.Size([1, 3, 16, 16, 16])

        >>> # for return_mask=True
        >>> x = paddle.uniform([1, 3, 32, 32, 32])
        >>> output, max_indices = paddle.nn.functional.max_pool3d(x, kernel_size=2, stride=2, padding=0, return_mask=True)
        >>> print(output.shape)
        paddle.Size([1, 3, 16, 16, 16])
        >>> print(max_indices.shape)
        paddle.Size([1, 3, 16, 16, 16])
r   r   ro   rr   rX   zTWhen setting return_mask to true, data_format must be set to NCDHW in API:max_pool3dFr   Tr   max_pool3d_with_indexr   r1   r   
max_pool3dru   r   r   rw   ry   r   )r   r\   re   r/   r	   r   r   r   r   r   r   r   r   r   r   s                    r)   r   r     s   @ "+q+>K~ M: a0L!3"G g+b
 	
 11yF )67fQi7==!  .9)hW11 s?	
 ""C"8<<UC88A"18 %$"'!#%6!&"*	 	 	
$ $/<H<r+   r(   c                   Sn[        U S5        S/[        USS5      Qn[        U S/5      n [        5       (       aQ  [	        5       (       a  U R                  S5      n [        R                  " U USS/SS/SSS	USSS
5      n[        US/5      $ Sn[        U S/ SQS5        [        US[        S5        [        U40 [        5       D6nUR                  SS9nUR                  U5      nSU0n	UR!                  USU 0U	UUSS.S9  [        US/5      $ )ax  
Adaptive average pooling 1d operation on :attr:`x` according to :attr:`output_size`.

Notes:
    See more details in :ref:`api_paddle_nn_AdaptiveAvgPool1d` .

Args:
    x (Tensor): The input Tensor of pooling, which is a 3-D tensor with shape :math:`[N, C, L]`, where :math:`N` is batch size, :math:`C` is the number of channels and :math:`L` is the length of the feature. The data type is float32 or float64.
        Alias: ``input``.
    output_size (int): The target output size. Its data type must be int.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor: The result of 1D adaptive average pooling. Its data type is same as input.

Examples:
    .. code-block:: pycon

        >>> # average adaptive pool1d
        >>> # suppose input data in shape of [N, C, L], `output_size` is m or [m],
        >>> # output shape is [N, C, m], adaptive pool divide L dimension
        >>> # of input data into m grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive max pool performs calculations as follow:
        >>> #
        >>> #     for i in range(m):
        >>> #         lstart = floor(i * L / m)
        >>> #         lend = ceil((i + 1) * L / m)
        >>> #         output[:, :, i] = sum(input[:, :, lstart: lend])/(lstart - lend)
        >>> #
        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> data = paddle.uniform([1, 3, 32])
        >>> pool_out = F.adaptive_avg_pool1d(data, output_size=16)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
rs   r   r!   r   rJ   Fr   TrS   r`   rt   r1   ri   adaptive_pool2dadaptive_pool1dru   rx   rw   )rz   r{   adaptiver   )r3   r   r   r	   r   _use_gpudnnr   rt   r   r   r   r;   r   r   r   r   r   )
r1   r   r   	pool_typer   r   l_typer   r   r   s
             r)   adaptive_avg_pool1dr     sF   T IAB_[![ABI!aSAe$A==FF
 x!%% s57H	
 	;c4EFV0vx0""C"8<<UC(#8 )" 	 	 		
 x!%%r+   c                   US;  a  [        SU S35      eUS:X  a  U R                  SS u  pEOU R                  SS u  pE[        U[        5      (       a  [	        USS	5      nO[        U5      nUS
   c  XAS
'   US   c  XQS'   [        5       (       aM  U Vs/ s H?  n[        U[        5      (       a%  [        R                  " U5      R                  S
5      OUPMA     nnO[        U5      (       a  [        U5      n[        5       (       aD  [        5       (       a  U R                  S5      n [         R"                  " U USS/S
S
/SSUSSSS5      $ Sn[%        U S/ SQS5        ['        US[(        S5        [+        U40 [-        5       D6nUR/                  SS9n	UR1                  U	5      n
SU
0nUR3                  USU 0USUSUS.S9  U
$ s  snf )aD
  

Applies 2D adaptive avg pooling on input tensor. The h and w dimensions
of the output tensor are determined by the parameter output_size.

For avg adaptive pool2d:

..  math::
    hstart &= floor(i * H_{in} / H_{out}) \\
    hend &= ceil((i + 1) * H_{in} / H_{out}) \\
    wstart &= floor(j * W_{in} / W_{out}) \\
    wend &= ceil((j + 1) * W_{in} / W_{out}) \\
    Output(i ,j) &= \frac{\sum Input[hstart:hend, wstart:wend]}{(hend - hstart) * (wend - wstart)}

Args:
    x (Tensor): The input tensor of adaptive avg pool2d operator, which is a 4-D tensor.
                      The data type can be float32 or float64.
        Alias: ``input``.
    output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list,
        it must contain two element, (H, W). H and W can be either a int, or None which means
        the size will be the same as that of the input.
    data_format (str, optional): The data format of the input and output data. An optional string
        from: "NCHW", "NHWC". The default is "NCHW". When it is "NCHW", the data is stored in
        the order of: [batch_size, input_channels, input_height, input_width].
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor, The output tensor of avg adaptive pool2d result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # adaptive avg pool2d
        >>> # suppose input data in shape of [N, C, H, W], `output_size` is [m, n],
        >>> # output shape is [N, C, m, n], adaptive pool divide H and W dimensions
        >>> # of input data into m * n grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive avg pool performs calculations as follow:
        >>> #
        >>> #     for i in range(m):
        >>> #         for j in range(n):
        >>> #             hstart = floor(i * H / m)
        >>> #             hend = ceil((i + 1) * H / m)
        >>> #             wstart = floor(i * W / n)
        >>> #             wend = ceil((i + 1) * W / n)
        >>> #             output[:, :, i, j] = avg(input[:, :, hstart: hend, wstart: wend])
        >>> #
        >>> import paddle

        >>> x = paddle.rand([2, 3, 32, 32])
        >>> # x.shape is [2, 3, 32, 32]
        >>> out = paddle.nn.functional.adaptive_avg_pool2d(x = x,
        ...                                                output_size=[3, 3])
        >>> print(out.shape)
        paddle.Size([2, 3, 3, 3])

rR   rU   r   rS   rJ   r   r!   r   r   r   FTrs   r`   rt   r1   ri   adaptive_avg_pool2drZ   ru   rx   rw   rz   r{   r   rZ   r   )r/   r.   r%   r;   r   r&   r   r   r   r   r   r   r   r	   r   r   r   rt   r   r   ra   r   r   r   r   r   )r1   r   rZ   r   in_hin_wr   r   r   r   r   r   s               r)   r   r     s
   D **""-a1
 	

 fWWQq\
dWWQq\
+s##%k1mD;'q>!!Nq>!!N $
# '1x&@&@BHHTN"dJ# 	 

 
k	"	"-k:e$A}}FF
 	
  s57L	
 	;s4IJV0vx0""C"8<<UC(#8 %$ *		 	 
	
 a
s   AGc                   US;  a  [        SU S35      eUS:X  a  U R                  SS u  pEnOU R                  SS u  pEn[        U[        5      (       a  [	        US	S
5      nO)[        U5      nUS   c  XAS'   US   c  XQS'   US   c  XaS'   [        5       (       aD  [        5       (       a  U R                  S5      n [        R                  " U U/ SQ/ SQSSUSSSS5      $ Sn[        U S/ SQS5        [        US[        S5        [        U40 [        5       D6nUR!                  SS9n	UR#                  U	5      n
SU
0nUR%                  USU 0USUSUS.S9  U
$ )a  

This operation applies 3D adaptive avg pooling on input tensor. The h and w dimensions
of the output tensor are determined by the parameter output_size.

For avg adaptive pool3d:

..  math::
    dstart &= floor(i * D_{in} / D_{out}) \\
    dend &= ceil((i + 1) * D_{in} / D_{out}) \\
    hstart &= floor(j * H_{in} / H_{out}) \\
    hend &= ceil((j + 1) * H_{in} / H_{out}) \\
    wstart &= floor(k * W_{in} / W_{out}) \\
    wend &= ceil((k + 1) * W_{in} / W_{out}) \\
    Output(i ,j, k) &= \frac{\sum Input[dstart:dend, hstart:hend, wstart:wend]}
        {(dend - dstart) * (hend - hstart) * (wend - wstart)}

Args:
    x (Tensor): The input tensor of adaptive avg pool3d operator, which is a 5-D tensor.
        The data type can be float32, float64.
        Alias: ``input``.
    output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or
        list, it must contain three elements, (D, H, W). D, H and W can be either a int,
        or None which means the size will be the same as that of the input.
    data_format (str, optional): The data format of the input and output data. An optional string
        from: "NCDHW", "NDHWC". The default is "NCDHW". When it is "NCDHW", the data is stored in
        the order of: [batch_size, input_channels, input_depth, input_height, input_width].
    name(str|None, optional): For detailed information, please refer to :ref:`api_guide_Name`.
        Usually name is no need to set and None by default.

Returns:
    Tensor, The output tensor of avg adaptive pool3d result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # adaptive avg pool3d
        >>> # suppose input data in shape of [N, C, D, H, W], `output_size` is [l, m, n],
        >>> # output shape is [N, C, l, m, n], adaptive pool divide D, H and W dimensions
        >>> # of input data into l * m * n grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive avg pool performs calculations as follow:
        >>> #
        >>> #     for i in range(l):
        >>> #         for j in range(m):
        >>> #             for k in range(n):
        >>> #                 dstart = floor(i * D / l)
        >>> #                 dend = ceil((i + 1) * D / l)
        >>> #                 hstart = floor(j * H / m)
        >>> #                 hend = ceil((j + 1) * H / m)
        >>> #                 wstart = floor(k * W / n)
        >>> #                 wend = ceil((k + 1) * W / n)
        >>> #                 output[:, :, i, j, k] =
        >>> #                     avg(input[:, :, dstart:dend, hstart: hend, wstart: wend])
        >>> import paddle

        >>> input_data = paddle.randn(shape=(2, 3, 8, 32, 32))
        >>> out = paddle.nn.functional.adaptive_avg_pool3d(x = input_data,
        ...                                                output_size=[3, 3, 3])
        >>> print(out.shape)
        paddle.Size([2, 3, 3, 3, 3])

rV   rY   r   rW   rJ   r   r!   r   r   r   r   Fr!   r!   r!   r   r   r   Trs   r`   r   r1   ri   r   rZ   ru   rx   rw   r   r   )r/   r.   r%   r;   r   r&   r	   r   r   r   r   r   r   ra   r   r   r   r   r   )r1   r   rZ   r   in_lr   r   r   r   r   r   r   s               r)   adaptive_avg_pool3dr     s   L ,,""-a1
 	

 g771Q<D771Q<D+s##%k1mD;'q>!!Nq>!!Nq>!!Ne$A}}
 	
  s57L	
 	;s4IJV0vx0""C"8<<UC(#8 %$ *		 	 
	
 r+   return_indicesc           
        [        U S5        S/[        USS5      Qn[        U S/5      n [        5       (       aV  [        R
                  " XSS/SS/SSS5      nU(       a   [        US   S/5      [        US   S/5      4$ [        US   S/5      $ Sn[        U S	S
S/S5        [        US[        S5        [        US[        S5        [        U40 [        5       D6nUR                  S	S9nUR                  U5      nUR                  S5      n	XYS.n
UR                  USU 0U
SUSSS.S9  U(       a  [        US/5      [        U	S/5      4$ [        US/5      $ )a  
This API implements adaptive max pooling 1d operation.
See more details in :ref:`api_paddle_nn_AdaptiveMaxPool1d` .

Args:
    x (Tensor): The input tensor of pooling operator, which is a 3-D tensor
                          with shape [N, C, L].  The format of input tensor is NCL,
                          where N is batch size, C is the number of channels, L is the
                          length of the feature. The data type is float32 or float64.
    output_size (int|list|tuple): The pool kernel size. It can be an integer, or a list or tuple containing a single integer.
    return_mask (bool): If true, the index of max pooling point will be returned along
            with outputs. It cannot be set in average pooling type. Default False.
    name(str|None, optional): For detailed information, please refer
                             to :ref:`api_guide_Name`. Usually name is no need to set and
                             None by default.
Returns:
        Tensor: The output tensor of adaptive pooling result. The data type is same
                  as input tensor.

Examples:
    .. code-block:: pycon

        >>> # max adaptive pool1d
        >>> # suppose input data in shape of [N, C, L], `output_size` is m or [m],
        >>> # output shape is [N, C, m], adaptive pool divide L dimension
        >>> # of input data into m grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive max pool performs calculations as follow:
        >>> #
        >>> #     for i in range(m):
        >>> #         lstart = floor(i * L / m)
        >>> #         lend = ceil((i + 1) * L / m)
        >>> #         output[:, :, i] = max(input[:, :, lstart: lend])
        >>> #
        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> data = paddle.uniform([1, 3, 32], paddle.float32)
        >>> pool_out = F.adaptive_max_pool1d(data, output_size=16)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
        >>> pool_out, indices = F.adaptive_max_pool1d(data, output_size=16, return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
        >>> print(indices.shape)
        paddle.Size([1, 3, 16])
r   r!   r   rJ   r   FTr   r1   rk   rl   adaptive_max_pool1dr   ru   r   r   rw   r   rz   r{   r   rc   r   )r3   r   r   r	   r   r   r   r   r   r;   boolr   r   r   r   r   )r1   r   r   r   r   r   r   r   r   r   r   s              r)   r   r     s   l AB_[![ABI!aSA//1a&1a&%u

  Xa[1#&aS(AB	
 !qc*	
 ) sY	*,A	
 	;S2GH;t5JKV0vx0""C"8<<UC88A"18 %" "		 	 
	
  Xs#WTA3%78	
 A3'	
r+   c           
     \   [        U S5        U R                  SS u  pE[        U[        5      (       a  [	        USS5      nO[        U5      nUS   c  XAS'   US   c  XQS'   [        5       (       a-  [        R                  " XSS/SS/SSS5      nU(       a  U$ US   $ Sn[        U S	S
S/S5        [        US[        S5        [        U40 [        5       D6nUR                  S	S9n	UR                  U	5      nUR                  S5      n
XjS.nUR!                  USU 0USUSSS.S9  U(       a  Xj4$ U$ )a  
This operation applies a 2D adaptive max pooling on input tensor.
See more details in :ref:`api_paddle_nn_AdaptiveMaxPool2d` .

Args:
    x (Tensor): The input tensor of adaptive max pool2d operator, which is a 4-D tensor. The data type can be float16, float32, float64, int32 or int64.
    output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain two elements, (H, W). H and W can be either a int, or None which means the size will be the same as that of the input.
    return_mask (bool): If true, the index of max pooling point will be returned along with outputs. Default False.
    name(str|None, optional): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default.

Returns:
    Tensor: The output tensor of adaptive max pool2d result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # max adaptive pool2d
        >>> # suppose input data in the shape of [N, C, H, W], `output_size` is [m, n]
        >>> # output shape is [N, C, m, n], adaptive pool divide H and W dimensions
        >>> # of input data into m*n grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive max pool performs calculations as follow:
        >>> #
        >>> #     for i in range(m):
        >>> #         for j in range(n):
        >>> #             hstart = floor(i * H / m)
        >>> #             hend = ceil((i + 1) * H / m)
        >>> #             wstart = floor(i * W / n)
        >>> #             wend = ceil((i + 1) * W / n)
        >>> #             output[:, :, i, j] = max(input[:, :, hstart: hend, wstart: wend])
        >>> #
        >>> import paddle

        >>> input_data = paddle.randn(shape=(2, 3, 32, 32))
        >>> out = paddle.nn.functional.adaptive_max_pool2d(x=input_data, output_size=[3, 3])
        >>> print(out.shape)
        paddle.Size([2, 3, 3, 3])
r   rJ   r   r   r!   FTr   r1   rk   rl   adaptive_max_pool2dr   ru   r   r   rw   r   r   r   )r3   r.   r%   r;   r   r&   r	   r   r   r   r   r   r   r   r   r   r   )r1   r   r   r   r   r   r   r   r   r   r   r   s               r)   r   r   t  sf   Z A1JD+s##%k1mD;'q>!!Nq>!!N//QFQFE4
 'x7HQK7( sY	*,A	
 	;t5JK V0vx0""C"8<<UC88A"18 %$ "		 	 
	
 $/<H<r+   c           
     r   [        U S5        U R                  SS u  pEn[        U[        5      (       a  [	        USS5      nO)[        U5      nUS   c  XAS'   US   c  XQS'   US   c  XaS'   [        5       (       a-  [        R                  " X/ SQ/ SQS	S
S	5      nU(       a  U$ US   $ Sn[        U SSS/S5        [        US[        S5        [        U40 [        5       D6n	U	R                  SS9n
U	R                  U
5      nU	R                  S5      nX{S.nU	R!                  USU 0USUS
S	S.S9  U(       a  X{4$ U$ )ay  
This operation applies a 3D adaptive max pooling on input tensor.
See more details in :ref:`api_paddle_nn_AdaptiveMaxPool3d` .

Args:
    x (Tensor): The input tensor of adaptive max pool3d operator, which is a 5-D tensor. The data type can be float32, float64.
    output_size (int|list|tuple): The pool kernel size. If pool kernel size is a tuple or list, it must contain three elements, (D, H, W). D, H and W can be either a int, or None which means the size will be the same as that of the input.
    return_mask (bool): If true, the index of max pooling point will be returned along with outputs. Default False.
    name(str|None, optional): For detailed information, please refer to :ref:`api_guide_Name`. Usually name is no need to set and None by default.

Returns:
    Tensor: The output tensor of adaptive max pool3d result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # adaptive max pool3d
        >>> # suppose input data in the shape of [N, C, D, H, W], `output_size` is [l, m, n]
        >>> # output shape is [N, C, l, m, n], adaptive pool divide D, H and W dimensions
        >>> # of input data into m*n grids averagely and performs poolings in each
        >>> # grid to get output.
        >>> # adaptive max pool performs calculations as follow:
        >>> #
        >>> #     for i in range(l):
        >>> #         for j in range(m):
        >>> #             for k in range(n):
        >>> #                 dstart = floor(i * D / l)
        >>> #                 dend = ceil((i + 1) * D / l)
        >>> #                 hstart = floor(i * H / m)
        >>> #                 hend = ceil((i + 1) * H / m)
        >>> #                 wstart = floor(i * W / n)
        >>> #                 wend = ceil((i + 1) * W / n)
        >>> #             output[:, :, i, j, k] = max(input[:, :, dstart: dend, hstart: hend, wstart: wend])
        >>> #
        >>> import paddle

        >>> input_data = paddle.randn(shape=(2, 3, 8, 32, 32))
        >>> out = paddle.nn.functional.adaptive_max_pool3d(x=input_data, output_size=[3, 3, 3])
        >>> print(out.shape)
        paddle.Size([2, 3, 3, 3, 3])
r   rJ   r   r   r   r!   r   r   FTr   r1   rk   rl   adaptive_max_pool3dr   ru   r   r   rw   r   r   r   )r3   r.   r%   r;   r   r&   r	   r   r   r   r   r   r   r   r   r   r   )r1   r   r   r   r   r   r   r   r   r   r   r   r   s                r)   r   r     sr   ` Awwq|D+s##%k1mD;'q>!!Nq>!!Nq>!!N//Iy%u
 'x7HQK7( sY	*,A	
 	;t5JK V0vx0""C"8<<UC88A"18 %$ "		 	 
	
 $/<H<r+   c           
        [        U S5        Uc  SnOUS::  d  US:  a  [        S5      eUb  [        USS5      OSS/nU R                  SS u  pg[	        U[
        5      (       a  [        USS5      nO[        U5      nUS   c  XaS'   US   c  XqS'   [        5       (       a0  [        R                  " XU[        U5      U5      nU(       a  U$ US   $ S	n	[        U S
/ SQS	5        [        US[        S	5        [        US[        S	5        [        U	40 [        5       D6n
U
R!                  S
S9nU
R#                  U5      nU
R#                  S5      nXS.nU
R%                  U	S
U 0UUUUUS.S9  U(       a  X4$ U$ )a  
This operation applies 2D fractional max pooling on input tensor, which is described in the paper:

[1] Ben Graham, Fractional Max-Pooling. 2015. http://arxiv.org/abs/1412.6071

The h and w dimensions of the output tensor are determined by the parameter output_size.

For each dimension, the fractional max pooling:

..  math::

    \alpha &= size_{input} / size_{output}

    index_{start} &= ceil( \alpha * (i + u) - 1)

    index_{end} &= ceil( \alpha * (i + 1 + u) - 1)

    Output &= max(Input[index_{start}:index_{end}])

    where, u \in (0, 1), i = 0,1,2...size_{output}

The ``u`` from the formula is the parameter ``random_u``, and subtract ``1`` for the index starts from ``0``
instead of ``1`` where ``ceil`` works.

For instance, giving a sequence of length ``7`` is ``[2, 4, 3, 1, 5, 2, 3]``, ``output_size`` is ``5`` and ``random_u`` is ``0.3``.
The ``alpha = 7/5 = 1.4``, the starts of index is ``[0, 1, 3, 4, 6]``, the ends of index is ``[1, 3, 4, 6, 7]`` and makes the
random sequence in the paper is ``index_end - index_start = [1, 2, 1, 2, 1]``. The strides and kernel_sizes are both equal to
the random sequence, giving the final pooling output is ``[2, 4, 1, 5, 3]``.

Parameters:
    x (Tensor): The input tensor of fractional max pool2d operator, which is a 4-D tensor. The data type can be float16, bfloat16, float32, float64.
    output_size(int|list|tuple): The output size. If output size is a tuple or list, it must contain
        two element, (H, W). H and W can be either a int, or None which means the size will be the same as that of
        the input.
    kernel_size (int|list|tuple, optional): The pool kernel size. If the kernel size
        is a tuple or list, it must contain two integers, (kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be the square of an int. Default is None, means using the non-overlapping mode.
    random_u(float): A random float number in range (0, 1) for the fractional pooling.
        Default None, means randomly generated by framework which can be fixed by ``paddle.seed``.
    return_mask(bool, optional): If true, the index of max pooling point will be returned along with outputs. Default False.
    name(str|None, optional): For detailed information, please refer to :ref:`api_guide_Name`.
        Usually name is no need to set and None by default.

Returns:
    Tensor: The output tensor of fractional max pool2d result which is a 4-D tensor.. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # fractional max pool2d
        >>> # suppose input data in shape of [N, C, H, W], `output_size` is [m, n],
        >>> # output shape is [N, C, m, n], fractional pool divide H and W dimensions
        >>> # of input data into m * n grids and performs poolings in each
        >>> # grid to get output.

        >>> import paddle

        >>> x = paddle.rand([2, 3, 32, 32])

        >>> # disjont: without `kernel_size`
        >>> pool_out = paddle.nn.functional.fractional_max_pool2d(x, output_size=3)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 3, 3])

        >>> # overlapping: with `kernel_size`
        >>> pool_out = paddle.nn.functional.fractional_max_pool2d(x, kernel_size=2, output_size=3)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 3, 3])

        >>> pool_out, indices = paddle.nn.functional.fractional_max_pool2d(x, output_size=[2, 3], return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 2, 3])
        >>> print(indices.shape)
        paddle.Size([2, 3, 2, 3])
r           r   r!   3The param `random_u` should be a `float` in (0, 1).rJ   rn   r   fractional_max_pool2dr1   r   rj   rk   rl   r   random_uru   r   outr   r   rn   r   r   r   )r3   r/   r   r.   r%   r;   r&   r	   r   r   floatr   r   r   r   r   r   r   r   )r1   r   rn   r   r   r   r   r   r   r   r   r   r   r   s                 r)   r   r   2  s   f Aq=HME  " 	Q6V  1JD+s##%k1mD;'q>!!Nq>!!N//Kx+
 'x7HQK7 ) 7#		
 	;t5LM#		
 V0vx0""C"8<<UC88A"18**$*		 	 
	
 $/<H<r+   c           
         [        U S5        Uc  SnOUS::  d  US:  a  [        S5      eUb  [        USS5      O/ SQnU R                  S	S u  pgn[	        U[
        5      (       a  [        USS
5      nO)[        U5      nUS   c  XaS'   US   c  XqS'   US	   c  XS	'   [        5       (       a1  [        R                  " U UU[        U5      U5      n	U(       a  U	$ U	S   $ Sn
[        U S/ SQS5        [        US[        S5        [        US[        S5        [        U
40 [        5       D6nUR!                  SS9nUR#                  U5      n	UR#                  S5      nXS.nUR%                  U
SU 0UUUUUS.S9  U(       a  X4$ U	$ )a9  
This operation applies 3D fractional max pooling on input tensor, which is described in the paper:

[1] Ben Graham, Fractional Max-Pooling. 2015. http://arxiv.org/abs/1412.6071

The d, h and w dimensions of the output tensor are determined by the parameter output_size.

For each dimension, the fractional max pooling:

..  math::

    \alpha &= size_{input} / size_{output}

    index_{start} &= ceil( \alpha * (i + u) - 1)

    index_{end} &= ceil( \alpha * (i + 1 + u) - 1)

    Output &= max(Input[index_{start}:index_{end}])

    where, u \in (0, 1), i = 0,1,2...size_{output}

The ``u`` from the formula is the parameter ``random_u``, and subtract ``1`` for the index starts from ``0``
instead of ``1`` where ``ceil`` works.

For instance, giving a sequence of length ``7`` is ``[2, 4, 3, 1, 5, 2, 3]``, ``output_size`` is ``5`` and ``random_u`` is ``0.3``.
The ``alpha = 7/5 = 1.4``, the starts of index is ``[0, 1, 3, 4, 6]``, the ends of index is ``[1, 3, 4, 6, 7]`` and makes the
random sequence in the paper is ``index_end - index_start = [1, 2, 1, 2, 1]``. The strides and kernel_sizes are both equal to
the random sequence, giving the final pooling output is ``[2, 4, 1, 5, 3]``.

Parameters:
    x (Tensor): The input tensor of fractional max pool3d operator, which is a 5-D tensor. The data type can be float16, bfloat16, float32, float64.
    output_size(int|list|tuple): The output size. If output size is a tuple or list, it must contain
        three element, (D, H, W). D, H and W can be either a int, or None which means the size will be the same as that of
        the input.
    kernel_size (int|list|tuple): The pool kernel size. If the kernel size
        is a tuple or list, it must contain three integers, (kernel_size_Depth, kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be the cube of an int. Default is None, means using the non-overlapping mode.
    random_u(float): A random float number in range (0, 1) for the fractional pooling.
        Default None, means randomly generated by framework which can be fixed by ``paddle.seed``.
    return_mask(bool, optional): If true, the index of max pooling point will be returned along with outputs. Default False.
    name(str|None, optional): For detailed information, please refer to :ref:`api_guide_Name`.
        Usually name is no need to set and None by default.

Returns:
    Tensor: The output tensor of fractional max pool3d result which is a 5-D tensor.. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> # fractional max pool3d
        >>> # suppose input data in shape of [N, C, D, H, W], `output_size` is [l, m, n],
        >>> # output shape is [N, C, l, m, n], fractional pool divide D, H and W dimensions
        >>> # of input data into l * m * n grids and performs poolings in each
        >>> # grid to get output.

        >>> import paddle

        >>> x = paddle.rand([2, 3, 8, 32, 32])

        >>> # disjont: without `kernel_size`
        >>> pool_out = paddle.nn.functional.fractional_max_pool3d(x, output_size=3)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 3, 3, 3])

        >>> # overlapping: with `kernel_size`
        >>> pool_out = paddle.nn.functional.fractional_max_pool3d(x, kernel_size=2, output_size=3)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 3, 3, 3])

        >>> pool_out, indices = paddle.nn.functional.fractional_max_pool3d(x, output_size=[2, 3, 3], return_mask=True)
        >>> print(pool_out.shape)
        paddle.Size([2, 3, 2, 3, 3])
        >>> print(indices.shape)
        paddle.Size([2, 3, 2, 3, 3])
r   r   r   r!   r   r   rn   r   rJ   r   fractional_max_pool3dr1   r   r   r   ru   r   r   r   r   )r3   r/   r   r.   r%   r;   r&   r	   r   r   r   r   r   r   r   r   r   r   r   )r1   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   s                  r)   r   r     s   f Aq=HME  " 	Q6  wwq|D+s##%k1mD;'q>!!Nq>!!Nq>!!N//(O
 'x7HQK7 ) 7#		
 	;t5LM#		
 V0vx0""C"8<<UC88A"18**$*		 	 
	
 $/<H<r+   c                   UnUS:X  a  SnSn	OSnSn	[        5       (       d  [        U S/ SQS5        [        U S	5        [        X	/5      n [	        USS
5      nS/UQnUc  UnO[	        USS5      nS/UQn[        US
SS9  [        USSS9  [        US5      n
[        USXS9u  pK[        U5      n[        5       (       a-  [        R                  " U UUUUSUSSSUU5      n[        X/5      $ Sn[        U40 [        5       D6nUR                  SS9nUR!                  U5      nUR#                  USU 0SU0SUSUUUUSUUS.
S9  [        UU	/5      $ )a
  
This API implements power-average pooling 1d operation.
See more details in :ref:`api_paddle_nn_LPPool1d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 3-D tensor with
                      shape [N, C, L]. where `N` is batch size, `C` is the number of channels,
                      `L` is the length of the feature. The data type is float16, float32 or float64.
    norm_type (int|float): The number the power operation.
    kernel_size (int|list|tuple): The pool kernel size. If it is a tuple or list,
        it must contain two integers, (kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be a square of an int.
    stride (int|list|tuple): The stride size. If it is a tuple or list,
        it must contain two integers, (stride_Height, stride_Width).
        Otherwise, the stride size will be a square of an int.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode(bool, optional): When True, it will use `ceil` instead of `floor` to compute the output shape. Default: False.
    data_format(str, optional): The data format of the input and output data. An optional string from: `"NCL"`,
        `"NLC"`. When it is `"NCL"`, the data is stored in the order of:
        `[batch_size, input_channels, input_length]`. Default:`"NCL"`.
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.
Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn as nn

        >>> data = paddle.uniform([1, 3, 32], paddle.float32)
        >>> LPPool1D = nn.LPPool1D(norm_type=3, kernel_size=2, stride=2, padding=0)
        >>> pool_out = LPPool1D(data)
        >>> print(pool_out.shape)
        paddle.Size([1, 3, 16])
rP   rS   rJ   rT   r!   r1   ri   	lp_pool1dr   rn   ro   r@   rp   rq   rr   TlpF	lp_pool2dru   r   
rz   rn   r|   r}   r~   rd   rc   r   rZ   	norm_typer   )r   r   r3   r   r   rC   r\   re   rg   r	   r   r   r   r   r   r   r   r   )r1   r   rn   rq   rF   rc   rZ   r   ori_data_formataxisrG   rd   r   r   r   r   r   s                    r)   r   r   n	  s   p "Oe s5{	
 A!VA!+q-@K#{#K~ M:fK$GFH= !4L!3"G
 %W-G!!
 vv&& W11""C"8<<UC8H% $*"'!#%6&!*&	 	 	
" x$((r+   c                &   [        U S5        US:X  a  [        S5      e[        U5      n[        USS5      nUc  UnO[        USS5      n[	        USSS	9  [	        US
SS	9  [        US5      n[        USXS9u  pI[        5       (       a#  [        R                  " U UUUUSUSSSU	U5      n
U
$ Sn[        U40 [        5       D6n[        U S/ SQS5        UR                  SS9nUR                  U5      nUR                  USU 0SU0SUSUUU	USUUS.
S9  U$ )aG  
This API implements power-average pooling 2d operation.
See more details in :ref:`api_paddle_nn_LPPool2d` .

Args:
    x (Tensor): The input tensor of pooling operator which is a 4-D tensor with
                      shape [N, C, H, W]. The format of input tensor is `"NCHW"` or
                      `"NHWC"`, 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. The data type if float32 or float64.
    norm_type (int|float): The number the power operation.
    kernel_size (int|list|tuple): The pool kernel size. If it is a tuple or list,
        it must contain two integers, (kernel_size_Height, kernel_size_Width).
        Otherwise, the pool kernel size will be a square of an int.
    stride (int|list|tuple): The stride size. If it is a tuple or list,
        it must contain two integers, (stride_Height, stride_Width).
        Otherwise, the stride size will be a square of an int.
    padding (string|int|list|tuple): The padding size. Padding could be in one of the following forms.
        1. A string in ['valid', 'same'].
        2. An int, which means the feature map is zero padded by size of `padding` on every sides.
        3. A list[int] or tuple(int) whose length is 2, [pad_height, pad_weight] whose value means the padding size of each dimension.
        4. A list[int] or tuple(int) whose length is 4. [pad_height_top, pad_height_bottom, pad_width_left, pad_width_right] whose value means the padding size of each side.
        5. A list or tuple of pairs of integers. It has the form [[pad_before, pad_after], [pad_before, pad_after], ...]. Note that, the batch dimension and channel dimension should be [0,0] or (0,0).
        The default value is 0.
    ceil_mode(bool, optional): When True, it will use `ceil` instead of `floor` to compute the output shape. Default: False.
    data_format (string, optional): The data format of the input and output data. An optional string from: `"NCHW"`, `"NHWC"`.
                    The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
                    `[batch_size, input_channels, input_height, input_width]`. Default: "NCHW".
    name(str|None, optional): For detailed information, please refer
                         to :ref:`api_guide_Name`. Usually name is no need to set and
                         None by default.

Returns:
    Tensor: The output tensor of pooling result. The data type is same as input tensor.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn.functional as F

        >>> # lp pool2d
        >>> x = paddle.uniform([1, 3, 32, 32], paddle.float32)
        >>> out = F.lp_pool2d(x, norm_type=2, kernel_size=2, stride=2, padding=0)
        >>> print(out.shape)
        paddle.Size([1, 3, 16, 16])
r   r   z`norm_type` cannot be 0.rJ   r   ro   rn   r@   rp   rq   r   Tr   Fr   r1   r   ru   r   r   r   )r3   r/   r   r   rC   r\   re   r	   r   r   r   r   r   r   r   r   )r1   r   rn   rq   rF   rc   rZ   r   rG   rd   r   r   r   r   r   s                  r)   r   r   	  sl   v AA~344i I!+q+>K~ M:K$GFH= a0L!3L"G !!
 W11 s?	
 ""C"8<<UC8H% $*"'!#%6&!*&	 	 	
$ r+   r?   )FF)Nr   TFN)r1   r   rn   r   rq   Size1 | NonerF    _PaddingSizeMode | Size1 | Size2r   r   rc   r   r   
str | Nonereturnr   )Nr   FTNrS   N)r1   r   rn   r   rq   Size2 | NonerF    _PaddingSizeMode | Size2 | Size4rc   r   r   r   r   float | NonerZ   r   r   r   r  r   )Nr   FTNrW   N)rn   r   rq   Size3 | NonerF    _PaddingSizeMode | Size3 | Size6rc   r   r   r   r   r  rZ   r   r   r   r  r   )Nr   FFN)r1   r   rn   r   rq   r   rF   r   r   r   rc   r   r   r   r  r   )Nr   rP   NN)r1   r   r   r   rn   r   rq   r   rF   r   rZ   r   r   Sequence[int] | Noner   r   r  r   )Nr   rS   NN)r1   r   r   r   rn   r   rq   r  rF   r  rZ   r   r   r  r   r   r  r   )Nr   rW   NN)r1   r   r   r   rn   r   rq   r  rF   r  rZ   r   r   r  r   r   r  r   )Nr   FFrS   N)r1   r   rn   r   rq   r  rF   r  r   r   rc   r   rZ   r   r   r   r  r   )Nr   FFrW   N)r1   r   rn   r   rq   r  rF   r  r   r   rc   r   rZ   r   r   r   r  r   r$   )r1   r   r   r;   r   r   r  r   )rS   N)
r1   r   r   r   rZ   r   r   r   r  r   )rW   N)
r1   r   r   r   rZ   r   r   r   r  r   )FN)
r1   r   r   r   r   r   r   r   r  r   )
r1   r   r   r   r   r   r   r   r  r   )
r1   r   r   r   r   r   r   r   r  r   )NNFN)r1   r   r   r   rn   r  r   r  r   r   r   r   r  r   )Nr   FrP   N)r1   r   r   r   rn   r   rq   r   rF   r   rc   r   rZ   r   r   r   r  r   )Nr   FrS   N)r1   r   r   r   rn   r   rq   r  rF   r  rc   r   rZ   r   r   r   r  r   )L
__future__r   typingr   numpyr   paddler   r   paddle.base.frameworkr   r   r	   paddle.utils.decorator_utilsr
   r   r   base.data_feederr   r   base.layer_helperr   tensor.manipulationr   r   utilsr   r   r   r   collections.abcr   r   paddle._typingr   r   r   r   r   r   r   r    commonr"   __all__r*   r3   r;   r   r8   rC   rH   rN   r\   re   rg   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   r+   r)   <module>r     s   #    * 
  E , 5  (	 	 	 )
,
 '*5\ 
"I=63&l
   01u&u&u& u& .	u&
 u& u& u& u&v  01%) &  .	
   #   J  01%) 'z
z
 z
 .	z

 z
 z
 #z
 z
 z
 z
@  01


 
 .	

 
 
 
 
D)`  01 %(,x$x$x$ x$ 	x$
 .x$ x$ &x$ x$ x$~  01 &(,MMM M 	M
 .M M &M M Mh  01 '(,~~~ ~ 	~
 .~ ~ &~ ~ ~H  01 &___ _ .	_
 _ _ _ _ _J  01 'C=C=C= C= .	C=
 C= C= C= C= C=L #w 48U&U&U&'1U&U& !U&p #w  !'	FFF F 	F
 F !FR #w  !(	DDD D 	D
 D !DN #w-1A!BC 	c
c
c
 c
 	c

 c
 Dc
L #w-1A!BC 	W=W=W= W= 	W=
 W= DW=t #w-1A!BC 	_=_=_= _= 	_=
 _= D_=J !%!X=X=X= X= 	X=
 X= X= X=| !%!^=^=^= ^= 	^=
 ^= ^= ^=B 
  01 %@)@)@) @) 	@)
 .@) @) @) @) @) @)F 
  01 &xxx x 	x
 .x x x x x xr+   