
    ёi                   >   S SK Jr  S SKJrJrJrJr  S SKrS SKJr  S SK	J
r
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JrJrJrJrJr  SSKJ r J!r!J"r"  \" S\\\#   5      r$S SK	J%r%  / r&\S[S j5       r'\S\S j5       r'S 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- " S S \5      r. " S! S"\5      r/ " S# S$\5      r0 " S% S&\5      r1 " S' S(\5      r2 " S) S*\5      r3 " S+ S,\35      r4 " S- S.\45      r5 " S/ S0\45      r6 " S1 S2\45      r7 " S3 S4\45      r8 " S5 S6\45      r9 " S7 S8\35      r: " S9 S:\:5      r; " S; S<\:5      r< " S= S>\:5      r= " S? S@\:5      r> " SA SB\:5      r? " SC SD\35      r@ " SE SF\@5      rA " SG SH\@5      rB " SI SJ\@5      rC " SK SL\@5      rD " SM SN\@5      rE " SO SP\5      rF " SQ SR\5      rG " SS ST\5      rH " SU SV\5      rI " SW SX\5      rJ " SY SZ\5      rKg)]    )annotations)TYPE_CHECKINGAnyTypeVaroverloadN)in_dynamic_mode)ParamAliasDecoratorparam_one_alias   )
functional   )Layer)Sequence)Tensor)
DataLayout1DDataLayout1DVariantDataLayout2DDataLayout3D	DTypeLikeParamAttrLike	PlaceLike	ShapeLikeSize2Size4)_DropoutMode_InterpolateMode_PaddingTensorMode
_T_Padding)ForbidKeywordsDecoratorc                    g N xns     V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/layer/common.py_npairsr'   8   s    25    c                    g r!   r"   r#   s     r&   r'   r'   <   s    *-r(   c                p    [        U [        R                  [        [        45      (       a  U $ U /US-  -  n U $ )Nr   )
isinstancepaddler   listtupler#   s     r&   r'   r'   @   s3    !fmmT5122	
q1uAHr(   c                  :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )IdentityG   a:  

A placeholder identity operator that is argument-insensitive. For each input :math:`X` ,
the output :math:`Out` is:

.. math::

    Out = X

Parameters:
    args: any argument (unused)
    kwargs: any keyword argument (unused)

Shape:
    - input: Multi-dimensional tensor with shape :math:`[batch\_size, n1, n2, ...]` .
    - output: Multi-dimensional tensor with shape :math:`[batch\_size, n1, n2, ...]` .

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(100)

        >>> input_tensor = paddle.randn(shape=[3, 2])
        >>> layer = paddle.nn.Identity()
        >>> out = layer(input_tensor)
        >>> print(input_tensor)
        Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1.41661501,  0.25904641],
         [ 0.00979547, -0.30324230],
         [-1.34256756, -0.76540256]])
        >>> print(out)
        Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1.41661501,  0.25904641],
         [ 0.00979547, -0.30324230],
         [-1.34256756, -0.76540256]])

c                "   > [         TU ]  5         g r!   super__init__)selfargskwargs	__class__s      r&   r5   Identity.__init__o   s    r(   c                    U$ r!   r"   r6   inputs     r&   forwardIdentity.forwardr   s    r(   r"   )r7   r   r8   r   returnNoner=   r   r@   r   )	__name__
__module____qualname____firstlineno____doc__r5   r>   __static_attributes____classcell__r9   s   @r&   r0   r0   G   s    %N r(   r0   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   \" 1 SkS	S
SS9   S           SU 4S jjj5       rSS jrSS jr	Sr
U =r$ )Linearv   av  

Fully-connected linear transformation layer. For each input :math:`X` ,
the equation is:

.. math::

    Out = XW + b

where :math:`W` is the weight and :math:`b` is the bias.

Linear layer takes only one multi-dimensional tensor as input with the
shape :math:`[batch\_size, *, in\_features]` , where :math:`*` means any
number of additional dimensions. It multiplies input tensor with the weight
(a 2-D tensor of shape :math:`[in\_features, out\_features]` ) and produces
an output tensor of shape :math:`[batch\_size, *, out\_features]` .
If :math:`bias\_attr` is not False, the bias (a 1-D tensor of
shape :math:`[out\_features]` ) will be created and added to the output.

Parameters:
    in_features (int): The number of input units.
    out_features (int): The number of output units.
    weight_attr (ParamAttr|None, optional): The attribute for the learnable
        weight of this layer. The default value is None. If the Initializer of the
        param_attr is not set, the parameter is initialized with Xavier.
        For detailed information, please refer to paddle.ParamAttr.
    bias_attr (ParamAttr|bool|None, optional): The attribute for the learnable bias
        of this layer. If it is set to False, no bias will be added to the output.
        If it is set to None or one kind of ParamAttr, a bias parameter will
        be created according to ParamAttr. For detailed information, please refer
        to paddle.ParamAttr. The default value is None and the bias will be
        initialized to zero.
    name (str|None, optional): Normally there is no need for user to set this parameter.
        For detailed information, please refer to :ref:`api_guide_Name` .

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

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

Shape:
    - input: Multi-dimensional tensor with shape :math:`[batch\_size, *, in\_features]` . Its data types are float16, float32, float64 ,The default is float32 .
    - output: Multi-dimensional tensor with shape :math:`[batch\_size, *, out\_features]` . The data type is the same as the input .

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(100)

        >>> # Define the linear layer.
        >>> weight_attr = paddle.ParamAttr(
        ...     name="weight",
        ...     initializer=paddle.nn.initializer.Constant(value=0.5))
        >>> bias_attr = paddle.ParamAttr(
        ...     name="bias",
        ...     initializer=paddle.nn.initializer.Constant(value=1.0))
        >>> linear = paddle.nn.Linear(2, 4, weight_attr=weight_attr, bias_attr=bias_attr)
        >>> print(linear.weight)
        Parameter containing:
        Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[0.50000000, 0.50000000, 0.50000000, 0.50000000],
         [0.50000000, 0.50000000, 0.50000000, 0.50000000]])

        >>> print(linear.bias)
        Parameter containing:
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=False,
        [1., 1., 1., 1.])

        >>> x = paddle.randn((3, 2), dtype="float32")
        >>> y = linear(x)
        >>> print(y)
        Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[ 0.42121571,  0.42121571,  0.42121571,  0.42121571],
         [ 0.85327661,  0.85327661,  0.85327661,  0.85327661],
         [-0.05398512, -0.05398512, -0.05398512, -0.05398512]])
r   weightbias
str | Nonename>   rO   dtypedevicezpaddle.nn.Linearzpaddle.compat.nn.Linearztorch.nn.Linearillegal_keys	func_namecorrect_name
url_suffixc                4  > [         TU ]  5         U R                  R                  5       U l        X0l        X@l        U R                  X/U R
                  U R                  SS9U l        U R                  U/U R                  U R                  SS9U l	        XPl
        g )NF)shapeattrrR   is_biasT)r4   r5   _helperget_default_dtype_dtype_weight_attr
