---
title: "ClikaRT::ops::cdist"
sidebar_label: "cdist"
description: "Pairwise L_p distance between every ROW pair of two matrices. \\[ \\mathrm{out}_{mn} = \\lVert a_m - b_n \\rVert_p \\] (B?, M, K) x (B?, N, K) -> (B?, M, N); the optional leading batch dims broadcast."
---

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

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

## cdist() {#cdist}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`cdist`**(<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 />
)

</div>

Pairwise L\_p distance between every ROW pair of two matrices.

$$
\mathrm{out}_{mn} = \lVert a_m - b_n \rVert_p
$$

`(B?, M, K) x (B?, N, K) -> (B?, M, N)`; the optional leading batch dims broadcast.

**Parameters**

- `x1`: rows `[.., M, K]`.
- `x2`: rows `[.., N, K]` (same trailing `K`).
- `p`: the norm degree, an int or float [`Scalar`](../Scalar.md), kind-preserved; default 2.

**Returns:** the distance matrix `[.., M, N]`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the trailing `K`s disagree.

<div class="api-declared">

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

</div>
