---
title: "ClikaRT::NamedTensors"
sidebar_label: "NamedTensors"
description: "An insertion-agnostic name → Tensor map. Copyable and movable (a copy shares each entry's storage; the tensors are refcount handles)."
---

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

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

**Header:** `ClikaRT/compute/named_tensors.h`

A `name → Tensor` collection: the container for a model's weights / state-dict and for multi-tensor I/O (safetensors, gguf). Entries are `Tensor`s (shared refcount handles), so `set`/`get` are cheap and the map shares each tensor's storage rather than copying data.

An insertion-agnostic `name → `[`Tensor`](./Tensor.md) map. Copyable and movable (a copy shares each entry's storage; the tensors are refcount handles). A moved-from [NamedTensors](./NamedTensors.md) is empty: every read answers empty / false / 0, and [`set`](./NamedTensors.md#set) fills it again (a dict moved into `load_state_dict` stays a usable object).

## Member functions

### NamedTensors() {#NamedTensors}

<div class="api-signature">

**`NamedTensors`**()

</div>

An empty collection.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 33

</div>

### NamedTensors(NamedTensors) {#NamedTensors-2}

<div class="api-signature">

**`NamedTensors`**(`const NamedTensors&` `other`)

</div>

Copy: an independent map; the tensor VALUES stay shared handles (storage is not duplicated).

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 37

</div>

### operator=(NamedTensors) {#operator-assign}

<div class="api-signature">

[`NamedTensors`](./NamedTensors.md)`&` **`operator=`**(`const` [`NamedTensors`](./NamedTensors.md)`&` `other`)

</div>

Copy-assign; same handle-sharing semantics as the copy ctor.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 39

</div>

### NamedTensors(NamedTensors) {#NamedTensors-3}

<div class="api-signature">

**`NamedTensors`**(`NamedTensors&&` `other`) `noexcept`

</div>

Move: transfers the map; `other` is left empty and stays usable.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 41

</div>

### operator=(NamedTensors) {#operator-assign-2}

<div class="api-signature">

[`NamedTensors`](./NamedTensors.md)`&` **`operator=`**([`NamedTensors`](./NamedTensors.md)`&&` `other`) `noexcept`

</div>

Move-assign; transfers the map; `other` is left empty and stays usable.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 43

</div>

### \~NamedTensors() {#NamedTensors-4}

<div class="api-signature">

**`~NamedTensors`**()

</div>

Releases the map (each held handle drops its reference).

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 45

</div>

### set() {#set}

<div class="api-signature">

`void` **`set`**(`std::string_view` `name`, [`Tensor`](./Tensor.md) `tensor`)

</div>

Insert or replace the tensor under `name`. `name` is copied.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 48

</div>

### get() {#get}

<div class="api-signature">

[`Tensor`](./Tensor.md) **`get`**(`std::string_view` `name`) `const`

</div>

The tensor under `name`; raises [`ClikaRT::Error`](./Error.md) (NotFound) if absent.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 51

</div>

### contains() {#contains}

<div class="api-signature">

`bool` **`contains`**(`std::string_view` `name`) `const`

</div>

True if `name` is present.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 53

</div>

### size() {#size}

<div class="api-signature">

`std::size_t` **`size`**() `const`

</div>

Number of entries.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 55

</div>

### names() {#names}

<div class="api-signature">

`std::vector<std::string>` **`names`**() `const`

</div>

All entry names (unordered).

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 57

</div>

### for\_each() {#for_each}

<div class="api-signature">

`void` **`for_each`**(`const std::function<void(std::string_view name, const` [`Tensor`](./Tensor.md)`&tensor)>&` `visit`) `const`

</div>

Visit each entry. `name` and `tensor` are valid only during the call.

A throw from `visit` is contained HERE, in your own TU / runtime, never unwinding through the library frame (a cross-runtime unwind into the Release `.so`'s static C++ runtime terminates), and stops the walk, and surfaces as the raised [`ClikaRT::Error`](./Error.md) / returned failure. To stop the walk early WITHOUT an error, use [`for_each_while`](./NamedTensors.md#for_each_while). An empty `visit` is refused ([`Status::InvalidArgument`](../index.md#Status)) before the walk.

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 66

</div>

### for\_each\_while() {#for_each_while}

<div class="api-signature">

`void` **`for_each_while`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`const std::function<bool(std::string_view name, const` [`Tensor`](./Tensor.md)`&tensor)>&` `visit`<br />
) `const`

</div>

The abort-capable sibling: `visit` returns `false` to stop the walk early (a clean stop, not an error). A throw is contained, and an empty `visit` refused, exactly as in [`for_each`](./NamedTensors.md#for_each).

<div class="api-declared">

Declared in `ClikaRT/compute/named_tensors.h`, line 77

</div>