_bias_attrcreate_parameterrN   rO   rQ   )r6   in_featuresout_featuresweight_attr	bias_attrrQ   r9   s         r&   r5   Linear.__init__   s     	ll446'#++-""++	 , 
 )).++	 * 
	 	r(   c                n    [         R                  " XR                  U R                  U R                  S9nU$ )N)r$   rN   rO   rQ   )FlinearrN   rO   rQ   r6   r=   outs      r&   r>   Linear.forward   s*    hhKKdiidii
 
r(   c                    U R                   (       a  SU R                    3OSnSU R                  R                  S    SU R                  R                  S    SU R                   U 3$ )N, name= zin_features=r   , out_features=r   , dtype=)rQ   rN   rZ   r_   r6   name_strs     r&   
extra_reprLinear.extra_repr   sc    ,0IIWTYYK(2dkk//23?4;;CTCTUVCWBXX`aealal`mnvmwxxr(   )ra   r_   r`   rO   rQ   rN   NNN)rc   intrd   rx   re   ParamAttrLike | Nonerf   ry   rQ   rP   r@   rA   rB   r@   strrC   rD   rE   rF   rG   __annotations__r   r5   r>   ru   rH   rI   rJ   s   @r&   rL   rL   v   s    L\ N
L
0$.$	 -1*.  *	
 (  
4y yr(   rL   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   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
$ )Upsample   a#  
This op resizes a batch of images.

The input must be a 3-D Tensor of the shape (num_batches, channels, in_w)
or (num_batches, in_w, channels), or 4-D (num_batches, channels, in_h, in_w) or
(num_batches, in_h, in_w, channels), or a 5-D Tensor of the shape
(num_batches, channels, in_d, in_h, in_w) or (num_batches, in_d, in_h, in_w, channels),
Where in_w is width of the input tensor, in_h is the height of the input tensor,
in_d is the depth of the input tensor.
and the resizing only applies on the three dimensions(depth, height and width).

Supporting resample methods:
    'linear' : Linear interpolation
    'bilinear' : Bilinear interpolation
    'trilinear' : Trilinear interpolation
    'nearest' : Nearest neighbor interpolation
    'bicubic' : Bicubic interpolation
    'area' : Area interpolation

Linear interpolation is the method of using a line connecting two known quantities
to determine the value of an unknown quantity between the two known quantities.

Nearest neighbor interpolation is to perform nearest neighbor interpolation
in both the 3rd dimension(in height direction) and the 4th dimension(in width
direction) on input tensor.

Bilinear interpolation is an extension of linear interpolation for
interpolating functions of two variables (e.g. H-direction and
W-direction in this op) on a rectilinear 2D grid. The key idea is
to perform linear interpolation first in one direction, and then
again in the other direction.

Bicubic interpolation is an extension of cubic interpolation for interpolating
data points on a two-dimensional regular grid. The interpolated surface is
smoother than corresponding surfaces obtained by bilinear interpolation or
nearest-neighbor interpolation.

Trilinear interpolation is an extension of linear interpolation for
interpolating functions of three variables (e.g. D-direction,
H-direction and W-direction in this op) on a rectilinear 3D grid.
The linear interpolation is performed on three directions.
align_corners and align_mode are optional parameters,the calculation method
of interpolation can be selected by them.

Area interpolation is to perform area interpolation
in both the 3rd dimension(in height direction) , the 4th dimension(in width
direction) and the 5th dimension(in depth direction) on input tensor. Set to
area will directly call `paddle.nn.functional.adaptive_avg_pool1d` or
`paddle.nn.functional.adaptive_avg_pool2d` or `paddle.nn.functional.adaptive_avg_pool3d`.

Example:

.. code-block:: text

    For scale_factor:
        if align_corners = True && out_size > 1 :
          scale_factor = (in_size-1.0)/(out_size-1.0)
        else:
          scale_factor = float(in_size/out_size)

    Linear interpolation:
        if:
            align_corners = False , align_mode = 0
            input : (N,C,W_in)
            output: (N,C,W_out) where:
            W_out = (W_{in}+0.5) * scale_{factor} - 0.5
        else:
            input : (N,C,W_in)
            output: (N,C,W_out) where:
            W_out = W_{in} * scale_{factor}

    Nearest neighbor interpolation:
      if:
          align_corners = False
          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = floor (H_{in} * scale_{factor})
          W_out = floor (W_{in} * scale_{factor})
      else:
          align_corners = True
          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = round(H_{in} * scale_{factor})
          W_out = round(W_{in} * scale_{factor})

    Bilinear interpolation:
      if:
          align_corners = False , align_mode = 0

          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = (H_{in}+0.5) * scale_{factor} - 0.5
          W_out = (W_{in}+0.5) * scale_{factor} - 0.5
      else:

          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = H_{in} * scale_{factor}
          W_out = W_{in} * scale_{factor}

    Bicubic interpolation:
      if:
          align_corners = False
          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = (H_{in}+0.5) * scale_{factor} - 0.5
          W_out = (W_{in}+0.5) * scale_{factor} - 0.5

      else:
          input : (N,C,H_in,W_in)
          output: (N,C,H_out,W_out) where:
          H_out = H_{in} * scale_{factor}
          W_out = W_{in} * scale_{factor}

    Trilinear interpolation:
      if:
          align_corners = False , align_mode = 0
          input : (N,C,D_in,H_in,W_in)
          output: (N,C,D_out,H_out,W_out) where:
          D_out = (D_{in}+0.5) * scale_{factor} - 0.5
          H_out = (H_{in}+0.5) * scale_{factor} - 0.5
          W_out = (W_{in}+0.5) * scale_{factor} - 0.5
      else:
          input : (N,C,D_in,H_in,W_in)
          output: (N,C,D_out,H_out,W_out) where:
          D_out = D_{in} * scale_{factor}
          H_out = H_{in} * scale_{factor}
          W_out = W_{in} * scale_{factor}

https://en.wikipedia.org/wiki/Linear_interpolation.
For details of linear interpolation, please refer to Wikipedia:

For details of nearest neighbor interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation.

For details of bilinear interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Bilinear_interpolation.

For details of bicubic interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Bicubic_interpolation

For details of trilinear interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Trilinear_interpolation.

Parameters:

    size (list|tuple|Tensor|None): Output shape of image resize
         layer, the shape is (out_w, ) when input is a 3-D Tensor, the shape is (out_h, out_w)
         when input is a 4-D Tensor and is (out_d, out_h, out_w) when input is a 5-D Tensor.
         Default: None. If a list/tuple, each element can be an integer or a Tensor of shape: [1].
         If a Tensor , its dimensions size should be a 1.
    scale_factor (float|Tensor|list|tuple|None): The multiplier for the input height or width. At
         least one of :attr:`size` or :attr:`scale_factor` must be set.
         And :attr:`size` has a higher priority than :attr:`scale_factor`. Has to match input size if it is either a list or a tuple or a Tensor.
         Default: None.
    mode (str): The resample method. It supports 'linear', 'nearest', 'bilinear', 'area',
                   'bicubic' and 'trilinear' currently. Default: 'nearest'
    align_corners(bool) :  An optional bool, If True, the centers of the 4 corner pixels of the
                           input and output tensors are aligned, preserving the values at the
                           corner pixels.
                           Default: False
    align_mode(int)  :  An optional for linear/bilinear/trilinear interpolation. Refer to the formula in the example above,
                        it can be '0' for src_idx = scale_factor*(dst_index+0.5)-0.5 , can be '1' for
                        src_idx = scale_factor*dst_index.
    data_format (str|None, optional): Specify the data format of the input, and the data format of
         the output will be consistent with that of the input. An optional string from:`"NCW"`,
         `"NWC"`,  `"NCHW"`, `"NHWC"`, `"NCDHW"`, `"NDHWC"`. The default value is None.
         When :attr:`data_format` is not specified, it will be automatically inferred from the
         input dimension of :attr:`x`. When :attr:`x` is a 3-D Tensor, :attr:`data_format` will be
         set to `"NCW"`; When :attr:`x` is a 4-D Tensor, :attr:`data_format` will be set to
         `"NCHW"`; When :attr:`x` is a 5-D Tensor, :attr:`data_format` will be set to `"NCDHW"`.
         When it is `"NCHW"`, the data should be stored in the order of:
         `[batch_size, input_channels, input_height, input_width]`. When it is `"NCDHW"`, the
         data should be stored in the order of: `[batch_size, input_channels, input_depth, input_height, input_width]`.
    recompute_scale_factor (bool, optional):  Whether to recompute the scaling factor for interpolation calculation.
         When set to `True`, the `scale_factor` parameter must be provided, and the function will use it along with
         the input tensor shape to calculate the output tensor shape, then recalculate the scaling factor based on
         the output and input tensor shapes. This parameter is particularly useful when `scale_factor` is a floating-point
         value. When set to `False`, either `size` or `scale_factor` will be used directly for interpolation without
         recalculation. Default: None.
    name(str|None, optional): The default value is None.
                         Normally there is no need for user to set this property.
                         For more information, please refer to :ref:`api_guide_Name`
Returns:
    A callable object of Upsample.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> input = paddle.rand([2, 3, 6, 10], dtype="float32")
        >>> upsample_out = paddle.nn.Upsample(size=[12, 12])

        >>> output = upsample_out(x=input)
        >>> print(output.shape)
        paddle.Size([2, 3, 12, 12])

ShapeLike | NonesizeShapeLike | float | Nonescale_factorr   modeboolalign_cornersrx   
align_mode8DataLayout1DVariant | DataLayout2D | DataLayout3D | Nonedata_formatbool | Nonerecompute_scale_factorrP   rQ   c	                   > [         T	U ]  5         Xl        X l        UR	                  5       U l        X@l        XPl        X`l        Xpl	        Xl
        g r!   )r4   r5   r   r   lowerr   r   r   r   r   rQ   )
r6   r   r   r   r   r   r   r   rQ   r9   s
            r&   r5   Upsample.__init__  sD     		(JJL	*$&&<#	r(   c                   U R                   cN  [        UR                  5      nUS:X  a  SU l         O+US:X  a  SU l         OUS:X  a  SU l         O[        SU S35      e[        R
                  " UU R                  U R                  U R                  U R                  U R                  U R                   U R                  U R                  S	9	nU$ )
N   NCW   NCHW   NCDHWz`The dimension of the input tensor should only be 3-D, 4-D or 5-D, but the received dimension is .)r   r   r   r   r   r   r   rQ   )r   lenrZ   
ValueErrorri   interpolater   r   r   r   r   r   rQ   )r6   r$   dim_sizerl   s       r&   r>   Upsample.forward  s    #177|H1}#( Q#) Q#*  vw  wA  AB  C  mm**,,((#'#>#>

 
r(   c           
        U R                   b  SU R                    3nOSU R                   3nU R                  (       a  SU R                   3OSnU SU R                   SU R                   SU R
                   SU R                   U 3
$ )	Nscale_factor=size=ro   rp   , mode=z, align_corners=z, align_mode=, data_format=)r   r   rQ   r   r   r   r   r6   main_strrt   s      r&   ru   Upsample.extra_repr  s    (&t'8'8&9:Htyyk*H,0IIWTYYK(27499+-=d>P>P=QQ^_c_n_n^oo}  C  O  O  ~P  QY  PZ  [  	[r(   )r   r   r   r   rQ   r   r   r   )NNnearestFr   NNN)r   r   r   r   r   r   r   r   r   rx   r   r   r   r   rQ   rP   r@   rA   r$   r   r@   r   rz   rC   rD   rE   rF   rG   r}   r5   r>   ru   rH   rI   rJ   s   @r&   r   r      s    FP **
OII''
 "&15!*# .2 / 	
   E !,  
 .6[ [r(   r   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'       S         SU 4S jjjr\" SS/5      SS j5       rSS jr	Sr
U =r$ )UpsamplingNearest2Di  a
  
This op upsamples a batch of images, using nearest neighbours' pixel values.
The input must be a 4-D Tensor of the shape (num_batches, channels, in_h, in_w),
where in_w is width of the input tensor, in_h is the height of the input tensor.
And the upsampling only applies on the two dimensions(height and width).
Nearest neighbor interpolation is to perform nearest neighbor interpolation
in both the 3rd dimension(in height direction) and the 4th dimension(in width
direction) on input tensor.

For details of nearest neighbor interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation.

Parameters:
    x (Tensor): 4-D Tensor, its data type is float32, float64, or uint8,
                      its data format is specified by :attr:`data_format`.
    size (int|list|tuple|Tensor|None): Output shape of image resize
         layer, the shape is (out_h, out_w) when input is a 4-D Tensor.
         Default: None. If an int value, the `out_h` and `out_w` will be set as the number.
         If a list/tuple, each element can be an integer or a Tensor of shape: [1].
         If a Tensor, its dimensions size should be a 1.
    scale_factor (float|int|list|tuple|Tensor|None): The multiplier for the input height or width. At
         least one of :attr:`size` or :attr:`scale_factor` must be set.
         And :attr:`size` has a higher priority than :attr:`scale_factor`.
         Has to match input size if it is either a list or a tuple or a Tensor.
         Default: None.
    data_format (str, optional): Specify the data format of the input, and the data format of the output
        will be consistent with that of the input. An optional string from:`NCW`, `NWC`, `"NCHW"`, `"NHWC"`, `"NCDHW"`,
        `"NDHWC"`. The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
        `[batch_size, input_channels, input_height, input_width]`. When it is `"NCHW"`, the data is stored
        in the order of: `[batch_size, input_channels, input_depth, input_height, input_width]`.
    name(str|None, optional): The default value is None.
                         Normally there is no need for user to set this property.
                         For more information, please refer to :ref:`api_guide_Name`
Returns:
    A 4-D Tensor of the shape (num_batches, channels, out_h, out_w) or (num_batches, out_h, out_w, channels),


Examples:
    .. code-block:: pycon

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

        >>> input_data = paddle.rand(shape=(2, 3, 6, 10)).astype("float32")
        >>> upsample_out = paddle.nn.UpsamplingNearest2D(size=[12, 12])
        >>> input = paddle.to_tensor(input_data)
        >>> output = upsample_out(x=input)
        >>> print(output.shape)
        paddle.Size([2, 3, 12, 12])
r   r   r   r   1DataLayout1DVariant | DataLayout2D | DataLayout3Dr   rP   rQ   c                   > [         TU ]  5         [        U[        5      (       a  X/nXl        X l        X0l        X@l        g r!   r4   r5   r+   rx   r   r   r   rQ   r6   r   r   r   rQ   r9   s        r&   r5   UpsamplingNearest2D.__init__:  :     	dC  <D	(&	r(   r$   r=   c                    [         R                  " UU R                  U R                  SSSU R                  U R
                  S9nU$ )Nr   Fr   r   r   r   r   r   r   rQ   ri   r   r   r   r   rQ   r6   r$   rl   s      r&   r>   UpsamplingNearest2D.forwardI  sC    mm**((	
 
r(   c                    U R                   b  SU R                    3nOSU R                   3nU R                  (       a  SU R                   3OSnU SU R                   U 3$ Nr   r   ro   rp   r   r   r   rQ   r   r   s      r&   ru   UpsamplingNearest2D.extra_reprX  e    (&t'8'8&9:Htyyk*H,0IIWTYYK(2>$*:*:);H:FFr(   r   rQ   r   r   NNr   N)
r   r   r   r   r   r   rQ   rP   r@   rA   r   rz   rC   rD   rE   rF   rG   r}   r5   r
   r>   ru   rH   rI   rJ   s   @r&   r   r     s    1f **BB
 "&15IO / G	
  
  c7^$ %G Gr(   r   c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'       S         SU 4S jjjr\" SS/5      SS j5       rSS jr	Sr
U =r$ )UpsamplingBilinear2Dia  aF  
This op upsamples a batch of images, using bilinear' pixel values.
The input must be a 4-D Tensor of the shape (num_batches, channels, in_h, in_w),
where in_w is width of the input tensor, in_h is the height of the input tensor.
And the upsampling only applies on the two dimensions(height and width).
Bilinear interpolation is an extension of linear interpolation for
interpolating functions of two variables (e.g. H-direction and
W-direction in this op) on a rectilinear 2D grid. The key idea is
to perform linear interpolation first in one direction, and then
again in the other direction.

For details of bilinear interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Bilinear_interpolation.

Parameters:
    x (Tensor): 4-D Tensor, its data type is float32, float64, or uint8,
                      its data format is specified by :attr:`data_format`.
    size (int|list|tuple|Tensor|None): Output shape of image resize
         layer, the shape is (out_h, out_w) when input is a 4-D Tensor.
         Default: None. If an int value, the `out_h` and `out_w` will be set as the number.
         If a list/tuple, each element can be an integer or a Tensor  of shape: [1].
         If a Tensor , its dimensions size should be a 1.
    scale_factor (float|int|list|tuple|Tensor|None): The multiplier for the input height or width. At
         least one of :attr:`size` or :attr:`scale_factor` must be set.
         And :attr:`size` has a higher priority than :attr:`scale_factor`.
         Has to match input size if it is either a list or a tuple or a Tensor.
         Default: None.
    data_format (str, optional): Specify the data format of the input, and the data format of the output
        will be consistent with that of the input. An optional string from:`NCW`, `NWC`, `"NCHW"`, `"NHWC"`, `"NCDHW"`,
        `"NDHWC"`. The default is `"NCHW"`. When it is `"NCHW"`, the data is stored in the order of:
        `[batch_size, input_channels, input_height, input_width]`. When it is `"NCHW"`, the data is stored
        in the order of: `[batch_size, input_channels, input_depth, input_height, input_width]`.
    name(str|None, optional): The default value is None.
                         Normally there is no need for user to set this property.
                         For more information, please refer to :ref:`api_guide_Name`
Returns:
    A 4-D Tensor of the shape (num_batches, channels, out_h, out_w) or (num_batches, out_h, out_w, channels),

Examples:
    .. code-block:: pycon

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

        >>> input_data = paddle.rand(shape=(2, 3, 6, 10)).astype("float32")
        >>> upsample_out = paddle.nn.UpsamplingBilinear2D(size=[12, 12])
        >>> input = paddle.to_tensor(input_data)
        >>> output = upsample_out(x=input)
        >>> print(output.shape)
        paddle.Size([2, 3, 12, 12])
r   r   ShapeLike | floatr   r   r   rP   rQ   c                   > [         TU ]  5         [        U[        5      (       a  X/nXl        X l        X0l        X@l        g r!   r   r   s        r&   r5   UpsamplingBilinear2D.__init__  r   r(   r$   r=   c                    [         R                  " UU R                  U R                  SSSU R                  U R
                  S9nU$ )NbilinearTr   r   r   r   s      r&   r>   UpsamplingBilinear2D.forward  sC    mm**((	
 
r(   c                    U R                   b  SU R                    3nOSU R                   3nU R                  (       a  SU R                   3OSnU SU R                   U 3$ r   r   r   s      r&   ru   UpsamplingBilinear2D.extra_repr  r   r(   r   r   )
r   r   r   r   r   r   rQ   rP   r@   rA   r   rz   r   rJ   s   @r&   r   r   a  s    2h ##BB
 "&*.IO ( G	
  
  c7^$ %G Gr(   r   c                  ~   ^  \ rS 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
$ )Bilineari  ai  

This layer performs bilinear on two inputs.

.. math::

  out_{i} = x1 * W_{i} * {x2^\mathrm{T}}, i=0,1,...,out_features-1

  out = out + b

In this formula:
 - :math:`x1`: the first input contains in1_features elements, shape is [batch_size, in1_features].
 - :math:`x2`: the second input contains in2_features elements, shape is [batch_size, in2_features].
 - :math:`W_{i}`: the i-th learned weight, shape is [in1_features, in2_features], and learned weight's shape is [out_features, in1_features, in2_features].
 - :math:`out_{i}`: the i-th element of out, shape is [batch_size], and out's shape is [batch_size, out_features].
 - :math:`b`: the learned bias, shape is [1, out_features].
 - :math:`x2^\mathrm{T}`: the transpose of :math:`x2`.

Parameters:
   in1_features (int): The dimension of each first input(`x1`).
   in2_features (int): The dimension of each second input(`x2`).
   out_features (int): The dimension of output of this layer.
   weight_attr (ParamAttr|None, optional): The parameter attribute for the learnable w, parameters/weights of
   this layer. The default value is None.
   bias_attr (ParamAttr|bool|None, optional): The parameter attribute for the bias
       of this layer. If it is set to False, no bias will be added to the output units.
       If it is set to None, the bias is initialized zero. The default value is None.
   name (str|None, optional): The default value is None. Normally there is no need for user
       to set this property. For more information, please refer to :ref:`api_guide_Name`. Default: None.

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

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

Returns:
   Tensor: A 2-D Tensor of shape [batch_size, out_features].

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> layer1 = paddle.rand((5, 5)).astype('float32')
        >>> layer2 = paddle.rand((5, 4)).astype('float32')
        >>> bilinear = paddle.nn.Bilinear(in1_features=5, in2_features=4, out_features=1000)

        >>> result = bilinear(layer1, layer2)
        >>> print(result.shape)
        paddle.Size([5, 1000])

r   rN   rO   c                  > [         T	U ]  5         X@l        XPl        X`l        Xl        X l        X0l        U R                  R                  5       U l
        U R                  U R
                  U R                  /nU R                  U R                  UU R                  SS9U l        SU R                  /nU R                  U R                  UU R                  SS9U l        g )NF)r[   rZ   rR   r\   r   T)r4   r5   r`   ra   _name_in1_features_in2_features_out_featuresr]   r^   r_   rb   rN   rO   )
r6   in1_featuresin2_featuresrd   re   rf   rQ   weight_shape
bias_shaper9   s
            r&   r5   Bilinear.__init__  s     	'#
)))ll446 

 ++""++	 , 
 ++,
))++	 * 
	r(   c                p    [         R                  " XU R                  U R                  U R                  5      $ r!   )ri   r   rN   rO   r   r6   x1x2s      r&   r>   Bilinear.forward   s#    zz"$++tyy$**EEr(   c           	         U R                   (       a  SU R                    3OSnSU R                   SU R                   SU R                   SU R                   U 3	$ )Nro   rp   zin1_features=z, in2_features=rq   rr   )r   r   r   r   r_   rs   s     r&   ru   Bilinear.extra_repr#  s    -1ZZWTZZL)Rt112/$BTBTAUUdeiewewdx  yA  BF  BM  BM  AN  OW  NX  Y  	Yr(   )	ra   r_   r   r   r   r   r`   rO   rN   rw   )r   rx   r   rx   rd   rx   re   ry   rf   ry   rQ   rP   r@   rA   r   r   r   r   r@   r   rz   r   rJ   s   @r&   r   r     s    3j N
L -1*.#
#
 #
 	#

 *#
 (#
 #
 
#
 #
JFY Yr(   r   c                     ^  \ rS rSr% SrS\S'   S\S'   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
$ )Dropouti(  a@	  
Dropout is a regularization technique for reducing overfitting by preventing
neuron co-adaption during training as described in the paper:
`Improving neural networks by preventing co-adaptation of feature detectors <https://arxiv.org/abs/1207.0580>`_
The dropout operator randomly sets the outputs of some units to zero, while upscale others
according to the given dropout probability.

See :ref:`api_paddle_nn_functional_dropout` for more details.

In dygraph mode, please use ``eval()`` to switch to evaluation mode, where dropout is disabled.

Warning:
    The corresponding `functional methods` please reference :ref:`api_paddle_nn_functional_dropout`.

Parameters:
    p (float|int, optional): Probability of setting units to zero. Default: 0.5
    inplace (bool, optional): If set to ``True``, will do this operation in-place. Default: ``False``
    axis (int|list|tuple|None, optional): The axis along which the dropout is performed. Default: None.
    mode(str, optional): ['upscale_in_train'(default) | 'downscale_in_infer']

                           1. upscale_in_train (default), upscale the output at training time

                              - train: :math:`out = input \times \frac{mask}{(1.0 - p)}`
                              - inference: :math:`out = input`

                           2. downscale_in_infer, downscale the output at inference

                              - train: :math:`out = input \times mask`
                              - inference: :math:`out = input \times (1.0 - p)`
    name (str|None, optional): Name for the operation, Default: None. For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - input: N-D tensor.
    - output: N-D tensor, the same shape as input.


Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype="float32")
        >>> m = paddle.nn.Dropout(p=0.5)

        >>> y_train = m(x)
        >>> print(y_train)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[2., 4., 0.],
         [8., 0., 0.]])

        >>> m.eval()  # switch the model to test phase
        >>> y_test = m(x)
        >>> print(y_test)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[1., 2., 3.],
         [4., 5., 6.]])
floatpint | Sequence[int] | Noneaxisr   r   rP   rQ   c                ^   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        g r!   )r4   r5   r   inplacer   r   rQ   )r6   r   r   r   r   rQ   r9   s         r&   r5   Dropout.__init__i  s)     				r(   c           
         [         R                  " UU R                  U R                  U R                  U R
                  U R                  U R                  S9nU$ )N)r   r   trainingr   r   rQ   )ri   dropoutr   r   r   r   r   rQ   rk   s      r&   r>   Dropout.forwardy  sD    iiff]]LL
 
r(   c           	         U R                   (       a  SU R                    3OSnSU R                   SU R                   SU R                   U SU R                   3	$ )Nro   rp   p=z, axis=r   z
, inplace=)rQ   r   r   r   r   rs   s     r&   ru   Dropout.extra_repr  sQ    ,0IIWTYYK(2DFF87499+WTYYKzTXT`T`Sabbr(   )r   r   r   rQ   r   )      ?FNupscale_in_trainN)r   r   r   r   r   r   r   r   rQ   rP   r@   rA   rB   rz   r   rJ   s   @r&   r   r   (  s    9v H
$$

 +//  )	
   
  
c cr(   r   c                  |   ^  \ rS rSr% SrS\S'   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
$ )	Dropout2Di  a	  
Randomly zero out entire channels (in the batched input 4d tensor with the shape `NCHW` ,
a channel is a 2D feature map with the shape `HW`). Each channel will be zeroed out independently
on every forward call with probability `p` using samples from a Bernoulli distribution.
Dropout2D will help promote independence between feature maps as described in the paper:
`Efficient Object Localization Using Convolutional Networks <https://arxiv.org/abs/1411.4280>`_

See :ref:`api_paddle_nn_functional_dropout2d` for more details.

In dygraph mode, please use ``eval()`` to switch to evaluation mode, where dropout is disabled.

Parameters:
    p (float, optional): Probability of setting units to zero. Default: 0.5.
    data_format (str, optional): Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from `NCHW` or `NHWC`. 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): Name for the operation, Default: None. For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - input: 4-D tensor.
    - output: 4-D tensor, the same shape as input.


Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(100)
        >>> x = paddle.rand([2, 2, 1, 3], dtype="float32")
        >>> print(x)
        Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0.55355281, 0.20714243, 0.01162981]],
          [[0.51577556, 0.36369765, 0.26091650]]],
         [[[0.18905126, 0.56219709, 0.00808361]],
          [[0.78120756, 0.32112977, 0.90572405]]]])

        >>> m = paddle.nn.Dropout2D(p=0.5)
        >>> y_train = m(x)
        >>> print(y_train)
        Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[1.10710561, 0.41428486, 0.02325963]],
          [[1.03155112, 0.72739530, 0.52183300]]],
         [[[0.        , 0.        , 0.        ]],
          [[0.        , 0.        , 0.        ]]]])

        >>> m.eval()  # switch the model to test phase
        >>> y_test = m(x)
        >>> print(y_test)
        Tensor(shape=[2, 2, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0.55355281, 0.20714243, 0.01162981]],
          [[0.51577556, 0.36369765, 0.26091650]]],
         [[[0.18905126, 0.56219709, 0.00808361]],
          [[0.78120756, 0.32112977, 0.90572405]]]])
