|
|
|
@ -341,9 +341,32 @@ def norm(input, p='fro', axis=None, keepdim=False, out=None, name=None):
|
|
|
|
|
def dist(x, y, p=2):
|
|
|
|
|
"""
|
|
|
|
|
This OP returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure
|
|
|
|
|
of distance. The shapes of x and y must be broadcastable.
|
|
|
|
|
of distance. The shapes of x and y must be broadcastable. The definition is as follows, for
|
|
|
|
|
details, please refer to the `numpy's broadcasting <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_:
|
|
|
|
|
|
|
|
|
|
Where, z = x - y,
|
|
|
|
|
- Each input has at least one dimension.
|
|
|
|
|
- Match the two input dimensions from back to front, the dimension sizes must either be equal, one of them is 1, or one of them does not exist.
|
|
|
|
|
|
|
|
|
|
Where, z = x - y, the shapes of x and y are broadcastable, then the shape of z can be
|
|
|
|
|
obtained as follows:
|
|
|
|
|
|
|
|
|
|
1. If the number of dimensions of x and y are not equal, prepend 1 to the dimensions of the
|
|
|
|
|
tensor with fewer dimensions.
|
|
|
|
|
|
|
|
|
|
For example, The shape of x is [8, 1, 6, 1], the shape of y is [7, 1, 5], prepend 1 to the
|
|
|
|
|
dimension of y.
|
|
|
|
|
|
|
|
|
|
x (4-D Tensor): 8 x 1 x 6 x 1
|
|
|
|
|
|
|
|
|
|
y (4-D Tensor): 1 x 7 x 1 x 5
|
|
|
|
|
|
|
|
|
|
2. Determine the size of each dimension of the output z: choose the maximum value from the
|
|
|
|
|
two input dimensions.
|
|
|
|
|
|
|
|
|
|
z (4-D Tensor): 8 x 7 x 6 x 5
|
|
|
|
|
|
|
|
|
|
If the number of dimensions of the two inputs are the same, the size of the output can be
|
|
|
|
|
directly determined in step 2. When p takes different values, the norm formula is as follows:
|
|
|
|
|
|
|
|
|
|
When p = 0, defining $0^0=0$, the zero-norm of z is simply the number of non-zero elements of z.
|
|
|
|
|
|
|
|
|
|