---
title: "ClikaRT::ops::expand"
sidebar_label: "expand"
description: "Broadcast input to a larger shape WITHOUT copying. Size-1 dims stretch to their target; leading target dims with no input counterpart broadcast; -1 keeps the input's extent at that position."
---

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

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

## expand() {#expand}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`expand`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `bidirectional` `=` `false`<br />
)

</div>

Broadcast `input` to a larger shape WITHOUT copying.

Size-1 dims stretch to their target; leading target dims with no input counterpart broadcast; `-1` keeps the input's extent at that position. Extents are literals or 0-D integer Tensors (trace symbolically). With `bidirectional = true` the aligned dims broadcast BOTH ways (the ONNX Expand rule): a target extent of 1 against a non-1 input dim keeps the input dim (the pairwise max) instead of raising. The default is the strict directed form ([`broadcast_to`](./broadcast_to.md#broadcast_to)).

Returns a VIEW: every stretched position aliases ONE stored element; treat the result as read-only (or [`contiguous`](./contiguous.md#contiguous) it to materialize).

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when a non-1 input dim mismatches its target (`code_name()` carries the reason).

**Returns:** a view of `input` with the requested shape.

```cpp
auto row = ClikaRT::ops::unsqueeze(bias, 0);        // [1, d]
auto b   = ClikaRT::ops::expand(row, {batch, -1});  // [batch, d], no copy
```

<div class="api-declared">

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

</div>
