---
title: "ClikaRT::ops::take_along_dim"
sidebar_label: "take_along_dim"
description: "gather with broadcasting between input and index on the other dims. With dim absent both operands are treated as flattened 1-D. Same index dtype law as gather (Int32/Int64). input the source."
---

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

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

## take\_along\_dim() {#take_along_dim}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`take_along_dim`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `index`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<int64_t>` `dim` `=` `std::nullopt`<br />
)

</div>

[`gather`](./gather.md#gather) with broadcasting between `input` and [`index`](./index-fn.md#index) on the other dims.

With `dim` absent both operands are treated as flattened 1-D. Same index dtype law as [`gather`](./gather.md#gather) (`Int32`/`Int64`).

**Parameters**

- `input`: the source.
- `index`: integer positions; broadcasts against `input` off the chosen dim.
- `dim`: the addressed axis; absent = flattened. Default: absent.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the shapes do not broadcast or the index dtype is wrong (`code_name()` carries the reason).

**Returns:** a new tensor of the broadcast shape, dtype of `input`.

<div class="api-declared">

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

</div>
