---
title: "ClikaRT::ops::einsum"
sidebar_label: "einsum"
description: "Einstein-summation contraction from a notation string. equation names each operand's axes and (after ->) the output axes; omitting -> keeps the once-appearing labels in alphabetical order."
---

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

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

## einsum() {#einsum}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`einsum`**(`std::string_view` `equation`, [`ClikaRT::Span`](../Span.md)`<const` [`Tensor`](../Tensor.md)`>` `operands`)

</div>

Einstein-summation contraction from a notation string.

`equation` names each operand's axes and (after `->`) the output axes; omitting `->` keeps the once-appearing labels in alphabetical order. One- and two-operand equations are served: one operand reduces and permutes; two operands contract through a single batched matmul.

**Parameters**

- `equation`: the contraction, e.g. `"bij,bjk->bik"`.
- `operands`: the tensors, one per comma-separated input group.

**Returns:** the contracted tensor, shaped by the output labels.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the equation is malformed, a label's extents disagree, or more than two operands are passed.

```cpp
ClikaRT::Tensor ops[] = {q, k};
auto scores = ClikaRT::ops::einsum("bhid,bhjd->bhij", ops);
```

<div class="api-declared">

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

</div>
