---
title: "ClikaRT::ops::trace"
sidebar_label: "trace"
description: "Sum of the main diagonal of a rank-2 tensor. \\[ \\mathrm{tr}(x) = \\sum_i x_{ii} \\] input a rank-2 tensor [M, N]. a 0-D tensor with input's dtype."
---

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

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

## trace() {#trace}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`trace`**([`Tensor`](../Tensor.md) `input`)

</div>

Sum of the main diagonal of a rank-2 tensor.

$$
\mathrm{tr}(x) = \sum_i x_{ii}
$$

**Parameters**

- `input`: a rank-2 tensor `[M, N]`.

**Returns:** a 0-D tensor with `input`'s dtype.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `input` is not rank-2.

<div class="api-declared">

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

</div>