r   r   r   r   rP   rQ   c                F   > [         TU ]  5         Xl        X l        X0l        g r!   r4   r5   r   r   rQ   r6   r   r   rQ   r9   s       r&   r5   Dropout2D.__init__        	&	r(   c                    [         R                  " UU R                  U R                  U R                  U R
                  S9nU$ N)r   r   r   rQ   )ri   	dropout2dr   r   r   rQ   rk   s      r&   r>   Dropout2D.forward  8    kkff]]((
 
r(   c                    U R                   (       a  SU R                    3OSnSU R                   SU R                   U 3$ Nro   rp   r   r   rQ   r   r   rs   s     r&   ru   Dropout2D.extra_repr  <    ,0IIWTYYK(2DFF8>$*:*:);H:FFr(   r   rQ   r   )r   r   N)r   r   r   r   rQ   rP   r@   rA   rB   rz   r   rJ   s   @r&   r   r     sh    3j H
 $*	

 "
 	

 

 
G Gr(   r   c                  |   ^  \ rS rSr% SrS\S'   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
$ )	Dropout3Di  a  
Randomly zero out entire channels (in the batched input 5d tensor with the shape `NCDHW` ,
a channel is a 3D feature map with the shape `DHW` ). Each channel will be zeroed out independently
on every forward call with probability `p` using samples from a Bernoulli distribution.
Dropout3D will help promote independence between feature maps as described in the paper:
`Efficient Object Localization Using Convolutional Networks <https://arxiv.org/abs/1411.4280>`_

See :ref:`api_paddle_nn_functional_dropout3d` for more details.

In dygraph mode, please use ``eval()`` to switch to evaluation mode, where dropout is disabled.

Parameters:
    p (float|int, optional): Probability of setting units to zero. Default: 0.5.
    data_format (str, optional): Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from `NCDHW` or `NDHWC`. When it is `NCDHW`, the data is stored in the order of: [batch_size, input_channels, input_depth, input_height, input_width]. Default: `NCDHW`.
    name (str|None, optional): Name for the operation, Default: None. For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - input: 5-D tensor.
    - output: 5-D tensor, the same shape as input.


Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.arange(24, dtype="float32").reshape((1, 2, 2, 2, 3))
        >>> print(x)
        Tensor(shape=[1, 2, 2, 2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[0. , 1. , 2. ],
            [3. , 4. , 5. ]],
           [[6. , 7. , 8. ],
            [9. , 10., 11.]]],
          [[[12., 13., 14.],
            [15., 16., 17.]],
           [[18., 19., 20.],
            [21., 22., 23.]]]]])

        >>> m = paddle.nn.Dropout3D(p=0.5)
        >>> y_train = m(x)

        >>> m.eval()  # switch the model to test phase
        >>> y_test = m(x)
        >>> print(y_test)
        Tensor(shape=[1, 2, 2, 2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[0. , 1. , 2. ],
            [3. , 4. , 5. ]],
           [[6. , 7. , 8. ],
            [9. , 10., 11.]]],
          [[[12., 13., 14.],
            [15., 16., 17.]],
           [[18., 19., 20.],
            [21., 22., 23.]]]]])
