---
title: "ClikaRT::ops::fill_diagonal"
sidebar_label: "fill_diagonal"
description: "A copy of the 2-D matrix input with fill_value written along its diagonal."
---

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

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

## fill\_diagonal() {#fill_diagonal}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`fill_diagonal`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Scalar`](../Scalar.md) `fill_value`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `wrap` `=` `false`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`<br />
)

</div>

A copy of the 2-D matrix `input` with `fill_value` written along its diagonal.

Without `wrap` the diagonal stops at `min(rows, cols)`; with `wrap = true` a TALL matrix continues the diagonal below the wrap row, restarting at the left edge (the classic tall-matrix wrap).

**Parameters**

- `input`: the matrix; off-diagonal values carry over unchanged.
- `fill_value`: the value written on the diagonal: a [`Scalar`](../Scalar.md), kind-preserving: an integer literal writes exactly on integer dtypes (no double round-trip).
- `wrap`: tall-matrix wrap, as above. Default `false`.
- `device`: optional stream override. Default: `input`'s placement.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `input` is not 2-D (`code_name()` carries the reason).

**Returns:** a new matrix, `input` with the diagonal overwritten.

<div class="api-declared">

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

</div>
