---
title: "expand"
sidebar_label: "expand"
description: "Kotlin binding reference: expand."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.runtime](../index.md)/[Ops](index.md)/[expand](expand.md)

# expand

[common]\
fun [expand](expand.md)(input: [Tensor](../Tensor/index.md), shape: [LongArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html), bidirectional: [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) = false): [Tensor](../Tensor/index.md)

`expand(input: Tensor, shape: LongArray, bidirectional: Boolean = false)`: the `expand` operator. 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`). Returns a VIEW: every stretched position aliases ONE stored element; treat the result as read-only (or `contiguous` it to materialize).