Rerun C++ SDK
Loading...
Searching...
No Matches
tensor.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/archetypes/tensor.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../components/tensor_data.hpp"
8#include "../data_cell.hpp"
9#include "../indicator_component.hpp"
10#include "../result.hpp"
11
12#include <cstdint>
13#include <utility>
14#include <vector>
15
16namespace rerun::archetypes {
17 /// **Archetype**: A generic n-dimensional Tensor.
18 ///
19 /// Since the underlying `rerun::datatypes::TensorData` uses `rerun::Collection` internally,
20 /// data can be passed in without a copy from raw pointers or by reference from `std::vector`/`std::array`/c-arrays.
21 /// If needed, this "borrow-behavior" can be extended by defining your own `rerun::CollectionAdapter`.
22 ///
23 /// ## Example
24 ///
25 /// ### Simple Tensor
26 /// ![image](https://static.rerun.io/tensor_simple/baacb07712f7b706e3c80e696f70616c6c20b367/full.png)
27 ///
28 /// ```cpp
29 /// #include <rerun.hpp>
30 ///
31 /// #include <algorithm> // std::generate
32 /// #include <random>
33 /// #include <vector>
34 ///
35 /// int main() {
36 /// const auto rec = rerun::RecordingStream("rerun_example_tensor_simple");
37 /// rec.spawn().exit_on_failure();
38 ///
39 /// std::default_random_engine gen;
40 /// // On MSVC uint8_t distributions are not supported.
41 /// std::uniform_int_distribution<int> dist(0, 255);
42 ///
43 /// std::vector<uint8_t> data(8 * 6 * 3 * 5);
44 /// std::generate(data.begin(), data.end(), [&] { return static_cast<uint8_t>(dist(gen)); });
45 ///
46 /// rec.log(
47 /// "tensor",
48 /// rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"width", "height", "channel", "batch"})
49 /// );
50 /// }
51 /// ```
52 struct Tensor {
53 /// The tensor data
55
56 public:
57 static constexpr const char IndicatorComponentName[] = "rerun.components.TensorIndicator";
58
59 /// Indicator component, used to identify the archetype when converting to a list of components.
61
62 public:
63 // Extensions to generated type defined in 'tensor_ext.cpp'
64
65 /// New Tensor from dimensions and tensor buffer.
67 : Tensor(datatypes::TensorData(std::move(shape), std::move(buffer))) {}
68
69 /// New tensor from dimensions and pointer to tensor data.
70 ///
71 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
72 /// \param shape
73 /// Shape of the image. Determines the number of elements expected to be in `data`.
74 /// \param data_
75 /// Target of the pointer must outlive the archetype.
76 template <typename TElement>
77 explicit Tensor(Collection<datatypes::TensorDimension> shape, const TElement* data_)
78 : Tensor(datatypes::TensorData(std::move(shape), data_)) {}
79
80 /// Update the `names` of the contained `TensorData` dimensions.
81 ///
82 /// Any existing Dimension names will be overwritten.
83 ///
84 /// If too many, or too few names are provided, this function will call
85 /// Error::handle and then proceed to only update the subset of names that it can.
87
88 public:
89 Tensor() = default;
90 Tensor(Tensor&& other) = default;
91
92 explicit Tensor(rerun::components::TensorData _data) : data(std::move(_data)) {}
93
94 /// Returns the number of primary instances of this archetype.
95 size_t num_instances() const {
96 return 1;
97 }
98 };
99
100} // namespace rerun::archetypes
101
102namespace rerun {
103 /// \private
104 template <typename T>
105 struct AsComponents;
106
107 /// \private
108 template <>
109 struct AsComponents<archetypes::Tensor> {
110 /// Serialize all set component batches.
111 static Result<std::vector<DataCell>> serialize(const archetypes::Tensor& archetype);
112 };
113} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:47
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:66
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Archetype: A generic n-dimensional Tensor.
Definition tensor.hpp:52
rerun::components::TensorData data
The tensor data.
Definition tensor.hpp:54
Tensor(Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
New Tensor from dimensions and tensor buffer.
Definition tensor.hpp:66
Tensor with_dim_names(Collection< std::string > names) &&
Update the names of the contained TensorData dimensions.
Tensor(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New tensor from dimensions and pointer to tensor data.
Definition tensor.hpp:77
size_t num_instances() const
Returns the number of primary instances of this archetype.
Definition tensor.hpp:95
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: A multi-dimensional Tensor with optionally named arguments.
Definition tensor_data.hpp:21
Datatype: The underlying storage for a Tensor.
Definition tensor_buffer.hpp:93
Datatype: A multi-dimensional Tensor of data.
Definition tensor_data.hpp:29