r   r   r   r   rP   rQ   c                F   > [         TU ]  5         Xl        X l        X0l        g r!   r   r   s       r&   r5   Dropout3D.__init__  r   r(   c                    [         R                  " UU R                  U R                  U R                  U R
                  S9nU$ r   )ri   	dropout3dr   r   r   rQ   rk   s      r&   r>   Dropout3D.forward'  r   r(   c                    U R                   (       a  SU R                    3OSnSU R                   SU R                   U 3$ r   r   rs   s     r&   ru   Dropout3D.extra_repr1  r   r(   r   )r   r   N)r   r   r   r   rQ   rP   r@   rA   rB   rz   r   rJ   s   @r&   r   r     sh    5n H
 $+	

 "
 	

 

 
G Gr(   r   c                  ^   ^  \ rS 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
$ )AlphaDropouti6  a  
Alpha Dropout is a type of Dropout that maintains the self-normalizing property. For an input with
zero mean and unit standard deviation, the output of Alpha Dropout maintains the original mean and
standard deviation of the input. Alpha Dropout fits well to SELU activate function by randomly setting
activations to the negative saturation value.

For more information, please refer to:
`Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_

In dygraph mode, please use ``eval()`` to switch to evaluation mode, where dropout is disabled.

Parameters:
    p (float|int, optional): Probability of setting units to zero. Default: 0.5
    name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - input: N-D tensor.
    - output: N-D tensor, the same shape as input.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> x = paddle.to_tensor([[-1, 1], [-1, 1]], dtype="float32")
        >>> m = paddle.nn.AlphaDropout(p=0.5)
        >>> y_train = m(x)
        >>> print(y_train)
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-0.10721093,  1.66559887],
         [-0.77919382,  1.66559887]])

        >>> m.eval()  # switch the model to test phase
        >>> y_test = m(x)
        >>> print(y_test)
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1.,  1.],
         [-1.,  1.]])
r   r   rP   rQ   c                :   > [         TU ]  5         Xl        X l        g r!   r4   r5   r   rQ   r6   r   rQ   r9   s      r&   r5   AlphaDropout.__init__c      	r(   c                n    [         R                  " XR                  U R                  U R                  S9nU$ N)r   r   rQ   )ri   alpha_dropoutr   r   rQ   rk   s      r&   r>   AlphaDropout.forwardh  s*    ooVVdmm$))
 
r(   c                h    U R                   (       a  SU R                    3OSnSU R                   U 3$ Nro   rp   r   rQ   r   rs   s     r&   ru   AlphaDropout.extra_reprn  /    ,0IIWTYYK(2DFF8H:&&r(   r  r   Nr   r   rQ   rP   r@   rA   rB   rz   r   rJ   s   @r&   r	  r	  6  s/    'R H
 
' 'r(   r	  c                  ^   ^  \ rS 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
$ )FeatureAlphaDropoutis  a^  
A channel is a feature map, Feature Alpha Dropout randomly masks out entire channels.
Alpha Dropout is a type of Dropout that maintains the self-normalizing property. For an input with
zero mean and unit standard deviation, the output of Alpha Dropout maintains the original mean and
standard deviation of the input. Alpha Dropout fits well to SELU activate function by randomly setting
activations to the negative saturation value.

For more information, please refer to:
`Self-Normalizing Neural Networks <https://arxiv.org/abs/1706.02515>`_

In dygraph mode, please use ``eval()`` to switch to evaluation mode, where dropout is disabled.

Parameters:
    p (float | int, optional): Probability of setting units to zero. Default: 0.5
    name (str | None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - input: N-D tensor.
    - output: N-D tensor, the same shape as input.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> x = paddle.to_tensor([[-1, 1], [-1, 1]], dtype="float32")
        >>> m = paddle.nn.FeatureAlphaDropout(p=0.5)
        >>> y_train = m(x)
        >>> print(y_train)
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-0.10721093,  1.66559887],
         [-0.77919382,  1.66559887]])

        >>> m.eval()  # switch the model to test phase
        >>> y_test = m(x)
        >>> print(y_test)
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1.,  1.],
         [-1.,  1.]])
r   r   rP   rQ   c                :   > [         TU ]  5         Xl        X l        g r!   r  r  s      r&   r5   FeatureAlphaDropout.__init__  r  r(   c                n    [         R                  " XR                  U R                  U R                  S9nU$ r  )ri   feature_alpha_dropoutr   r   rQ   rk   s      r&   r>   FeatureAlphaDropout.forward  s,    %%VVdmm$))
 
r(   c                h    U R                   (       a  SU R                    3OSnSU R                   U 3$ r  r  rs   s     r&   ru   FeatureAlphaDropout.extra_repr  r  r(   r  r  r  rB   rz   r   rJ   s   @r&   r  r  s  s/    (T H
 
' 'r(   r  c                     ^  \ rS rSrSr    S	           S
U 4S jjjr\" SS/5      SS j5       rSS jrSr	U =r
$ )_PadnDi  r   c                   > [         TU ]  5         [        XR                  5      U l        X l        X0l        UU l        XPl        g r!   )	r4   r5   r'   _n_dimpadding_modevalue_data_formatr   r6   r'  r   r)  r   rQ   r9   s         r&   r5   _PadnD.__init__  s<     	w4)-

 	 
r(   r$   r=   c           	         [         R                  " UU R                  U R                  U R                  U R
                  U R                  S9$ )N)padr   r)  r   rQ   )ri   r.  r'  r(  r)  r*  r   r6   r$   s     r&   r>   _PadnD.forward  s;    uu**))
 	
r(   c           	         U R                   (       a  SU R                    3OSnSU R                   SU R                   SU R                   SU R                   U 3	$ )Nro   rp   zpadding=r   z, value=r   )r   r'  r(  r)  r*  rs   s     r&   ru   _PadnD.extra_repr  sS    -1ZZWTZZL)R$,,wtzzl(4::,n]a]n]n\opxoyzzr(   )r*  r(  r   r'  r)  constant        NCLN)r'  Tensor | Sequence[int] | intr   r   r)  r   r   z*DataLayout1D | DataLayout2D | DataLayout3DrQ   rP   r@   rA   r   rz   )rC   rD   rE   rF   r&  r5   r
   r>   ru   rH   rI   rJ   s   @r&   r$  r$    s    F
 $.BG- ! 	
 @  
 " c7^$
 %
{ {r(   r$  c                  R   ^  \ rS rSrSr    S           SU 4S jjjrSrU =r$ )Pad1Di  af  
This interface is used to construct a callable object of the ``Pad1D`` class.
Pad tensor according to ``pad``, ``mode`` and ``value``.
If mode is ``reflect``, pad[0] and pad[1] must be no greater than width-1.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
    mode (str, optional): Four modes: ``'constant'`` (default), ``'reflect'``, ``'replicate'``, ``'circular'``. Default: ``'constant'``.
       - 'constant' mode, uses a constant value to pad the input tensor.
       - 'reflect' mode, uses reflection of the input boundaries to pad the input tensor.
       - 'replicate' mode, uses input boundaries to pad the input tensor.
       - 'circular' mode, uses circular input to pad the input tensor.

    value (float, optional): The value to fill the padded areas. Default is :math:`0.0`.
    data_format (str, optional): An string from: ``'NCL'``, ``'NLC'``. Specify the data format of the input data.
       Default: ``'NCL'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Returns:
    Tensor: The padded tensor.

Examples:
    .. code-block:: python

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

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.Pad1D(padding=pad, mode="constant")
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[0., 1., 2., 3., 0., 0.],
          [0., 4., 5., 6., 0., 0.]]])
