o
    pi                     @  sT   d dl mZ d dlmZ ddlmZ ddlmZ erd dl	Z	g Z
G dd	 d	eZdS )
    )annotations)TYPE_CHECKING   )
functional   )LayerNc                      s@   e Zd ZdZ				dd fddZdddZdddZ  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])
           @ư>FNpfloatepsilonkeepdimboolname
str | Nonec                   s&   t    || _|| _|| _|| _d S N)super__init__r   r   r   r   )selfr   r   r   r   	__class__ _/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddle/nn/layer/distance.pyr   G   s
   

zPairwiseDistance.__init__xpaddle.Tensoryreturnc                 C  s   t ||| j| j| j| jS r   )FZpairwise_distancer   r   r   r   )r   r   r   r   r   r   forwardT   s   zPairwiseDistance.forwardstrc                 C  sL   d}| j dkr|d7 }| jdur|d7 }| jd ur|d7 }|jdi | jS )Nzp={p}r
   z, epsilon={epsilon}Fz, keepdim={keepdim}z, name={name}r   )r   r   r   format__dict__)r   Zmain_strr   r   r   
extra_reprY   s   


zPairwiseDistance.extra_repr)r	   r
   FN)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r    )__name__
__module____qualname____doc__r   r   r#   __classcell__r   r   r   r   r      s    ,
r   )
__future__r   typingr    r   r   Zlayersr   Zpaddle__all__r   r   r   r   r   <module>   s   