---
title: "ClikaRT::ops::shape"
sidebar_label: "shape"
description: "The tensor's shape as a 1-D Int64 tensor (or one extent as 0-D). The value is produced ON DEVICE and is traceable; under tracing it carries the symbolic value."
---

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

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

2 overloads.

## shape(Tensor, optional\<int64\_t\>) {#shape}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`shape`**([`Tensor`](../Tensor.md) `input`, `std::optional<int64_t>` `dim` `=` `std::nullopt`)

</div>

The tensor's shape as a 1-D Int64 tensor (or one extent as 0-D).

The value is produced ON DEVICE and is traceable; under tracing it carries the symbolic value. For a plain host integer use the `*_host` sibling instead. With `dim` set, returns that single extent as a 0-D Int64 tensor (negative `dim` counts from the end).

**Throws**

- `ClikaRT::Error`: when `dim` is out of range (`code_name()` carries the reason).

**Returns:** `[`[`ndim`](./ndim.md#ndim)`]` Int64, or 0-D Int64 with `dim` set.

<div class="api-declared">

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

</div>

## shape(Tensor, optional\<int64\_t\>, optional\<int64\_t\>) {#shape-2}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`shape`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `start`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<std::int64_t>` `end`<br />
)

</div>

The `[start, end)` window of the shape as ONE 1-D Int64 tensor, a contiguous dim range in a single call (Python-slice bounds: negative values count from the end, `std::nullopt` leaves that side open). Same on-device, traceable contract as `shape(x)`; the host-integer sibling is `shape_host(x, start, end)`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the window is out of range (`code_name()` carries the reason).

**Returns:** `[end - start]` Int64 (empty when the window is empty).

<div class="api-declared">

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

</div>