c                (   > [         TU ]  XX4U5        g r!   r3   r+  s         r&   r5   Pad1D.__init__       	DAr(   r"   r3  )r'  r7  r   r   r)  r   r   r   rQ   rP   r@   rA   rC   rD   rE   rF   rG   r5   rH   rI   rJ   s   @r&   r9  r9    sc    &V $.$)B-B !B 	B
 "B B 
B Br(   r9  c                  J   ^  \ rS rSrSr  S         SU 4S jjjrSrU =r$ )ConstantPad1Di	  a]  
This interface is used to construct a callable object of the ``ConstantPad1D`` class.
Pads the input tensor boundaries with a constant value.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
    value (float): The value to fill the padded areas.
    data_format (str, optional): An string from: ``'NCL'``, ``'NLC'``. Specify the data format of the input data.
        Default: ``'NCL'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Shape:
    - x(Tensor): The input tensor of constantpad1d operator, which is a 3-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of constantpad1d operator, which is a 3-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ConstantPad1D(padding=pad, value=0.5)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[0.5, 1. , 2. , 3. , 0.5, 0.5],
          [0.5, 4. , 5. , 6. , 0.5, 0.5]]])
c                *   > [         TU ]  USX#U5        g Nr4  r3   r6   r'  r)  r   rQ   r9   s        r&   r5   ConstantPad1D.__init__2       	*e$Gr(   r"   r6  N)
r'  r7  r)  r   r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   r?  r?  	  sR    &X %*H-H H "	H
 H 
H Hr(   r?  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReplicationPad1Di<  a  
This interface is used to construct a callable object of the ``ReplicationPad1D`` class.
Pads the input tensor boundaries by replicating the edge values.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
    data_format (str|None): An string from: "NCL", "NLC". Specify the data format of the input data.
        Default: ``"NCL"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of replicationpad1d operator, which is a 3-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of replicationpad1d operator, which is a 3-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from replication_padding_layers import ReplicationPad1D

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ReplicationPad1D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[1., 1., 2., 3., 3., 3.],
          [4., 4., 5., 6., 6., 6.]]])
c                *   > [         TU ]  USSX#5        g N	replicater5  r3   r6   r'  r   rQ   r9   s       r&   r5   ReplicationPad1D.__init__f       	+sKFr(   r"   rE  r'  r7  r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   rG  rG  <  sG    'X %*	G-G "G 	G
 
G Gr(   rG  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReflectionPad1Dio  a  
This interface is used to construct a callable object of the ``ReflectionPad1D`` class.
Pads the input tensor boundaries using reflection of the input boundaries.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
        Padding width must be less than the corresponding input dimension.
    data_format (str|None): An string from: "NCL", "NLC". Specify the data format of the input data.
        Default: ``"NCL"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of reflectionpad1d operator, which is a 3-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of reflectionpad1d operator, which is a 3-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from reflection_padding_layers import ReflectionPad1D

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data = [[[1., 2., 3.], [4., 5., 6.]]]
        >>> my_pad = nn.ReflectionPad1D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[2., 1., 2., 3., 2., 1.],
          [5., 4., 5., 6., 5., 4.]]])
c                *   > [         TU ]  USSX#5        g Nreflectr5  r3   rK  s       r&   r5   ReflectionPad1D.__init__       	)S+Dr(   r"   rE  rN  r=  rJ   s   @r&   rP  rP  o  sG    )\ %*	E-E "E 	E
 
E Er(   rP  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )	ZeroPad1Di  a  
This interface is used to construct a callable object of the ``ZeroPad1D`` class.
Pads the input tensor boundaries with zero.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
    data_format (str|None): An string from: "NCL", "NLC". Specify the data format of the input data.
       Default: ``"NCL"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of zeropad1d operator, which is a 3-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of zeropad1d operator, which is a 3-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ZeroPad1D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[0., 1., 2., 3., 0., 0.],
          [0., 4., 5., 6., 0., 0.]]])
c                *   > [         TU ]  USSX#5        g Nr4  r5  r3   rK  s       r&   r5   ZeroPad1D.__init__       	*c;Er(   r"   rE  rN  r=  rJ   s   @r&   rW  rW    sG    &V %*	F-F "F 	F
 
F Fr(   rW  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )CircularPad1Di  af  
This interface is used to construct a callable object of the ``CircularPad1D`` class.
Pads the input tensor boundaries by circular padding.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to both the left and right side.
        If `padding` is a list or tuple of two ints, it is interpreted as `(pad_left, pad_right)`.
    data_format (str|None): An string from: "NCL", "NLC". Specify the data format of the input data.
        Default: ``"NCL"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of circularpad1d operator, which is a 3-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of circularpad1d operator, which is a 3-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 2, 3)
        >>> pad = [1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data is [[[1., 2., 3.], [4., 5., 6.]]]
        >>> my_pad = nn.CircularPad1D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[3., 1., 2., 3., 1., 2.],
          [6., 4., 5., 6., 4., 5.]]])
c                *   > [         TU ]  USSX#5        g Ncircularr5  r3   rK  s       r&   r5   CircularPad1D.__init__   r[  r(   r"   rE  rN  r=  rJ   s   @r&   r]  r]    sG    'X %*	F-F "F 	F
 
F Fr(   r]  c                  V   ^  \ rS rSrSrSr    S           SU 4S jjjrSrU =r$ )Pad2Di	  a  
This interface is used to construct a callable object of the ``Pad2D`` class.
Pad tensor according to ``pad``, ``mode`` and ``value``.
If mode is ``'reflect'``, pad[0] and pad[1] must be no greater
than width-1. The height dimension has the same condition.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as `(pad_left, pad_right, pad_top, pad_bottom)`.
    mode (str, optional): Four modes: ``'constant'`` (default), ``'reflect'``, ``'replicate'``, ``'circular'``. Default: ``'constant'``.

       - 'constant' mode, uses a constant value to pad the input tensor.
       - 'reflect' mode, uses reflection of the input boundaries to pad the input tensor.
       - 'replicate' mode, uses input boundaries to pad the input tensor.
       - 'circular' mode, uses circular input to pad the input tensor.

    value (float, optional): The value to fill the padded areas. Default is :math:`0.0`.
    data_format (str, optional): An string from: ``'NCHW'``, ``'NHWC'``. Specify the data format of the input data.
       Default: ``'NCHW'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Returns:
    Tensor: The padded tensor.

Examples:
    .. code-block:: python

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

        >>> input_shape = (1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.Pad2D(padding=pad, mode="constant")
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0., 0., 0., 0.],
           [0., 1., 2., 3.],
           [0., 4., 5., 6.],
           [0., 0., 0., 0.],
           [0., 0., 0., 0.]]]])
r   c                (   > [         TU ]  XX4U5        g r!   r3   r+  s         r&   r5   Pad2D.__init__9  r<  r(   r"   )r4  r5  r   N)r'  r7  r   r   r)  r   r   r   rQ   rP   r@   rA   	rC   rD   rE   rF   rG   r&  r5   rH   rI   rJ   s   @r&   rc  rc  	  sj    +Z F
 $.$*B-B !B 	B
 "B B 
B Br(   rc  c                  J   ^  \ rS rSrSr  S         SU 4S jjjrSrU =r$ )ConstantPad2DiD  a  
This interface is used to construct a callable object of the ``ConstantPad2D`` class.
Pads the input tensor boundaries with a constant value.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as `(pad_left, pad_right, pad_top, pad_bottom)`.
    value (float): The value to fill the padded areas.
    data_format (str, optional): An string from: ``'NCHW'``, ``'NHWC'``. Specify the data format of the input data.
        Default: ``'NCHW'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Shape:
    - x(Tensor): The input tensor of constantpad2d operator, which is a 4-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of constantpad2d operator, which is a 4-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ConstantPad2D(padding=pad, value=0.5)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0.5, 0.5, 0.5, 0.5],
           [0.5, 1. , 2. , 3. ],
           [0.5, 4. , 5. , 6. ],
           [0.5, 0.5, 0.5, 0.5],
           [0.5, 0.5, 0.5, 0.5]]]])
c                *   > [         TU ]  USX#U5        g rA  r3   rB  s        r&   r5   ConstantPad2D.__init__p  rD  r(   r"   r   N)
r'  r7  r)  r   r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   rh  rh  D  sR    )^ %+H-H H "	H
 H 
H Hr(   rh  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReplicationPad2Diz  a
  
This interface is used to construct a callable object of the ``ReplicationPad2D`` class.
Pads the input tensor boundaries by replicating the edge values.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as `(pad_left, pad_right, pad_top, pad_bottom)`.
    data_format (str|None): An string from: "NCHW", "NHWC". Specify the data format of the input data.
        Default: ``"NCHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of replicationpad2d operator, which is a 4-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of replicationpad2d operator, which is a 4-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from replication_padding_layers import ReplicationPad2D

        >>> input_shape = (1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ReplicationPad2D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[1., 1., 2., 3.],
           [1., 1., 2., 3.],
           [4., 4., 5., 6.],
           [4., 4., 5., 6.],
           [4., 4., 5., 6.]]]])
c                *   > [         TU ]  USSX#5        g rI  r3   rK  s       r&   r5   ReplicationPad2D.__init__  rM  r(   r"   rk  r'  r7  r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   rm  rm  z  sG    *^ %+	G-G "G 	G
 
G Gr(   rm  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReflectionPad2Di  a  
This interface is used to construct a callable object of the ``ReflectionPad2D`` class.
Pads the input tensor boundaries using reflection of the input boundaries.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as `(pad_left, pad_right, pad_top, pad_bottom)`.
        Padding width must be less than the corresponding input dimension.
    data_format (str|None): An string from: "NCHW", "NHWC". Specify the data format of the input data.
        Default: ``"NCHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of reflectionpad2d operator, which is a 4-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of reflectionpad2d operator, which is a 4-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from reflection_padding_layers import ReflectionPad2D

        >>> input_shape = (1, 1, 2, 3)
        >>> pad = [1, 0, 1, 1] # L=1, R=0, T=1, B=1
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data = [[[[1., 2., 3.], [4., 5., 6.]]]]
        >>> my_pad = nn.ReflectionPad2D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
            Tensor(shape=[1, 1, 4, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
                [[[[5., 4., 5., 6.],
                    [2., 1., 2., 3.],
                    [5., 4., 5., 6.],
                    [2., 1., 2., 3.]]]])
c                *   > [         TU ]  USSX#5        g rR  r3   rK  s       r&   r5   ReflectionPad2D.__init__  rU  r(   r"   rk  rp  r=  rJ   s   @r&   rr  rr    sG    +` %+	E-E "E 	E
 
E Er(   rr  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )	ZeroPad2Di  a  
This interface is used to construct a callable object of the ``ZeroPad2D`` class.
Pads the input tensor boundaries with zero.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as `(pad_left, pad_right, pad_top, pad_bottom)`.
    data_format (str|None): An string from: "NCHW", "NHWC". Specify the data format of the input data.
       Default: ``"NCHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of zeropad2d operator, which is a 4-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of zeropad2d operator, which is a 4-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = paddle.to_tensor([1, 1, 2, 3])
        >>> pad = [1, 0, 1, 2]
        >>> data = paddle.arange(paddle.prod(input_shape), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ZeroPad2D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0., 0., 0., 0.],
           [0., 1., 2., 3.],
           [0., 4., 5., 6.],
           [0., 0., 0., 0.],
           [0., 0., 0., 0.]]]])
