fn
pdist
→Tensorpdist(x: Tensor, p: float = 2.0)Pairwise distances between rows of a 2-D tensor.
For an input of shape (N, M), returns the
strictly-upper-triangular pairwise
distances in row-major order:
where k(i, j) enumerates pairs in row-major order.
Parameters
xTensor2-D input of shape
(N, M).pfloat= 2.0Exponent of the norm. Common values:
2 for
Euclidean (default), 1 for Manhattan, float("inf") for
Chebyshev.Returns
Tensor1-D tensor of length (empty when ).
Notes
Internally computed by extracting the strict upper triangle of the
full lucid.cdist matrix, which keeps the implementation
simple and fully differentiable but is in both
compute and intermediate memory — for very large N, prefer a
blocked / streaming pairwise routine.
Examples
>>> import lucid
>>> from lucid.nn.functional import pdist
>>> x = lucid.tensor([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])
>>> pdist(x, p=2)
Tensor([1.0000, 1.0000, 1.4142])