---
title: "ClikaRT::spec::TensorSpec"
sidebar_label: "TensorSpec"
description: "A named, typed input/output slot, the library's ONE vocabulary for describing a tensor slot (a model input/output, a graph feed, a traced signature)."
---

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

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

**Header:** `ClikaRT/runtime/schema.h`

A named, typed input/output slot, the library's ONE vocabulary for describing a tensor slot (a model input/output, a graph feed, a traced signature).

[`TensorSpec`](./TensorSpec.md) DESCRIBES a slot (name/dtype/dims as observed or declared); [`InputSpec`](./InputSpec.md) ([graph/input\_specs.h](./index.md#input_specs-h)) CONSTRAINS one; a compile/trace directive pinning an input's dynamic dims. Two types, two jobs. [`dims`](./TensorSpec.md#dims) is the expected shape; an entry equal to [`kDynamicDim`](./TensorSpec.md#kDynamicDim) (-1) is resolved at run time, and an empty [`dims`](./TensorSpec.md#dims) leaves the shape unconstrained (it never declares a 0-D tensor). A dynamic dim may additionally carry a NAME in [`dim_names`](./TensorSpec.md#dim_names) (an ONNX `dim_param` like "batch\_size"); the same name on two slots declares the same size, so pinning it once (an [`InputSpec`](./InputSpec.md), a named-dim binding) resolves every slot that shares it. [`dim_names`](./TensorSpec.md#dim_names) is either empty (no names) or [`dims`](./TensorSpec.md#dims)-length with `""` for unnamed dims. [`optional`](./TensorSpec.md#optional) marks an input the model can run without.

## Static member functions

### from\_tensor() {#from_tensor}

<div class="api-signature">

`static` [`TensorSpec`](./TensorSpec.md) **`from_tensor`**(`const` [`Tensor`](../Tensor.md)`&` `tensor`, `std::string` `name` `=` `{}`)

</div>

The spec a live tensor observes: its dtype and concrete dims. A symbolic dim (a traced stand-in's dynamic dim) reads as [`kDynamicDim`](./TensorSpec.md#kDynamicDim) and keeps its declared name. Raises [`ClikaRT::Error`](../Error.md) on an undefined tensor.

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 96

</div>

### from\_tensors() {#from_tensors}

<div class="api-signature">

`static` `std::vector<`[`TensorSpec`](./TensorSpec.md)`>` **`from_tensors`**(`const std::vector<`[`Tensor`](../Tensor.md)`>&` `tensors`)

</div>

One spec per tensor, in order, names left empty; name the slots yourself, or let the consuming surface default them positionally.

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 102

</div>

## Member functions

### TensorSpec() {#TensorSpec}

<div class="api-signature">

**`TensorSpec`**() `=default`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 74

</div>

### TensorSpec(string, DataType, vector\<int64\_t\>, bool, …) {#TensorSpec-2}

<div class="api-signature">

**`TensorSpec`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string` `slot_name`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `slot_dtype`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::vector<std::int64_t>` `slot_dims`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`bool` `is_optional` `=` `false`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::vector<std::string>` `slot_dim_names` `=` `{}`<br />
)

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 75

</div>

### dim\_is\_dynamic() {#dim_is_dynamic}

<div class="api-signature">

`bool` **`dim_is_dynamic`**(`std::size_t` `i`) `const`

</div>

True when dim `i` is the dynamic sentinel ([`kDynamicDim`](./TensorSpec.md#kDynamicDim)).

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 84

</div>

### dim\_name() {#dim_name}

<div class="api-signature">

`std::string` **`dim_name`**(`std::size_t` `i`) `const`

</div>

The dim's declared name, or "" (unnamed / out of range).

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 88

</div>

### merge\_from() {#merge_from}

<div class="api-signature">

`void` **`merge_from`**(`const` [`TensorSpec`](./TensorSpec.md)`&` `other`)

</div>

Widen THIS spec by another observation of the same slot. Dims widen infallibly: a dim dynamic on either side stays dynamic, differing extents become dynamic, and a rank clash makes every dim dynamic at the max rank, so `from_tensor(a)` + `merge_from(from_tensor(b))` infers the dynamic dims from example observations. A dim name is kept where the two sides agree or one is unnamed, dropped where they conflict; [`name`](./TensorSpec.md#name) is kept (adopted from `other` when empty), [`optional`](./TensorSpec.md#optional) is kept. Raises [`ClikaRT::Error`](../Error.md) when the dtypes differ; two dtypes never merge.

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 116

</div>

## Data members

### name {#name}

<div class="api-signature">

`std::string` **`name`**

</div>

edge name, the binding key

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 68

</div>

### dtype {#dtype}

<div class="api-signature">

[`DataType`](../../index.md#DataType) **`dtype`** `=` [`DataType::Float32`](../../index.md#DataType)

</div>

element dtype

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 69

</div>

### dims {#dims}

<div class="api-signature">

`std::vector<std::int64_t>` **`dims`**

</div>

per-dim sizes; kDynamicDim marks a dynamic dim

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 70

</div>

### dim\_names {#dim_names}

<div class="api-signature">

`std::vector<std::string>` **`dim_names`**

</div>

optional per-dim labels, aligned with dims

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 71

</div>

### optional {#optional}

<div class="api-signature">

`bool` **`optional`** `= false`

</div>

the edge may be absent in a request

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 72

</div>

## Static data members

### kDynamicDim {#kDynamicDim}

<div class="api-signature">

`static` `std::int64_t` **`kDynamicDim`** `= -1`

</div>

sentinel dim: the size resolves at bind/run time

<div class="api-declared">

Declared in `ClikaRT/runtime/schema.h`, line 66

</div>