c                *   > [         TU ]  USSX#5        g rY  r3   rK  s       r&   r5   ZeroPad2D.__init__  r[  r(   r"   rk  rp  r=  rJ   s   @r&   rv  rv    sG    )\ %+	F-F "F 	F
 
F Fr(   rv  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )CircularPad2Di  a  
This interface is used to construct a callable object of the ``CircularPad2D`` class.
Pads the input tensor boundaries by circular padding.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all four sides (left, right, top, bottom).
        If `padding` is a list or tuple of four ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom)`.
    data_format (str|None): An string from: "NCHW", "NHWC". Specify the data format of the input data.
        Default: ``"NCHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of circularpad2d operator, which is a 4-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of circularpad2d operator, which is a 4-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2] # (L, R, T, B)
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data is [[[[1., 2., 3.],
        >>> #           [4., 5., 6.]]]]
        >>> my_pad = nn.CircularPad2D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[6., 4., 5., 6.],
           [3., 1., 2., 3.],
           [6., 4., 5., 6.],
           [3., 1., 2., 3.],
           [6., 4., 5., 6.]]]])
c                *   > [         TU ]  USSX#5        g r_  r3   rK  s       r&   r5   CircularPad2D.__init__K  r[  r(   r"   rk  rp  r=  rJ   s   @r&   rz  rz    sG    ,b %+	F-F "F 	F
 
F Fr(   rz  c                  V   ^  \ rS rSrSrSr    S           SU 4S jjjrSrU =r$ )Pad3DiT  a`  
This interface is used to construct a callable object of the ``Pad3D`` class.
Pad tensor according to ``'pad'``, ``'mode'`` and ``'value'``.
If mode is ``'reflect'``, pad[0] and pad[1] must be no greater
than width-1. The height and depth dimension has the same condition.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
    mode (str, optional): Four modes: ``'constant'`` (default), ``'reflect'``, ``'replicate'``, ``'circular'``. Default: ``'constant'``.

       - 'constant' mode, uses a constant value to pad the input tensor.
       - 'reflect' mode, uses reflection of the input boundaries to pad the input tensor.
       - 'replicate' mode, uses input boundaries to pad the input tensor.
       - 'circular' mode, uses circular input to pad the input tensor.

    value (float, optional): The value to fill the padded areas. Default is :math:`0.0`.
    data_format (str, optional): An string from: ``'NCDHW'``, ``'NDHWC'``. Specify the data format of the input data.
       Default:  ``'NCDHW'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Returns:
    Tensor: The padded tensor.

Examples:
    .. code-block:: python

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

        >>> input_shape = (1, 1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2, 0, 0]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.Pad3D(padding=pad, mode="constant")
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[0., 0., 0., 0.],
            [0., 1., 2., 3.],
            [0., 4., 5., 6.],
            [0., 0., 0., 0.],
            [0., 0., 0., 0.]]]]])
r   c                (   > [         TU ]  XX4U5        g r!   r3   r+  s         r&   r5   Pad3D.__init__  r<  r(   r"   )r4  r5  r   N)r'  r7  r   r   r)  r   r   r   rQ   rP   r@   rA   rf  rJ   s   @r&   r~  r~  T  sj    ,\ F
 $.$+B-B !B 	B
 "B B 
B Br(   r~  c                  J   ^  \ rS rSrSr  S         SU 4S jjjrSrU =r$ )ConstantPad3Di  a  
This interface is used to construct a callable object of the ``ConstantPad3D`` class.
Pads the input tensor boundaries with a constant value.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
    value (float): The value to fill the padded areas.
    data_format (str, optional): An string from: ``'NCDHW'``, ``'NDHWC'``. Specify the data format of the input data.
        Default: ``'NCDHW'``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``None``.

Shape:
    - x(Tensor): The input tensor of constantpad3d operator, which is a 5-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of constantpad3d operator, which is a 5-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2, 0, 0]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ConstantPad3D(padding=pad, value=0.5)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[0.5, 0.5, 0.5, 0.5],
           [0.5, 1. , 2. , 3. ],
           [0.5, 4. , 5. , 6. ],
           [0.5, 0.5, 0.5, 0.5],
           [0.5, 0.5, 0.5, 0.5]]]]])
c                *   > [         TU ]  USX#U5        g rA  r3   rB  s        r&   r5   ConstantPad3D.__init__  rD  r(   r"   r   N)
r'  r7  r)  r   r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   r  r    sR    *` %,H-H H "	H
 H 
H Hr(   r  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReplicationPad3Di  aC  
This interface is used to construct a callable object of the ``ReplicationPad3D`` class.
Pads the input tensor boundaries by replicating the edge values.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
    data_format (str|None): An string from: "NCDHW", "NDHWC". Specify the data format of the input data.
        Default: ``"NCDHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of replicationpad3d operator, which is a 5-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of replicationpad3d operator, which is a 5-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from replication_padding_layers import ReplicationPad3D

        >>> input_shape = (1, 1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2, 0, 0]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ReplicationPad3D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[1., 1., 2., 3.],
           [1., 1., 2., 3.],
           [4., 4., 5., 6.],
           [4., 4., 5., 6.],
           [4., 4., 5., 6.]]]]])
c                *   > [         TU ]  USSX#5        g rI  r3   rK  s       r&   r5   ReplicationPad3D.__init__  rM  r(   r"   r  r'  r7  r   r   rQ   rP   r@   rA   r=  rJ   s   @r&   r  r    sG    +` %,	G-G "G 	G
 
G Gr(   r  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )ReflectionPad3Di  a  
This interface is used to construct a callable object of the ``ReflectionPad3D`` class.
Pads the input tensor boundaries using reflection of the input boundaries.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
        Padding width must be less than the corresponding input dimension.
    data_format (str|None): An string from: "NCDHW", "NDHWC". Specify the data format of the input data.
        Default: ``"NCDHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of reflectionpad3d operator, which is a 5-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of reflectionpad3d operator, which is a 5-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> # from reflection_padding_layers import ReflectionPad3D

        >>> input_shape = (1, 1, 1, 2, 3)
        >>> pad = [1, 0, 1, 0, 0, 0]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data = [[[[[1., 2., 3.], [4., 5., 6.]]]]]
        >>> my_pad = nn.ReflectionPad3D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[5., 4., 5., 6.],
            [2., 1., 2., 3.],
            [5., 4., 5., 6.]]]]])
c                *   > [         TU ]  USSX#5        g rR  r3   rK  s       r&   r5   ReflectionPad3D.__init__,  rU  r(   r"   r  r  r=  rJ   s   @r&   r  r    sG    +` %,	E-E "E 	E
 
E Er(   r  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )	ZeroPad3Di5  a  
This interface is used to construct a callable object of the ``ZeroPad3D`` class.
Pads the input tensor boundaries with zero.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
    data_format (str|None): An string from: "NCDHW", "NDHWC". Specify the data format of the input data.
       Default: ``"NCDHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of zeropad3d operator, which is a 5-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of zeropad3d operator, which is a 5-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 1, 1, 2, 3)
        >>> pad = [1, 0, 1, 2, 0, 0]
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> my_pad = nn.ZeroPad3D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[0., 0., 0., 0.],
            [0., 1., 2., 3.],
            [0., 4., 5., 6.],
            [0., 0., 0., 0.],
            [0., 0., 0., 0.]]]]])
c                *   > [         TU ]  USSX#5        g rY  r3   rK  s       r&   r5   ZeroPad3D.__init__b  r[  r(   r"   r  r  r=  rJ   s   @r&   r  r  5  sG    *^ %,	F-F "F 	F
 
F Fr(   r  c                  F   ^  \ rS rSrSr  S       SU 4S jjjrSrU =r$ )CircularPad3Dik  aY  
This interface is used to construct a callable object of the ``CircularPad3D`` class.
Pads the input tensor boundaries by circular padding.

Parameters:
    padding (Tensor | Sequence[int] | int): The padding size. If `padding` is an `int`,
        the same padding is applied to all six sides (left, right, top, bottom, front, back).
        If `padding` is a list or tuple of six ints, it is interpreted as
        `(pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back)`.
    data_format (str|None): An string from: "NCDHW", "NDHWC". Specify the data format of the input data.
        Default: ``"NCDHW"``
    name (str|None, optional) : The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x(Tensor): The input tensor of circularpad3d operator, which is a 5-D tensor.
      The data type can be float32, float64.
    - output(Tensor): The output tensor of circularpad3d operator, which is a 5-D tensor.
      The data type is same as input x.

Returns:
    Tensor: The padded tensor.

Examples:

    .. code-block:: python

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

        >>> input_shape = (1, 1, 1, 2, 3) # NCDHW
        >>> pad = [1, 0, 1, 2, 0, 0] # (L, R, T, B, F, K)
        >>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
        >>> # data is [[[[[1., 2., 3.],
        >>> #            [4., 5., 6.]]]]]
        >>> my_pad = nn.CircularPad3D(padding=pad)
        >>> result = my_pad(data)
        >>> print(result)
        Tensor(shape=[1, 1, 1, 5, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[[6., 4., 5., 6.],
            [3., 1., 2., 3.],
            [6., 4., 5., 6.],
            [3., 1., 2., 3.],
            [6., 4., 5., 6.]]]]])
c                *   > [         TU ]  USSX#5        g r_  r3   rK  s       r&   r5   CircularPad3D.__init__  r[  r(   r"   r  r  r=  rJ   s   @r&   r  r  k  sG    ,b %,	F-F "F 	F
 
F Fr(   r  c                     ^  \ rS rSrSr\" SS/5      SSU 4S jjj5       rSS jrSS jr\	SS j5       r
\
R                  SS	 j5       r
S
rU =r$ )CosineSimilarityi  a  
This interface is used to compute cosine similarity between x1 and x2 along axis.

Parameters:
    axis (int): Dimension of vectors to compute cosine similarity. Default is 1.
    eps (float): Small value to avoid division by zero. Default is 1e-8.
Returns:
    None

Examples:
    .. code-block:: text

        Case 0:
            x1 = [[0.8024077  0.9927354  0.27238318 0.8344984 ]
                  [0.48949873 0.5797396  0.65444374 0.66510963]
                  [0.1031398  0.9614342  0.08365563 0.6796464 ]
                  [0.10760343 0.7461209  0.7726148  0.5801006 ]]
            x2 = [[0.62913156 0.1536727  0.9847992  0.04591406]
                  [0.9098952  0.15715368 0.8671125  0.3156102 ]
                  [0.4427798  0.54136837 0.5276275  0.32394758]
                  [0.3769419  0.8535014  0.48041078 0.9256797 ]]
            axis = 1
            eps = 1e-8
            Out: [0.5275037  0.8368967  0.75037485 0.9245899]

Code Examples:
    .. code-block:: python

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

        >>> x1 = paddle.to_tensor([[1., 2., 3.],
        ...                        [2., 3., 4.]], dtype="float32")
        >>> x2 = paddle.to_tensor([[8., 3., 3.],
        ...                        [2., 3., 4.]], dtype="float32")

        >>> cos_sim_func = nn.CosineSimilarity(axis=0)
        >>> result = cos_sim_func(x1, x2)
        >>> print(result)
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.65079135, 0.98058069, 1.        ])
r   dimc                :   > [         TU ]  5         Xl        X l        g r!   )r4   r5   _axis_eps)r6   r   epsr9   s      r&   r5   CosineSimilarity.__init__  s    
	r(   c                V    [         R                  " XU R                  U R                  S9$ )N)r   r  )ri   cosine_similarityr  r  r   s      r&   r>   CosineSimilarity.forward  s    ""2

		JJr(   c                :    SR                   " S0 U R                  D6$ )Nzaxis={_axis}, eps={_eps}r"   )format__dict__r6   s    r&   ru   CosineSimilarity.extra_repr  s    )00A4==AAr(   c                    U R                   $ r!   r  r  s    r&   r  CosineSimilarity.dim  s    zzr(   c                    Xl         g r!   r  r6   r)  s     r&   r  r    s    
r(   )r  r  )r   g:0yE>)r   rx   r  r   r@   rA   r   rz   )r@   rx   )r)  rx   r@   rA   )rC   rD   rE   rF   rG   r
   r5   r>   ru   propertyr  setterrH   rI   rJ   s   @r&   r  r    sc    )V fe_%  &
