Skip to main content

ClikaRT::ops::pairwise_distance

function

pairwise_distance()

Tensor pairwise_distance(
    Tensor a,
    Tensor b,
    Scalar p = 2.0,
    std::optional<double> eps = std::nullopt,
    bool keepdim = false
)

Row-wise L_p distance between two batched vectors.

out=ab+εp\mathrm{out} = \lVert a - b + \varepsilon \rVert_p

Reduces the LAST axis; leading dims broadcast.

Parameters

  • a: left operand [.., K].
  • b: right operand [.., K].
  • p: the norm degree, an int or float Scalar, kind-preserved; default 2.
  • eps: small perturbation for gradient stability; std::nullopt selects 1e-6.
  • keepdim: keep the reduced axis as size 1; default false.

Returns: the distances; the broadcast shape minus the last axis.

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) when the trailing extents disagree.

Declared in ClikaRT/compute/ops.h, line 2858