---
title: "ClikaRT::ops::pairwise_distance"
sidebar_label: "pairwise_distance"
description: "Row-wise L_p distance between two batched vectors. \\[ \\mathrm{out} = \\lVert a - b + \\varepsilon \\rVert_p \\] Reduces the LAST axis; leading dims broadcast. x1 left operand [.., K]."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## pairwise\_distance() {#pairwise_distance}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`pairwise_distance`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `x1`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `x2`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Scalar`](../Scalar.md) `p` `=` `2.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `eps` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `keepdim` `=` `false`<br />
)

</div>

Row-wise L\_p distance between two batched vectors.

$$
\mathrm{out} = \lVert a - b + \varepsilon \rVert_p
$$

Reduces the LAST axis; leading dims broadcast.

**Parameters**

- `x1`: left operand `[.., K]`.
- `x2`: right operand `[.., K]`.
- `p`: the norm degree, an int or float [`Scalar`](../Scalar.md), 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.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2945

</div>
