Ë
    •\;jç  ã                   óL   — d dl Z d dl mZ d dlmZ ddlmZmZ ddlmZ g Z	dd„Z
y)	é    N)Ú_C_ops)Úin_dynamic_or_pir_modeé   )Ú
check_typeÚcheck_variable_and_dtype)ÚLayerHelperc                 ó2  — t        «       rmt        j                  | |«      }|dk7  r8t        j                  |g|j
                  ¬«      }t        j                  ||«      }t        j                  ||dd|d«      S t        |dt        t        fd«       t        |dt        d«       t        |dt        d«       t        | d	g d
¢d«       t        |dg d
¢d«       t        j                  | |«      }|dk7  r_|j                  j                  |j
                  ¬«      }t        j                  dg||j
                  ¬«      }t        j                  ||«      }t!        d|¬«      }d||ddœ}	|j#                  | j
                  ¬«      }
|j%                  dd|id|
i|	¬«       |
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
            float16, 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
            float16, 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)
            Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
            [4.99999860, 4.99999860])
    g        )ÚdtypeéÿÿÿÿFÚporderÚPairwiseDistanceÚepsilonÚkeepdimÚx)Úfloat16Úfloat32Úfloat64Úyé   )ÚshapeÚ
fill_valuer
   )Úname)Úaxisr   r   r   Úp_normÚXÚOut)ÚtypeÚinputsÚoutputsÚattrs)r   r   ÚsubtractÚpaddleÚ	to_tensorr
   Úaddr   r   ÚfloatÚintÚboolr   ÚblockÚ
create_varÚfullr   Ú"create_variable_for_type_inferenceÚ	append_op)r   r   Úpr   r   r   ÚsubÚepsilon_varÚhelperr    Úouts              úfG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/nn/functional/distance.pyÚpairwise_distancer3      sƒ  € ôZ ÔÜ�o‰o˜a Ó#ˆà�cŠ>Ü×&Ñ&¨ y¸¿	¹	ÔBˆGÜ—*‘*˜S 'Ó*ˆCÜ�}‰}˜S ! R¨¨g°uÓ=Ð=ô 	�1�h¤¬ Ð.@ÔAÜ�7˜I¬Ð0BÔCÜ�7˜I¬Ð/AÔBä ØˆsÒ5Ð7Iô	
ô 	!ØˆsÒ5Ð7Iô	
ô �o‰o˜a Ó#ˆØ�cŠ>ØŸ)™)×.Ñ.°S·Y±YÐ.Ó?ˆKÜ Ÿ+™+Ø�c g°S·Y±YôˆKô —*‘*˜S +Ó.ˆCÜÐ/°dÔ;ˆàØØØñ	
ˆð ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØ 3¨ *°u¸c°lÈ%ð 	ô 	
ð ˆ
ó    )g       @g�íµ ÷Æ°>FN)r"   r   Úpaddle.frameworkr   Úbase.data_feederr   r   Úbase.layer_helperr   Ú__all__r3   © r4   r2   Ú<module>r:      s!   ðó Ý Ý 3ç DÝ ,à
€ôSr4   