Compute the p-norm distance between each pair of the two collections of inputs.
This function is equivalent to `scipy.spatial.distance.cdist(input,'minkowski', p=p)`
if :math:`p \in (0, \infty)`. When :math:`p = 0` it is equivalent to `scipy.spatial.distance.cdist(input, 'hamming') * M`.
When :math:`p = \infty`, the closest scipy function is `scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max())`.
Args:
x (Tensor): A tensor with shape :math:`B \times P \times M`.
y (Tensor): A tensor with shape :math:`B \times R \times M`.
p (float, optional): The value for the p-norm distance to calculate between each vector pair. Default: :math:`2.0`.
compute_mode (str, optional): The mode for compute distance.
- ``use_mm_for_euclid_dist_if_necessary`` , for p = 2.0 and (P > 25 or R > 25), it will use matrix multiplication to calculate euclid distance if possible.
- ``use_mm_for_euclid_dist`` , for p = 2.0, it will use matrix multiplication to calculate euclid distance.
- ``donot_use_mm_for_euclid_dist`` , it will not use matrix multiplication to calculate euclid distance.
Default: ``use_mm_for_euclid_dist_if_necessary``.
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 x has shape :math:`B \times P \times M` and y has shape :math:`B \times R \times M` then
the output will have shape :math:`B \times P \times R`.
Examples:
.. code-block:: python
import paddle
x = paddle.to_tensor([[0.9041, 0.0196], [-0.3108, -2.4423], [-0.4821, 1.059]], dtype=paddle.float32)
y = paddle.to_tensor([[-2.1763, -0.4713], [-0.6986, 1.3702]], dtype=paddle.float32)