---
title: "TensorSpec"
sidebar_label: "TensorSpec"
description: "The clika_runtime TensorSpec class."
---

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

One input or output slot of a graph: its name, dtype and dims. A dims entry of -1 (TensorSpec.kDynamicDim) is dynamic; a dim_names entry names a dynamic dim so slots sharing the name share the size.

## `dim_names` (property)

Optional per-dim labels aligned with dims; empty when unnamed.

## `dims` (property)

Per-dim sizes; -1 marks a dynamic dim.

## `dtype` (property)

The element dtype (clika_runtime.float32 and kin); assignable from a dtype object or its name.

## `is_dynamic` (property)

True when any dim is dynamic.

## `kDynamicDim` (property)

(arg: object, /) -> int

## `name` (property)

The slot name, the binding key.

## `optional` (property)

True when the slot may be absent in a request.

## `__init__`

```python
__init____init__(self) -> None
```

__init__(self) -> None
__init__(self, name: str, dtype: object, dims: collections.abc.Sequence[int], optional: bool = False, dim_names: collections.abc.Sequence[str] = []) -> None

Overloaded function.

1. ``__init__(self) -> None``


2. ``__init__(self, name: str, dtype: object, dims: collections.abc.Sequence[int], optional: bool = False, dim_names: collections.abc.Sequence[str] = []) -> None``

TensorSpec(name, dtype, dims, optional=False, dim_names=())

An input/output slot: dims entries of -1 are dynamic; a dim_names entry names a dynamic dim so slots sharing the name share the size. `dtype` is a dtype object (clika_runtime.float32) or its name.

## `dim_is_dynamic`

```python
dim_is_dynamicdim_is_dynamic(self, i: int) -> bool
```

dim_is_dynamic(self, i: int) -> bool

dim_is_dynamic(i) -> bool

Whether dim `i` is dynamic (False past the rank).

## `dim_name`

```python
dim_namedim_name(self, i: int) -> str
```

dim_name(self, i: int) -> str

dim_name(i) -> str

The label of dim `i`, or '' when unnamed.

## `from_tensor`

```python
from_tensorfrom_tensor(tensor: clika_runtime._core.Tensor, name: str = '') -> clika_runtime._core.TensorSpec
```

from_tensor(tensor: clika_runtime._core.Tensor, name: str = '') -> clika_runtime._core.TensorSpec

from_tensor(tensor, name='') -> TensorSpec

The slot a tensor fills: its dtype and its dims as fixed sizes (waits for a pending shape).

## `from_tensors`

```python
from_tensorsfrom_tensors(tensors: collections.abc.Sequence[clika_runtime._core.Tensor]) -> list[clika_runtime._core.TensorSpec]
```

from_tensors(tensors: collections.abc.Sequence[clika_runtime._core.Tensor]) -> list[clika_runtime._core.TensorSpec]

from_tensors(tensors) -> list[TensorSpec]

One slot per tensor, in order, each named positionally.

## `merge_from`

```python
merge_frommerge_from(self, other: clika_runtime._core.TensorSpec) -> None
```

merge_from(self, other: clika_runtime._core.TensorSpec) -> None

merge_from(other) -> None

Widen this slot, in place, by another observation of the same slot. A dim dynamic on either side stays dynamic, extents that differ become dynamic, and a rank clash makes every dim dynamic at the larger rank, so merging TensorSpec.from_tensor(b) into TensorSpec.from_tensor(a) marks the dims the two examples disagree on. A dim name is kept where the two sides agree or one is unnamed, and dropped where they conflict. An empty `name` takes `other.name`, and `optional` is kept. Raises InvalidArgumentError when the dtypes differ.
