---
title: "ClikaRT::ops::diag_embed"
sidebar_label: "diag_embed"
description: "Embed the LAST dim along the diagonal of a fresh (dim1, dim2) plane: output rank = input rank + 1, both new dims sized last + |offset|, the inverse of diagonal."
---

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

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

## diag\_embed() {#diag_embed}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`diag_embed`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `offset` `=` `0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim1` `=` `-2`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim2` `=` `-1`<br />
)

</div>

Embed the LAST dim along the diagonal of a fresh `(dim1, dim2)` plane: output rank = input rank + 1, both new dims sized `last + |offset|`, the inverse of [`diagonal`](./diagonal.md#diagonal). Defaults place the plane at the trailing two dims. Copies.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `dim1`/`dim2` collide or exceed the output rank (`code_name()` carries the reason).

**Returns:** a new tensor of rank + 1.

<div class="api-declared">

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

</div>
