tfep.utils.geometry.pdist
- tfep.utils.geometry.pdist(x, pairs=None, return_diff=False)[source]
Compute p-norm distances between pairs of row vectors.
In comparison to
torch.nn.functional.pdist, the function can handle batches and compute distances between a subset of all pairs. Only the Euclidean norm is currently supported.- Parameters:
x (torch.Tensor) – Positions of particles with shape
(batch_size, n_particles, D), whereDis the dimensionality of the vector space.pairs (torch.Tensor, optional) – A tensor of shape
(2, n_pairs). For each batch sample, the function will compute thei-th distance between thepairs[0, i]-th and thepairs[1, i]-th atoms. If not passed, all pairwise distances are computed.return_diff (bool, optional) – If
True, the difference vector between pairs of particles are also returned.
- Returns:
distances (torch.Tensor) – This has shape
(batch_size, n_pairs), anddistances[b, i]is the distance between the particles of thei-th pair for theb-th batch samplediff (torch.Tensor, optional) – This has shape
(batch_size, n_pairs, 3), anddiff[b, i]is the vectorp1-p0, wherepXis the position of particlepairs[b, X]. This is returned only ifreturn_diffisTrue.