o
    Qe@                     @   sV   d dl Z ddlmZmZ ddlmZ d dl mZmZ d dlm	Z	m
Z
 g Zdd
dZdS )    N   )check_variable_and_dtype
check_type)LayerHelper)_C_ops_legacy_C_ops)in_dygraph_mode_in_legacy_dygraph       @ư>Fc                 C   s  t |dttfd t |dtd t |dtd t r@t| |}|dkr6tjj	j
j|g|jd}t||}t||dd|dS t rlt| |}|dkr_tjj	j
j|g|jd}t||}t|d	dd|d|dd	S t| d
ddgd t|dddgd t| |}|dkr|jj|jd}tjdg||jd}t||}td|d}d||dd}	|j| jd}
|jdd|id|
i|	d |
S )a  
    It computes the pairwise distance between two vectors. The
    distance is calculated by p-oreder norm:

    .. math::

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

    Parameters:
        x (Tensor): Tensor, shape is :math:`[N, D]` or :math:`[D]`, where :math:`N`
            is batch size, :math:`D` is the dimension of vector. Available dtype is
            float32, float64.
        y (Tensor): Tensor, shape is :math:`[N, D]` or :math:`[D]`, where :math:`N`
            is batch size, :math:`D` is the dimension of vector. Available dtype is
            float32, float64.
        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.

    Returns:
        Tensor, the dtype is same 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)
            distance = paddle.nn.functional.pairwise_distance(x, y)
            print(distance.numpy()) # [5. 5.]

    porderZPairwiseDistanceepsilonkeepdimg        )dtypeFaxisxZfloat32Zfloat64y   )shapeZ
fill_valuer   )name)r   r   r   r   p_normXZOut)typeZinputsZoutputsattrs)r   floatintboolr   r   subtractpaddleZfluidZdygraphbaseZto_variabler   addr   r	   r   Zelementwise_subZelementwise_addr   blockZ
create_varfullr   Z"create_variable_for_type_inferenceZ	append_op)r   r   pr   r   r   subZepsilon_varhelperr   out r(   MD:\Projects\ConvertPro\env\Lib\site-packages\paddle/nn/functional/distance.pypairwise_distance   sX   *r*   )r
   r   FN)r   Zfluid.data_feederr   r   Zfluid.layer_helperr   r   r   Zpaddle.fluid.frameworkr   r	   __all__r*   r(   r(   r(   r)   <module>   s   