KB   	ZZ r(   r  c            
         ^  \ rS rSr% SrS\S'      SSSSSSSSSS.                           SU 4S jjjjr\S	 5       r\R                  S
 5       r\
" SS/5      SS j5       rSS jrSrU =r$ )	Embeddingi  ad  

Embedding Layer, used to construct a callable object of the ``Embedding`` class.
For specific usage, refer to code examples. It implements the function of the Embedding Layer.
This layer is used to lookup embeddings vector of ids provided by :attr:`x` .
It automatically constructs a 2D embedding matrix based on the
input :attr:`num_embeddings` and :attr:`embedding_dim`.

The shape of output Tensor is generated by appending an emb_size dimension to the
last dimension of the input Tensor shape.

Note:
    The id in :attr:`x` must satisfy :math:`0 <= id < num_embeddings` ,
    otherwise the program will throw an exception and exit.

.. code-block:: text

    Case 1:

    x is a Tensor. padding_idx = -1
        x.data = [[1, 3], [2, 4], [4, 127]
        x.shape = [3, 2]
    Given size = [128, 16]
    output is a Tensor:
        out.shape = [3, 2, 16]
        out.data = [[[0.129435295, 0.244512452, ..., 0.436322452],
                     [0.345421456, 0.524563927, ..., 0.144534654]],
                    [[0.345249859, 0.124939536, ..., 0.194353745],
                     [0.945345345, 0.435394634, ..., 0.435345365]],
                    [[0.945345345, 0.435394634, ..., 0.435345365],
                     [0.0,         0.0,         ..., 0.0        ]]]  # padding data
    The input padding_idx is less than 0, it is automatically converted to padding_idx = -1 + 128 = 127
    It will pad all-zero data when ids is 127.

Parameters:
    num_embeddings (int): Just one element which indicate the size of the dictionary of embeddings.
    embedding_dim (int):  Just one element which indicate the size of each embedding vector respectively.
    padding_idx(int|float|None, optional): padding_idx needs to be in the interval [-num_embeddings, num_embeddings).
        If :math:`padding\_idx < 0`, the :math:`padding\_idx` will automatically be converted
        to :math:`vocab\_size + padding\_idx` . It will output all-zero padding data whenever lookup
        encounters :math:`padding\_idx` in id. And the padding data will not be updated while training.
        If set None, it makes no effect to output. Default: None.
    max_norm(float, optional): If provided, will renormalize the embedding vectors to have a norm larger than
        :attr:`max\_norm` . It will inplace update the input embedding weight in dynamic graph mode. Default: None.
    norm_type(float, optional): The p of the p-norm to compute for the max_norm option. Default: 2.0.
    sparse(bool, optional): The flag indicating whether to use sparse update. This parameter only
        affects the performance of the backwards gradient update. It is recommended to set
        True because sparse update is faster. But some optimizer does not support sparse update,
        such as :ref:`api_paddle_optimizer_adadelta_Adadelta` , :ref:`api_paddle_optimizer_adamax_Adamax` , :ref:`api_paddle_optimizer_lamb_Lamb`.
        In these case, sparse must be False. Default: False.
    scale_grad_by_freq(bool, optional): Indicating whether to scale the gradients by the inverse frequency of the
        word ids in input `x`. Default: False.
    _weight(Tensor, optional): The learnable weights to be applied to the input embeddings.
        If :attr:`_weight` is specified, the :attr:`weight_attr` is ignored. Default: None.
    _freeze(bool, optional): Indicates whether to freeze the embedding weights. If set to True, the provided embedding tensor
        will be treated as a fixed lookup table and will not be updated during training.
        If set to False, the provided tensor remains learnable. Default: False.
    device(PlaceLike, optional): Device where the computation takes place when :attr:`weight_attr` is specified. Default: None
    dtype(DTypeLike, optional): Data type of the weights when :attr:`weight_attr` is specified. Default: None.
    weight_attr(ParamAttr|None, optional): To specify the weight parameter property. If set, the :attr:`_freeze` attribute will be
        ignored and whether the weight is trainable  depends on the ``trainable`` option in ``weight_attr`. Default: None, which means the
        default weight parameter property is used. See usage for details in :ref:`api_paddle_ParamAttr` . In addition,
        user-defined or pre-trained word vectors can be loaded with the :attr:`param_attr` parameter.
        The local word vector needs to be transformed into numpy format, and the shape of local word
        vector should be consistent with :attr:`num_embeddings` . Then :ref:`api_paddle_nn_initializer_Assign`
        is used to load custom or pre-trained word vectors. See code example for details.
    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.

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

Returns:
    None

Examples:

    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[0], [1], [3]], dtype="int64", stop_gradient=False)
        >>> embedding = paddle.nn.Embedding(4, 3, sparse=True)

        >>> w0 = paddle.to_tensor([[0., 0., 0.],
        ...                        [1., 1., 1.],
        ...                        [2., 2., 2.],
        ...                        [3., 3., 3.]], dtype="float32")
        >>> embedding.weight.set_value(w0)
        >>> print(embedding.weight)
        Parameter containing:
        Tensor(shape=[4, 3], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[0., 0., 0.],
         [1., 1., 1.],
         [2., 2., 2.],
         [3., 3., 3.]])

        >>> adam = paddle.optimizer.Adam(parameters=[embedding.weight], learning_rate=0.01)
        >>> adam.clear_grad()

        >>> out = embedding(x)
        >>> print(out)
        Tensor(shape=[3, 1, 3], dtype=float32, place=Place(cpu), stop_gradient=False,
        [[[0., 0., 0.]],
         [[1., 1., 1.]],
         [[3., 3., 3.]]])

        >>> out.backward()
        >>> adam.step()

r   rN   NF)scale_grad_by_freqsparse_weight_freezerS   rR   re   rQ   c                 > [         TU ]  5         Xl        X l        Xpl        SU l        X@l        XPl        X0l        X`l	        Xl
        U R                  S::  a  [        S5      eU R                  S::  a  [        S5      eUc  SOUS:  a  UOX-   nX1:  d  X1* :  a  [        SU SU S35      eUc  U R                  R                  5       OUU l        U R                  U R                  /U l        Xl        SU l        Xl        Ub9  ['        UR(                  5      UU/:X  d   S	5       eXl        XR*                  l        O]U R/                  U R                   U R                  U R                  SU R                  S
9U l        U R                   c  XR*                  l        [1        5       (       aU  US:w  aN  U R*                  R3                  5       (       a.  [4        R6                  " 5          SU R*                  U'   S S S 5        g g g g ! , (       d  f       g = f)NFr   z$num_embeddings must be gather than 0z#embedding_dim must be gather than 0zpadding_idx must be within [-z, )z?Shape of weight does not match num_embeddings and embedding_dim)r[   rZ   rR   r\   rS   r5  )r4   r5   _num_embeddings_embedding_dim_sparse_is_distributed	_max_norm
_norm_type_padding_idx_scale_grad_by_freq_devicer   r]   r^   r_   _sizer`   _remote_prefetchr   r-   rZ   rN   stop_gradientrb   r   _is_initializedr,   no_grad)r6   num_embeddingsembedding_dimpadding_idxmax_norm	norm_typer  r  r  r  rS   rR   re   rQ   r9   s                 r&   r5   Embedding.__init__W	  s   " 	-+$!#'#5 1$CDD!#BCC "  !# $2 	 (K/,I//?r.AQQRS 
 16DLL**,5 	 **D,?,?@
' %
&+  Q QQ  "K(/KK%//&&jjkk|| 0 DK   (,3) r!++--!+.K( "! . "  "!s   !G==
Hc                    U R                   $ r!   r  r  s    r&   r  Embedding.padding_idx	         r(   c                    Xl         g r!   r  r  s     r&   r  r  	      !r(   r$   r=   c                    [         R                  " UU R                  U R                  U R                  U R
                  U R                  U R                  U R                  S9$ )N)rN   r  r  r  r  r  rQ   )	ri   	embeddingrN   r  r  r  r  r  r   r/  s     r&   r>   Embedding.forward	  sK    {{;;))^^oo<<#77	
 		
r(   c                    SnU R                   b  US-  nUS-  nUS-  nU R                  b  US-  nUR                  " S0 U R                  D6$ )Nz#{_num_embeddings}, {_embedding_dim}z, padding_idx={_padding_idx}z, sparse={_sparse}z*, scale_grad_by_freq={_scale_grad_by_freq}z, name={_name}r"   )r  r   r  r  )r6   r   s     r&   ru   Embedding.extra_repr	  s_    8(66H((@@::!((H///r(   )r  r_   r  r  r  r   r  r  r  r  r  r  r  r`   rN   )NNg       @)r  rx   r  rx   r  float | Noner  r  r  r   r  r   r  r   r  zTensor | Noner  r   rS   zPlaceLike | NonerR   zDTypeLike | Nonere   ry   rQ   rP   r@   rA   r   rz   )rC   rD   rE   rF   rG   r}   r5   r  r  r  r
   r>   ru   rH   rI   rJ   s   @r&   r  r    s6   n` N %)!%Q/ $)!%#'"&,0Q/Q/ Q/ "	Q/
 Q/ Q/ !Q/ Q/ Q/ Q/ !Q/  Q/ *Q/ Q/  
!Q/ Q/f ! ! " " c7^$

 %

0 0r(   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S	\S
'   \" 1 SkSSSS9    S           SU 4S jjj5       rSS jrSS jr	Sr
U =r$ )Unfoldi	  a  
Returns a col buffer of sliding local blocks of input x, also known
as im2col for batched 2D image tensors. For each block under the convolution filter,
all element will be rearranged as a column. While the convolution filter sliding over
the input feature map, a series of such columns will be formed.

For each input :math:`x` with shape [N, C, H, W], the output shape [N, Cout, Lout]
can be calculated as following.

See ``paddle.nn.functional.unfold`` for more details.


Parameters:
    kernel_sizes(int|list|tuple): The size of convolution kernel, should be [k_h, k_w]
        or an integer k treated as [k, k].
    strides(int|list|tuple, optional): The strides, should be [stride_h, stride_w]
        or an integer stride treated as [stride, stride]. For default, strides will be [1, 1].
    paddings(int|list|tuple, optional): The paddings of each dimension, should be
        [padding_top, padding_left, padding_bottom, padding_right] or [padding_h, padding_w]
        or an integer padding. If [padding_h, padding_w] was given, it will expanded to
        [padding_h, padding_w, padding_h, padding_w]. If an integer padding was given,
        [padding, padding, padding, padding] will be used. For default,
        paddings will be [0, 0, 0, 0].
    dilations(int|list|tuple, optional): The dilations of convolution kernel, should be
        [dilation_h, dilation_w], or an integer dilation treated as [dilation, dilation].
        For default, it will be [1, 1].
    name(str|None, optional): The default value is None. Normally there is no need for user to
        set this property. For more information, please refer to :ref:`api_guide_Name`


Examples:
    .. code-block:: pycon

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

        >>> x = paddle.randn((100, 3, 224, 224))
        >>> unfold = nn.Unfold(kernel_sizes=[3, 3])
        >>> result = unfold(x)
        >>> print(result.shape)
        paddle.Size([100, 27, 49284])

r   kernel_sizes	dilationsSize2 | Size4paddingsstridesrP   rQ   >   strider'  dilationkernel_sizezpaddle.nn.Unfoldzpaddle.compat.nn.Unfoldztorch.nn.UnfoldrT   c                ^   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        g r!   )r4   r5   r  r  r  r  rQ   )r6   r  r  r  r  rQ   r9   s         r&   r5   Unfold.__init__	  s*     	(" 	r(   c           	         [         R                  " UU R                  U R                  U R                  U R
                  U R                  S9$ )N)r  r  r  r  rQ   )ri   unfoldr  r  r  r  rQ   r<   s     r&   r>   Unfold.forward
  s;    xx**LL]]nn
 	
r(   c           	         U R                   (       a  SU R                    3OSnSU R                   SU R                   SU R                   SU R                   U 3	$ Nro   rp   zkernel_size=z, dilation=z
, padding=z	, stride=rQ   r  r  r  r  rs   s     r&   ru   Unfold.extra_repr
  j    ,0IIWTYYK(2d//0DNN;K:VZVcVcUddmnrnznzm{  }E  |F  G  	Gr(   )r  r  rQ   r  r  r   r   r   N)r  r   r  r   r  r  r  r   rQ   rP   r@   rA   rB   rz   r|   rJ   s   @r&   r  r  	  s    *X N
E$.$	 "#   	
   
 
G Gr(   r  c                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S\S	'   S
\S'   \" S/S/S/S/S/S.5          S              S!U 4S jjj5       rS"S jrS#S jr	\
S$S j5       r\R                  S%S j5       r\
S$S j5       r\R                  S%S j5       r\
S$S j5       r\R                  S%S j5       r\
S&S j5       r\R                  S'S j5       r\
S$S j5       r\R                  S%S j5       rSrU =r$ )(Foldi"
  a1
  

Combines an array of sliding local blocks into a large containing
tensor. also known as col2im when operated on batched 2D image tensor. Fold calculates each
combined value in the resulting large tensor by summing all values from all containing blocks.


For each input :math:`x` with shape [N, C_in , L], the output shape [N, C_out, H_out, W_out]
can be calculated as following.

.. math::

    H_{out} &= output\_size[0] \\
    W_{out} &= output\_size[1] \\
    C_{out} &= \frac{C_{in}}{kernel\_sizes[0]\times kernel\_sizes[1]} \\

Parameters:
    output_sizes(list):  The size of output size, should be [output_size_h, output_size_w]
                              or an integer o treated as [o, o].
    kernel_sizes(int|list|tuple):   The size of convolution kernel, should be [k_h, k_w]
                              or an integer k treated as [k, k].
    strides(int|list|tuple, optional):  The strides, should be [stride_h, stride_w]
                              or an integer stride treated as [stride, stride].
                              For default, strides will be [1, 1].
    paddings(int|list|tuple, optional):  The paddings of each dimension, should be
                              [padding_top, padding_left, padding_bottom, padding_right]
                              or [padding_h, padding_w] or an integer padding.
                              If [padding_h, padding_w] was given, it will expanded to
                              [padding_h, padding_w, padding_h, padding_w]. If an integer
                              padding was given, [padding, padding, padding, padding] will
                              be used. For default, paddings will be [0, 0, 0, 0]
    dilations(int|list|tuple, optional): The dilations of convolution kernel, should be
                              [dilation_h, dilation_w], or an integer dilation treated as
                              [dilation, dilation]. For default, it will be [1, 1].
    name(str|None, optional): The default value is None.
                         Normally there is no need for user to set this property.
                         For more information, please refer to :ref:`api_guide_Name`


Returns:
    The tensor formed by combining a group of sliding local blocks
    The output shape is [N, Cout, H, W] as described above.

Examples:

    .. code-block:: pycon

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

        >>> x = paddle.randn([2, 3*2*2, 12])
        >>> fold = nn.Fold(output_sizes=[4, 5], kernel_sizes=2)
        >>> y = fold(x)
        >>> print(y.shape)
        paddle.Size([2, 3, 4, 5])
r   output_sizesr  r  r  r  r  rP   rQ   output_sizer  r  r'  r  )r  r  r  r  r  c                j   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        X`l        g r!   )r4   r5   r  r  r  r  r  rQ   )r6   r  r  r  r  r  rQ   r9   s          r&   r5   Fold.__init__c
  s0    $ 	((" 	r(   c           
         [         R                  " UU R                  U R                  U R                  U R
                  U R                  U R                  S9$ )N)r  r  r  r  r  rQ   )ri   foldr  r  r  r  r  rQ   r<   s     r&   r>   Fold.forward~
  sD    vv****LL]]nn
 	
r(   c           	         U R                   (       a  SU R                    3OSnSU R                   SU R                   SU R                   SU R                   U 3	$ r  r  rs   s     r&   ru   Fold.extra_repr
  r  r(   c                    U R                   $ r!   r  r  s    r&   r  Fold.output_size
  r  r(   c                    Xl         g r!   r  r  s     r&   r  r  
  r  r(   c                    U R                   $ r!   r  r  s    r&   r  Fold.kernel_size
  r  r(   c                    Xl         g r!   r  r  s     r&   r  r  
  r  r(   c                    U R                   $ r!   r  r  s    r&   r  Fold.stride
  s    ||r(   c                    Xl         g r!   r   r  s     r&   r  r  
  s    r(   c                    U R                   $ r!   r  r  s    r&   r'  Fold.padding
  s    }}r(   c                    Xl         g r!   r  r  s     r&   r'  r  
  s    r(   c                    U R                   $ r!   r  r  s    r&   r  Fold.dilation
  s    ~~r(   c                    Xl         g r!   r  r  s     r&   r  r	  
  s    r(   )r  r  rQ   r  r  r  r  )r  r   r  r   r  r   r  r  r  r   rQ   rP   r@   rA   rB   rz   )r@   r   )r)  r   r@   rA   )r@   r  )r)  r  r@   rA   )rC   rD   rE   rF   rG   r}   r	   r5   r>   ru   r  r  r  r  r  r'  r  rH   rI   rJ   s   @r&   r  r  "
  s   7r N
*O*O z"$	
 "#  	
     
$	
G ! ! " " ! ! " "   ]]    ^^    __ r(   r  c                  T   ^  \ rS rSr% SrS\S'   S\S'   S	S
U 4S jjjrSS jrSrU =r	$ )Flatteni
  af  
