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
inputTensor(N, M).pfloat= 2.02 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. For p=2 that is
lucid.cdist's default compute_mode: pair-by-pair differences
up to 25 rows, the matrix-product expansion past that. Both keep a
distance whose square leaves the float range (rows near 1e-20 or
1e25), as lucid.cdist documents.
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., 1., 1.414])