The current euclidean distance calculation produces non-symmetric distance matrices. I suspect this is a numeric issue (although it persists even when using float64):
out = -2 * torch.matmul(x, y)
out += (x ** 2).sum(dim=-1, keepdim=True)
out += (y ** 2).sum(dim=-2, keepdim=True)
a = out.t() - out
tensor([[ 0.0000e+00, 0.0000e+00, 0.0000e+00, ..., -7.1054e-15,
-7.1054e-15, 0.0000e+00],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, ..., 7.1054e-15,
0.0000e+00, 0.0000e+00],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, ..., -7.1054e-15,
0.0000e+00, -7.1054e-15],
...,
[ 7.1054e-15, -7.1054e-15, 7.1054e-15, ..., 0.0000e+00,
0.0000e+00, 0.0000e+00],
[ 7.1054e-15, 0.0000e+00, 0.0000e+00, ..., 0.0000e+00,
0.0000e+00, 0.0000e+00],
[ 0.0000e+00, 0.0000e+00, 7.1054e-15, ..., 0.0000e+00,
0.0000e+00, 0.0000e+00]], dtype=torch.float64)
Apparently sklearn.metric.pairwise_distance also has this issue...
The current euclidean distance calculation produces non-symmetric distance matrices. I suspect this is a numeric issue (although it persists even when using float64):
Apparently
sklearn.metric.pairwise_distancealso has this issue...