This interface is used to construct a callable object of the ``Flatten`` class.
For more details, refer to code examples.
It implements flatten a contiguous range of dims into a tensor.

Parameters:
    start_axis(int): first dim to flatten (default = 1)
    stop_axis(int): last dim to flatten (default = -1).

Returns:
    None

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> inp = paddle.ones([5, 2, 3, 4]).astype('float32')
        >>> flatten = paddle.nn.Flatten(start_axis=1, stop_axis=2)
        >>> y = flatten(inp)
        >>> print(y.shape)
        paddle.Size([5, 6, 4])

rx   
start_axis	stop_axisc                :   > [         TU ]  5         Xl        X l        g r!   )r4   r5   r  r  )r6   r  r  r9   s      r&   r5   Flatten.__init__
  s    $"r(   c                X    [         R                  " XR                  U R                  S9nU$ )Nr  r  )r,   flattenr  r  rk   s      r&   r>   Flatten.forward
  s$    nnoo
 
r(   r  )r   r  )r  rx   r  rx   r@   rA   rB   )
rC   rD   rE   rF   rG   r}   r5   r>   rH   rI   rJ   s   @r&   r  r  
  s(    4 ON# #
 r(   r  c                  x   ^  \ rS rSr% SrS\S'   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
$ )	Unflatteni
  a  
This interface is used to construct a callable object of the ``Unflatten`` class.
For more details, refer to code examples.
It a certain dimension of the input x Tensor into a desired shape.

Parameters:
    axis (int): :attr:`axis` to be unflattened, specified as an index into `x.shape`.
    shape (list|tuple|Tensor): Unflatten :attr:`shape` on the specified :attr:`axis`. At most one dimension of the target :attr:`shape` can be -1.
        If the input :attr:`shape` does not contain -1 , the product of all elements in ``shape`` should be equal to ``x.shape[axis]``.
        The data type is `int` . If :attr:`shape` is a list or tuple, the elements of it should be integers or Tensors with shape [].
        If :attr:`shape` is an Tensor, it should be an 1-D Tensor.
    name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    None

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> x = paddle.randn(shape=[4, 6, 8])
        >>> shape = [2, 3]
        >>> axis = 1
        >>> unflatten = paddle.nn.Unflatten(axis, shape)
        >>> res = unflatten(x)
        >>> print(res.shape)
        paddle.Size([4, 2, 3, 8])

rx   r   r   rZ   rP   rQ   c                F   > [         TU ]  5         Xl        X l        X0l        g r!   )r4   r5   r   rZ   rQ   )r6   r   rZ   rQ   r9   s       r&   r5   Unflatten.__init__  s     		
	r(   c                n    [         R                  " XR                  U R                  U R                  S9nU$ )N)r   rZ   rQ   )r,   	unflattenr   rZ   rQ   rk   s      r&   r>   Unflatten.forward  s,    		$))
 
r(   c                    U R                   (       a  SU R                    3OSnSU R                   SU R                   U 3$ )Nro   rp   zaxis=z, shape=)rQ   r   rZ   rs   s     r&   ru   Unflatten.extra_repr  s9    ,0IIWTYYK(2tyyk$**hZ@@r(   )r   rQ   rZ   r!   )r   rx   rZ   r   rQ   rP   r@   rA   rB   rz   r   rJ   s   @r&   r  r  
  s]    @ I
 ?C )1;	 A Ar(   r  )r$   r   r%   rx   r@   r   )r$   rx   r%   rx   r@   z	list[int])L
__future__r   typingr   r   r   r   r,   r   paddle.utils.decorator_utilsr	   r
   rp   r   ri   layersr   collections.abcr   r   paddle._typingr   r   r   r   r   r   r   r   r   r   functional.commonr   r   r   rx   r   r   __all__r'   r0   rL   r   r   r   r   r   r   r   r	  r  r$  r9  r?  rG  rP  rW  r]  rc  rh  rm  rr  rv  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r"   r(   r&   <module>r&     s   # 8 8  " M  (    vx}=J @
 
 5 
 5 
 - 
 -,u ,^{yU {y|J[u J[Z]G% ]G@^G5 ^GBcYu cYL_ce _cDRG RGjTG TGn:'5 :'z;'% ;'|!{U !{H1BF 1Bh0HE 0Hf0Gu 0Gf2Ee 2Ej/F /Fd0FE 0Ff8BF 8Bv3HE 3Hl3Gu 3Gl4Ee 4En2F 2Fj5FE 5Fp9BF 9Bx4HE 4Hn4Gu 4Gn4Ee 4En3F 3Fl5FE 5Fp>u >Bc0 c0LUGU UGpQ5 Qh'e 'T5A 5Ar(   