
    {-j                    r    d dl mZ d dlmZ d dlmZmZ ddlmZ	 ddl
mZ erd dlZg Z G d	 d
e          ZdS )    )annotations)TYPE_CHECKING)param_one_aliasparam_two_alias   )
functional   )LayerNc                      e Zd ZdZ eddg          	 	 	 	 dd fd            Z eddgddg          d d            Zd!dZe	d"d            Z
e
j        d#d            Z
e	d"d            Zej        d#d            Z xZS )$PairwiseDistancea  

    It computes the pairwise distance between two vectors. The
    distance is calculated by p-order norm:

    .. math::

        \Vert x \Vert _p = \left( \sum_{i=1}^n \vert x_i \vert ^ p \right) ^ {1/p}.

    Parameters:
        p (float, optional): The order of norm. Default: :math:`2.0`.
        epsilon (float, optional): Add small value to avoid division by zero.
            Default: :math:`1e-6`.
        keepdim (bool, optional): Whether to reserve the reduced dimension
            in the output Tensor. The result tensor is one dimension less than
            the result of ``|x-y|`` unless :attr:`keepdim` is True. Default: False.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`.
            Generally, no setting is required. Default: None.

    Shape:
        - x: :math:`[N, D]` or :math:`[D]`, where :math:`N` is batch size, :math:`D`
          is the dimension of the data. Available data type is float16, float32, float64.
        - y: :math:`[N, D]` or :math:`[D]`, y have the same dtype as x.
        - output: The same dtype as input tensor.
            - If :attr:`keepdim` is True, the output shape is :math:`[N, 1]` or :math:`[1]`,
              depending on whether the input has data shaped as :math:`[N, D]`.
            - If :attr:`keepdim` is False, the output shape is :math:`[N]` or :math:`[]`,
              depending on whether the input has data shaped as :math:`[N, D]`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.to_tensor([[1., 3.], [3., 5.]], dtype=paddle.float64)
            >>> y = paddle.to_tensor([[5., 6.], [7., 8.]], dtype=paddle.float64)
            >>> dist = paddle.nn.PairwiseDistance()
            >>> distance = dist(x, y)
            >>> print(distance)
            Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
            [4.99999860, 4.99999860])
    epsiloneps       @ư>FNpfloatkeepdimboolname
str | Nonec                    t                                                       || _        || _        || _        || _        d S N)super__init__r   r   r   r   )selfr   r   r   r   	__class__s        X/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/nn/layer/distance.pyr   zPairwiseDistance.__init__I   s;     				    xx1yx2paddle.Tensorreturnc                \    t          j        ||| j        | j        | j        | j                  S r   )Fpairwise_distancer   r   r   r   )r   r   r!   s      r   forwardzPairwiseDistance.forwardW   s,    "q$&$,di
 
 	
r   strc                ~    d}| j         dk    r|dz  }| j        dur|dz  }| j        |dz  } |j        di | j        S )Nzp={p}r   z, epsilon={epsilon}Fz, keepdim={keepdim}z, name={name} )r   r   r   format__dict__)r   main_strs     r   
extra_reprzPairwiseDistance.extra_repr]   sc    <4--H<u$$--H9 'Hx/////r   c                    | j         S r   r   r   s    r   r   zPairwiseDistance.epsg   s
    |r   valueNonec                    || _         d S r   r1   r   r3   s     r   r   zPairwiseDistance.epsk   s    r   c                    | j         S r   r   r2   s    r   normzPairwiseDistance.normo   s	    vr   c                    || _         d S r   r8   r6   s     r   r9   zPairwiseDistance.norms   s    r   )r   r   FN)r   r   r   r   r   r   r   r   )r   r#   r!   r#   r$   r#   )r$   r)   )r$   r   )r3   r   r$   r4   )__name__
__module____qualname____doc__r   r   r   r(   r/   propertyr   setterr9   __classcell__)r   s   @r   r   r      sD       ( (T _i'((       )( _c4[3+..
 
 
 /.

0 0 0 0    X 	Z   Z    X 
[   [    r   r   )
__future__r   typingr   paddle.utils.decorator_utilsr   r    r   r&   layersr
   paddle__all__r   r+   r   r   <module>rI      s    # " " " " "             I I I I I I I I             MMM
W W W W Wu W W W W Wr   